Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/reference/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12831,6 +12831,61 @@ paths:
summary: Get all your payments
tags: []
parameters: []

/dossiers/rates:
get:
summary: Your GET endpoint
tags: []
responses:
'200':
content:
application/json:
schema:
type: object
x-examples:
Example 1:
items:
- id: 0
name: ''
rate: 0
required:
- items
properties:
items:
type: array
items:
type: object
required:
- id
- name
- rate
properties:
id:
type: integer
name:
type: string
rate:
type: integer
examples:
Example 1:
value:
items:
- id: 0
name: Name
rate: 0
'403':
$ref: '#/components/responses/Authentication'
'404':
$ref: '#/components/responses/NotFound'
'406':
description: Not Acceptable
'500':
description: Internal Server Error
operationId: get-dossiers-rates
x-stoplight:
id: qhs3sh6dveatp
security:
- JWT: []
/users/me/permissions:
get:
description: Return all user permissions
Expand Down
108 changes: 108 additions & 0 deletions src/routes/dossiers/rates/_get/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import app from "@src/app";
import { tryber } from "@src/features/database";
import request from "supertest";

describe("Route GET /dossiers/rates", () => {
beforeAll(async () => {
await tryber.tables.WorkRates.do().insert([
{
id: 1,
name: "Junior Tester",
daily_rate: 100,
},
{
id: 2,
name: "Senior Tester",
daily_rate: 200,
},
]);
await tryber.tables.WpAppqEvdProfile.do().insert({
id: 1,
wp_user_id: 1,
email: "pino@example.com",
employment_id: 1,
education_id: 1,
});
});

afterAll(async () => {
await tryber.tables.WorkRates.do().delete();
await tryber.tables.WpAppqEvdProfile.do().delete();
});

it("Should answer 403 if not logged in", async () => {
const response = await request(app).get("/dossiers/rates");

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

it("Should answer 401 if not admin", async () => {
const response = await request(app)
.get("/dossiers/rates")
.set("authorization", "Bearer tester");

expect(response.status).toBe(401);
expect(response.body).toEqual(
expect.objectContaining({ message: "No access to campaign" })
);
});

it("Should answer 200 if user is admin", async () => {
const response = await request(app)
.get(`/dossiers/rates`)
.set("authorization", "Bearer admin");

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

it("Should return 200 if user has only some campaign olps", async () => {
const response = await request(app)
.get(`/dossiers/rates`)
.set("Authorization", 'Bearer tester olp {"appq_campaign":[1,2,3]}');

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

it("Should return 200 if user has full campaign olps", async () => {
const response = await request(app)
.get(`/dossiers/rates`)
.set("Authorization", 'Bearer tester olp {"appq_campaign":true}');

expect(response.status).toBe(200);
});
it("Should return array of items", async () => {
const response = await request(app)
.get(`/dossiers/rates`)
.set("authorization", "Bearer admin");

expect(response.status).toBe(200);

expect(response.body).toHaveProperty("items");
expect(response.body.items).toBeInstanceOf(Array);
expect(response.body.items.length).toBe(2);
});

it("Should return items with id, name and rate", async () => {
const response = await request(app)
.get(`/dossiers/rates`)
.set("authorization", "Bearer admin");

expect(response.status).toBe(200);

expect(response.body).toHaveProperty(
"items",
expect.arrayContaining([
expect.objectContaining({
id: 1,
name: "Junior Tester",
rate: 100,
}),
expect.objectContaining({
id: 2,
name: "Senior Tester",
rate: 200,
}),
])
);
});
});
46 changes: 46 additions & 0 deletions src/routes/dossiers/rates/_get/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/** OPENAPI-CLASS: get-dossiers-rates */

import { tryber } from "@src/features/database";
import OpenapiError from "@src/features/OpenapiError";
import UserRoute from "@src/features/routes/UserRoute";

export default class RouteItem extends UserRoute<{
response: StoplightOperations["get-dossiers-rates"]["responses"]["200"]["content"]["application/json"];
}> {
constructor(configuration: RouteClassConfiguration) {
super(configuration);
}

protected async filter() {
if (!(await super.filter())) return false;

if (!this.campaignOlps) {
this.setError(401, new OpenapiError("No access to campaign"));
return false;
}

return true;
}

private async getDossierRates() {
const rates = await tryber.tables.WorkRates.do().select("*");

return rates;
}

protected async prepare() {
try {
const rates = await this.getDossierRates();

this.setSuccess(200, {
items: rates.map((rate) => ({
id: rate.id,
name: rate.name,
rate: rate.daily_rate,
})),
});
} catch (e) {
this.setError(500, e as OpenapiError);
}
}
}
24 changes: 24 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ export interface paths {
get: operations["get-users-me-pending-booty"];
parameters: {};
};
"/dossiers/rates": {
get: operations["get-dossiers-rates"];
};
"/users/me/permissions": {
/** Return all user permissions */
get: operations["get-users-me-permissions"];
Expand Down Expand Up @@ -5263,6 +5266,27 @@ export interface operations {
404: components["responses"]["NotFound"];
};
};
"get-dossiers-rates": {
responses: {
200: {
content: {
"application/json": {
items: {
id: number;
name: string;
rate: number;
}[];
};
};
};
403: components["responses"]["Authentication"];
404: components["responses"]["NotFound"];
/** Not Acceptable */
406: unknown;
/** Internal Server Error */
500: unknown;
};
};
/** Return all user permissions */
"get-users-me-permissions": {
parameters: {};
Expand Down
Loading