Skip to content

Commit

Permalink
Handle custom roles (#306)
Browse files Browse the repository at this point in the history
* feat: Add roles designs

* feat: Allow linking roles to campaign

* feat: Assign olps

* feat: Add roles to get

* feat: Allow changing roles

* feat: Delete only custom roles olps

* chore: Update database

* fix: Format datetime

* chore: Remove x-stoplight meta

* test: Format date
  • Loading branch information
d-beezee committed May 20, 2024
1 parent 58ebe74 commit b21f944
Show file tree
Hide file tree
Showing 8 changed files with 539 additions and 72 deletions.
132 changes: 72 additions & 60 deletions src/reference/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1176,8 +1176,6 @@ paths:
type: string
metal:
type: string
x-stoplight:
id: 9afe0zlf0hr2b
devices:
type: array
items:
Expand Down Expand Up @@ -4239,8 +4237,6 @@ paths:
type: string
type:
type: string
x-stoplight:
id: 6yohqfohiv47u
required:
- id
- name
Expand Down Expand Up @@ -9688,8 +9684,6 @@ paths:
properties:
id:
type: integer
x-stoplight:
id: 965rh7aagxj8x
examples:
Example 1:
value:
Expand Down Expand Up @@ -9735,118 +9729,102 @@ paths:
properties:
id:
type: integer
x-stoplight:
id: qqon32evab2o5
title:
type: object
x-stoplight:
id: qfn9vuux1vjp1
required:
- customer
- tester
properties:
customer:
type: string
x-stoplight:
id: tyx8mtant8jej
tester:
type: string
x-stoplight:
id: cupl63jal29yu
startDate:
type: string
x-stoplight:
id: lif1wyyh6miiy
format: date-time
endDate:
type: string
x-stoplight:
id: dhx6h9l494pyw
format: date-time
customer:
type: object
x-stoplight:
id: b6vdml702n2vr
required:
- id
- name
properties:
id:
type: integer
x-stoplight:
id: hzxvga289ilzv
name:
type: string
x-stoplight:
id: zxk4wi6clmaxr
project:
type: object
x-stoplight:
id: 9dnwnxk98slrj
required:
- id
- name
properties:
id:
type: integer
x-stoplight:
id: 795lyzmcn2f3i
name:
type: string
x-stoplight:
id: lonlyyu0xqpx9
testType:
type: object
x-stoplight:
id: y2l96ujpgntcx
required:
- id
- name
properties:
id:
type: integer
x-stoplight:
id: 5ut1dht9q3e5f
name:
type: string
x-stoplight:
id: 3zafe5jvg89hd
deviceList:
type: array
x-stoplight:
id: 8ac5l94cifolj
items:
x-stoplight:
id: p874do1llblvt
type: object
properties:
id:
type: integer
x-stoplight:
id: 64zrvfx7v23m8
name:
type: string
x-stoplight:
id: 838zaws7zfcb6
required:
- id
- name
csm:
type: object
x-stoplight:
id: ye4vllt9hwd40
required:
- id
- name
properties:
id:
type: integer
x-stoplight:
id: 29ini0mkuenx4
name:
type: string
x-stoplight:
id: 0v4z9eu7jfeja
roles:
type: array
items:
type: object
properties:
role:
type: object
properties:
id:
type: integer
name:
type: string
required:
- id
- name
user:
type: object
properties:
id:
type: integer
name:
type: string
surname:
type: string
required:
- id
- name
- surname
required:
- id
- title
Expand All @@ -9857,6 +9835,38 @@ paths:
- testType
- deviceList
- csm
examples:
Example 1:
value:
id: 1
title:
customer: Customer Title
tester: Tester Title
startDate: '2019-08-24T14:15:22Z'
endDate: '2019-08-24T14:15:22Z'
customer:
id: 1
name: My Customer
project:
id: 1
name: My Project
testType:
id: 1
name: Bughunting
deviceList:
- id: 1
name: Android
csm:
id: 1
name: Name Surname
roles:
- role:
id: 1
name: PM
user:
id: 1
name: Name
surname: Surname
security:
- JWT: []
'/customers/{customer}/projects':
Expand All @@ -9879,21 +9889,13 @@ paths:
properties:
results:
type: array
x-stoplight:
id: 9ccc89bhovco5
items:
x-stoplight:
id: zog5qqnv5h7rb
type: object
properties:
id:
type: integer
x-stoplight:
id: xapq51u019ada
name:
type: string
x-stoplight:
id: 8fxvw6c3m46bv
required:
- id
- name
Expand Down Expand Up @@ -11057,8 +11059,18 @@ components:
type: integer
csm:
type: number
x-stoplight:
id: tczilke0whidg
roles:
type: array
items:
type: object
properties:
role:
type: number
user:
type: number
required:
- role
- user
required:
- project
- testType
Expand Down
66 changes: 66 additions & 0 deletions src/routes/dossiers/_post/creation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ const baseRequest = {

describe("Route POST /dossiers", () => {
beforeAll(async () => {
await tryber.tables.WpAppqEvdProfile.do().insert({
id: 1,
wp_user_id: 100,
name: "",
email: "",
education_id: 1,
employment_id: 1,
});
await tryber.tables.WpAppqCustomer.do().insert({
id: 1,
company: "Test Company",
Expand Down Expand Up @@ -48,16 +56,23 @@ describe("Route POST /dossiers", () => {
architecture: 1,
},
]);

await tryber.tables.CustomRoles.do().insert([
{ id: 1, name: "Test Role", olp: '["appq_bugs"]' },
]);
});

afterAll(async () => {
await tryber.tables.WpAppqCustomer.do().delete();
await tryber.tables.WpAppqProject.do().delete();
await tryber.tables.WpAppqCampaignType.do().delete();
await tryber.tables.WpAppqEvdPlatform.do().delete();
await tryber.tables.WpAppqEvdProfile.do().delete();
await tryber.tables.CustomRoles.do().delete();
});
afterEach(async () => {
await tryber.tables.WpAppqEvdCampaign.do().delete();
await tryber.tables.CampaignCustomRoles.do().delete();
});

it("Should create a campaign", async () => {
Expand Down Expand Up @@ -270,4 +285,55 @@ describe("Route POST /dossiers", () => {
expect(campaign).toHaveProperty("os", "1,2");
expect(campaign).toHaveProperty("form_factor", "0,1");
});

it("Should return 406 if adding a role that does not exist", async () => {
const response = await request(app)
.post("/dossiers")
.set("authorization", "Bearer admin")
.send({ ...baseRequest, roles: [{ role: 100, user: 1 }] });

expect(response.status).toBe(406);
});

it("Should return 406 if adding a role to a user that does not exist", async () => {
const response = await request(app)
.post("/dossiers")
.set("authorization", "Bearer admin")
.send({ ...baseRequest, roles: [{ role: 1, user: 100 }] });

expect(response.status).toBe(406);
});

it("Should link the roles to the campaign", async () => {
const response = await request(app)
.post("/dossiers")
.set("authorization", "Bearer admin")
.send({ ...baseRequest, roles: [{ role: 1, user: 1 }] });

const id = response.body.id;

const roles = await tryber.tables.CampaignCustomRoles.do()
.select()
.where({ campaign_id: id });
expect(roles).toHaveLength(1);
expect(roles[0]).toHaveProperty("custom_role_id", 1);
expect(roles[0]).toHaveProperty("tester_id", 1);
});

it("Should set the olp roles to the campaign", async () => {
const response = await request(app)
.post("/dossiers")
.set("authorization", "Bearer admin")
.send({ ...baseRequest, roles: [{ role: 1, user: 1 }] });

const id = response.body.id;

const olps = await tryber.tables.WpAppqOlpPermissions.do()
.select()
.where({ main_id: id });
expect(olps).toHaveLength(1);
expect(olps[0]).toHaveProperty("type", "appq_bugs");
expect(olps[0]).toHaveProperty("main_type", "campaign");
expect(olps[0]).toHaveProperty("wp_user_id", 100);
});
});
Loading

0 comments on commit b21f944

Please sign in to comment.