Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New release #339

Merged
merged 11 commits into from
Jul 2, 2024
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@appquality/tryber-database": "^0.40.3",
"@appquality/tryber-database": "^0.41.1",
"@appquality/wp-auth": "^1.0.7",
"@googlemaps/google-maps-services-js": "^3.3.7",
"@sendgrid/mail": "^7.6.0",
Expand All @@ -38,6 +38,7 @@
"express": "^4.18.1",
"express-fileupload": "^1.4.0",
"glob": "^8.0.3",
"i18n-iso-countries": "^7.11.2",
"jsonwebtoken": "^8.5.1",
"morgan": "^1.10.0",
"multer-s3": "^2.10.0",
Expand Down
25 changes: 22 additions & 3 deletions src/reference/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9986,6 +9986,10 @@ paths:
type: string
size:
type: integer
cap:
type: integer
x-stoplight:
id: yzv1ppm6f5kq7
countries:
type: array
minItems: 1
Expand Down Expand Up @@ -10532,7 +10536,6 @@ components:
id:
type: integer
CampaignOptional:
description: ''
type: object
x-examples:
example-1:
Expand Down Expand Up @@ -10674,14 +10677,26 @@ components:
$ref: '#/components/schemas/TranslatablePage'
bugform_link:
oneOf:
- properties: {}
type: boolean
- type: boolean
description: Exists only when the campaign bugform is deactivated. It is FALSE
- $ref: '#/components/schemas/TranslatablePage'
description: If bugform is deactivated is a boolean else contains URLs to bugforms for each languages
applied:
type: boolean
description: True if you applied on this Campaign
visibility:
type: object
x-stoplight:
id: z9vo6su8stzvn
properties:
freeSpots:
type: integer
x-stoplight:
id: qy6n5oa4quk52
totalSpots:
type: integer
x-stoplight:
id: 1jumwi4cvp91d
CampaignRequired:
description: ''
type: object
Expand Down Expand Up @@ -11269,6 +11284,10 @@ components:
type: string
size:
type: integer
cap:
type: integer
x-stoplight:
id: dv3yqv5k8gpv6
countries:
type: array
items:
Expand Down
65 changes: 65 additions & 0 deletions src/routes/dossiers/_post/creation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,23 @@ describe("Route POST /dossiers", () => {
expect(dossierData).toHaveLength(1);
expect(dossierData[0]).toHaveProperty("target_size", 10);
});
it("Should save target size 0 in the dossier data", async () => {
const response = await request(app)
.post("/dossiers")
.set("authorization", "Bearer admin")
.send({ ...baseRequest, target: { size: 0 } });

expect(response.status).toBe(201);
expect(response.body).toHaveProperty("id");

const id = response.body.id;

const dossierData = await tryber.tables.CampaignDossierData.do()
.select()
.where({ campaign_id: id });
expect(dossierData).toHaveLength(1);
expect(dossierData[0]).toHaveProperty("target_size", 0);
});

it("Should save the tester id in the dossier data", async () => {
const response = await request(app)
Expand Down Expand Up @@ -708,4 +725,52 @@ describe("Route POST /dossiers", () => {
expect(getResponse.status).toBe(200);
expect(getResponse.body).toHaveProperty("notes", "Notes");
});
it("Should save the cap in the dossier data", async () => {
const response = await request(app)
.post("/dossiers")
.set("authorization", "Bearer admin")
.send({
...baseRequest,
target: {
cap: 100,
},
});

expect(response.status).toBe(201);
expect(response.body).toHaveProperty("id");

const id = response.body.id;

const getResponse = await request(app)
.get(`/dossiers/${id}`)
.set("authorization", "Bearer admin");

expect(getResponse.status).toBe(200);
expect(getResponse.body).toHaveProperty("target");
expect(getResponse.body.target).toHaveProperty("cap", 100);
});
it("Should save the cap 0 in the dossier data", async () => {
const response = await request(app)
.post("/dossiers")
.set("authorization", "Bearer admin")
.send({
...baseRequest,
target: {
cap: 0,
},
});

expect(response.status).toBe(201);
expect(response.body).toHaveProperty("id");

const id = response.body.id;

const getResponse = await request(app)
.get(`/dossiers/${id}`)
.set("authorization", "Bearer admin");

expect(getResponse.status).toBe(200);
expect(getResponse.body).toHaveProperty("target");
expect(getResponse.body.target).toHaveProperty("cap", 0);
});
});
8 changes: 4 additions & 4 deletions src/routes/dossiers/_post/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ export default class RouteItem extends UserRoute<{
const campaign = await tryber.tables.WpAppqEvdCampaign.do()
.select(
"id",
"desired_number_of_testers",
"min_allowed_media",
"cust_bug_vis",
"campaign_type",
Expand Down Expand Up @@ -261,10 +260,11 @@ export default class RouteItem extends UserRoute<{
os: os.join(","),
form_factor: form_factor.join(","),
base_bug_internal_id: "UG",
...(typeof this.getBody().target?.cap !== "undefined"
? { desired_number_of_testers: this.getBody().target?.cap }
: {}),
...(campaignToDuplicate
? {
desired_number_of_testers:
campaignToDuplicate.desired_number_of_testers,
min_allowed_media: campaignToDuplicate.min_allowed_media,
cust_bug_vis: campaignToDuplicate.cust_bug_vis,
campaign_type: campaignToDuplicate.campaign_type,
Expand Down Expand Up @@ -296,7 +296,7 @@ export default class RouteItem extends UserRoute<{
goal: this.getBody().goal,
out_of_scope: this.getBody().outOfScope,
target_audience: this.getBody().target?.notes,
...(this.getBody().target?.size && {
...(typeof this.getBody().target?.size !== "undefined" && {
target_size: this.getBody().target?.size,
}),
product_type_id: this.getBody().productType,
Expand Down
92 changes: 92 additions & 0 deletions src/routes/dossiers/campaignId/_get/cap.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import app from "@src/app";
import { tryber } from "@src/features/database";
import request from "supertest";

describe("Route GET /dossiers/:id", () => {
beforeAll(async () => {
await tryber.tables.CampaignPhase.do().insert([
{
id: 1,
name: "Active",
type_id: 1,
},
]);
await tryber.tables.WpAppqCustomer.do().insert({
id: 1,
company: "Test Company",
pm_id: 1,
});
await tryber.tables.WpAppqProject.do().insert({
id: 1,
display_name: "Test Project",
customer_id: 1,
edited_by: 1,
});

await tryber.tables.WpAppqEvdProfile.do().insert([
{
name: "Test",
surname: "CSM",
email: "",
education_id: 1,
employment_id: 1,
id: 1,
wp_user_id: 1,
},
]);

await tryber.tables.WpAppqCampaignType.do().insert({
id: 1,
name: "Test Type",
description: "Test Description",
category_id: 1,
});

await tryber.tables.WpAppqEvdPlatform.do().insert([
{
id: 1,
name: "Test Device",
form_factor: 0,
architecture: 1,
},
]);

await tryber.tables.WpAppqEvdCampaign.do().insert({
id: 1,
project_id: 1,
campaign_type_id: 1,
title: "Test Campaign",
customer_title: "Test Customer Campaign",
start_date: "2019-08-24T14:15:22Z",
end_date: "2019-08-24T14:15:22Z",
close_date: "2019-08-27T14:15:22Z",
platform_id: 0,
os: "1",
page_manual_id: 0,
page_preview_id: 0,
pm_id: 1,
customer_id: 0,
desired_number_of_testers: 100,
});
});

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.WpAppqEvdCampaign.do().delete();
await tryber.tables.WpAppqEvdProfile.do().delete();
await tryber.tables.CampaignPhase.do().delete();
});

it("Should return cap", async () => {
const response = await request(app)
.get("/dossiers/1")
.set("authorization", "Bearer admin");

expect(response.status).toBe(200);
expect(response.body).toHaveProperty("target");
expect(response.body.target).toHaveProperty("cap", 100);
});
});
1 change: 1 addition & 0 deletions src/routes/dossiers/campaignId/_get/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe("Route GET /dossiers/:id", () => {
page_preview_id: 0,
pm_id: 1,
customer_id: 0,
desired_number_of_testers: 100,
});

await tryber.tables.CustomRoles.do().insert([
Expand Down
13 changes: 11 additions & 2 deletions src/routes/dossiers/campaignId/_get/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default class RouteItem extends UserRoute<{
"project_id",
"campaign_type_id",
"os",
tryber
.ref("desired_number_of_testers")
.withSchema("wp_appq_evd_campaign")
.as("cap"),
tryber
.ref("display_name")
.withSchema("wp_appq_project")
Expand Down Expand Up @@ -280,14 +284,19 @@ export default class RouteItem extends UserRoute<{
...(this.campaign.out_of_scope && {
outOfScope: this.campaign.out_of_scope,
}),
...((this.campaign.target_audience || this.campaign.target_size) && {
...((this.campaign.target_audience ||
typeof this.campaign.target_size !== "undefined" ||
typeof this.campaign.cap !== "undefined") && {
target: {
...(this.campaign.target_audience && {
notes: this.campaign.target_audience,
}),
...(this.campaign.target_size && {
...(typeof this.campaign.target_size !== "undefined" && {
size: this.campaign.target_size,
}),
...(typeof this.campaign.cap !== "undefined" && {
cap: this.campaign.cap,
}),
},
}),
...(this.campaign.target_devices && {
Expand Down
6 changes: 5 additions & 1 deletion src/routes/dossiers/campaignId/_put/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default class RouteItem extends UserRoute<{
private async updateCampaign() {
const { os, form_factor } = await this.getDevices();

console.log(typeof this.getBody().target?.cap);
await tryber.tables.WpAppqEvdCampaign.do()
.update({
title: this.getBody().title.tester,
Expand All @@ -128,6 +129,9 @@ export default class RouteItem extends UserRoute<{
customer_title: this.getBody().title.customer,
os: os.join(","),
form_factor: form_factor.join(","),
...(typeof this.getBody().target?.cap !== "undefined" && {
desired_number_of_testers: this.getBody().target?.cap,
}),
})
.where({
id: this.campaignId,
Expand Down Expand Up @@ -166,7 +170,7 @@ export default class RouteItem extends UserRoute<{
goal: this.getBody().goal,
out_of_scope: this.getBody().outOfScope,
target_audience: this.getBody().target?.notes,
...(this.getBody().target?.size && {
...(typeof this.getBody().target?.size !== "undefined" && {
target_size: this.getBody().target?.size,
}),
product_type_id: this.getBody().productType,
Expand Down
Loading
Loading