From b5b964d6a14374de05c0ed05d019d63870c119f0 Mon Sep 17 00:00:00 2001 From: "it@app-quality.com" Date: Tue, 14 May 2024 11:56:47 +0200 Subject: [PATCH 01/12] Modified src/reference/openapi.yml --- src/reference/openapi.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/reference/openapi.yml b/src/reference/openapi.yml index f3e923e4f..31aab5e8f 100644 --- a/src/reference/openapi.yml +++ b/src/reference/openapi.yml @@ -1831,18 +1831,27 @@ paths: application/json: schema: type: object + required: + - items properties: items: type: array items: type: object + required: + - id + - name + - time + - tester + - cluster + - media properties: id: type: integer name: type: string time: - type: integer + type: number tester: type: object required: @@ -1876,15 +1885,6 @@ paths: type: string streamUrl: type: string - required: - - id - - name - - time - - tester - - cluster - - media - required: - - items examples: 3-observations: value: From 9a25c1f213a11747d36d778e788e22a4fcdc562b Mon Sep 17 00:00:00 2001 From: ZecD Date: Tue, 14 May 2024 12:08:33 +0200 Subject: [PATCH 02/12] changed data type to number from integer --- .../campaigns/campaignId/observations/_get/index.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/routes/campaigns/campaignId/observations/_get/index.spec.ts b/src/routes/campaigns/campaignId/observations/_get/index.spec.ts index 5814a9dd0..eb29f4e16 100644 --- a/src/routes/campaigns/campaignId/observations/_get/index.spec.ts +++ b/src/routes/campaigns/campaignId/observations/_get/index.spec.ts @@ -47,7 +47,7 @@ beforeAll(async () => { id: 1, media_id: 1, name: "Observation1 name", - video_ts: 59, + video_ts: 59.5, description: "Observation1 description", ux_note: "Observation1 ux_notes", }, @@ -55,7 +55,7 @@ beforeAll(async () => { id: 2, media_id: 2, name: "Observation2 name", - video_ts: 59, + video_ts: 59.5, description: "Observation2 description", ux_note: "Observation2 ux_notes", }, @@ -63,7 +63,7 @@ beforeAll(async () => { id: 3, media_id: 3, name: "Observation2 name", - video_ts: 59, + video_ts: 59.5, description: "Observation2 description", ux_note: "Observation2 ux_notes", }, @@ -250,7 +250,7 @@ describe("GET /campaigns/:campaignId/observations", () => { expect(response.body.items).toEqual( expect.arrayContaining([ expect.objectContaining({ - time: 59, + time: 59.5, }), ]) ); From 8dfec5e8e720bfd95d98d406ae244e0b4c4174fc Mon Sep 17 00:00:00 2001 From: ZecD Date: Tue, 14 May 2024 12:14:57 +0200 Subject: [PATCH 03/12] fixed to return only 1 decimal --- .../campaigns/campaignId/observations/_get/index.spec.ts | 6 +++--- src/routes/campaigns/campaignId/observations/_get/index.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/routes/campaigns/campaignId/observations/_get/index.spec.ts b/src/routes/campaigns/campaignId/observations/_get/index.spec.ts index eb29f4e16..eb8dca02a 100644 --- a/src/routes/campaigns/campaignId/observations/_get/index.spec.ts +++ b/src/routes/campaigns/campaignId/observations/_get/index.spec.ts @@ -47,7 +47,7 @@ beforeAll(async () => { id: 1, media_id: 1, name: "Observation1 name", - video_ts: 59.5, + video_ts: 59.5232, description: "Observation1 description", ux_note: "Observation1 ux_notes", }, @@ -55,7 +55,7 @@ beforeAll(async () => { id: 2, media_id: 2, name: "Observation2 name", - video_ts: 59.5, + video_ts: 59.5658, description: "Observation2 description", ux_note: "Observation2 ux_notes", }, @@ -63,7 +63,7 @@ beforeAll(async () => { id: 3, media_id: 3, name: "Observation2 name", - video_ts: 59.5, + video_ts: 59.545122, description: "Observation2 description", ux_note: "Observation2 ux_notes", }, diff --git a/src/routes/campaigns/campaignId/observations/_get/index.ts b/src/routes/campaigns/campaignId/observations/_get/index.ts index 9a7dc146a..601fbdfa5 100644 --- a/src/routes/campaigns/campaignId/observations/_get/index.ts +++ b/src/routes/campaigns/campaignId/observations/_get/index.ts @@ -99,7 +99,7 @@ export default class SingleCampaignRoute extends CampaignRoute<{ results.push({ id: observation.id, name: observation.name, - time: observation.time, + time: Number(observation.time.toFixed(1)), cluster: { id: observation.cluster_id, name: observation.cluster_title, From c17048440dde68ce2abab11895cf55681602cbd7 Mon Sep 17 00:00:00 2001 From: Davide Bizzi Date: Mon, 20 May 2024 10:00:48 +0200 Subject: [PATCH 04/12] feat: Update webhook triggering --- src/features/webhookTrigger/index.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/features/webhookTrigger/index.ts b/src/features/webhookTrigger/index.ts index c9d026fd4..3a2adec6d 100644 --- a/src/features/webhookTrigger/index.ts +++ b/src/features/webhookTrigger/index.ts @@ -26,9 +26,14 @@ export class WebhookTrigger } async trigger() { - await axios.post(this.webhookUrl, { - ...this.data, - environment: process.env.ENVIROMENT, - }); + try { + await axios.post(this.webhookUrl, { + ...this.data, + environment: process.env.ENVIROMENT, + }); + } catch (e) { + console.error("Error triggering webhook", e); + throw e; + } } } From 8784e68438d72325ac90ee96f4dcc8442668c729 Mon Sep 17 00:00:00 2001 From: Davide Bizzi Date: Mon, 20 May 2024 10:01:42 +0200 Subject: [PATCH 05/12] chore: Add log to wp trigger --- .../wp/WordpressJsonApiTrigger/index.ts | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/features/wp/WordpressJsonApiTrigger/index.ts b/src/features/wp/WordpressJsonApiTrigger/index.ts index a5a94e142..0458b1cb8 100644 --- a/src/features/wp/WordpressJsonApiTrigger/index.ts +++ b/src/features/wp/WordpressJsonApiTrigger/index.ts @@ -22,14 +22,19 @@ class WordpressJsonApiTrigger { } private async postToWordpress(url: string) { - await axios({ - method: "GET", - url: `${process.env.WORDPRESS_API_URL}/${url}`, - headers: { - "User-Agent": "Tryber API", - "Content-Type": "application/json", - }, - }); + try { + await axios({ + method: "GET", + url: `${process.env.WORDPRESS_API_URL}/${url}`, + headers: { + "User-Agent": "Tryber API", + "Content-Type": "application/json", + }, + }); + } catch (e) { + console.error("Error triggering wp", e); + throw e; + } } } From e0b764fb2bb9037412fee5abceff92ae24acd9c3 Mon Sep 17 00:00:00 2001 From: Davide Bizzi Date: Mon, 20 May 2024 10:27:19 +0200 Subject: [PATCH 06/12] feat: Duplicate meta --- src/reference/openapi.yml | 4 ++ src/routes/dossiers/_post/index.ts | 76 ++++++++++++++++++++++++++++-- src/schema.ts | 1 + 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/src/reference/openapi.yml b/src/reference/openapi.yml index 17bcc15c9..f286791d7 100644 --- a/src/reference/openapi.yml +++ b/src/reference/openapi.yml @@ -9782,6 +9782,10 @@ paths: type: integer testers: type: integer + campaign: + type: integer + x-stoplight: + id: 8os8pe07l1htz '/dossiers/{campaign}': parameters: - name: campaign diff --git a/src/routes/dossiers/_post/index.ts b/src/routes/dossiers/_post/index.ts index a530d0c7d..0b5c1cae1 100644 --- a/src/routes/dossiers/_post/index.ts +++ b/src/routes/dossiers/_post/index.ts @@ -141,19 +141,70 @@ export default class RouteItem extends AdminRoute<{ campaignId, }, }); - await webhook.trigger(); - this.setSuccess(201, { - id: campaignId, - }); + try { + await webhook.trigger(); + this.setSuccess(201, { + id: campaignId, + }); + } catch (e) { + this.setSuccess(206, { + id: campaignId, + }); + } } catch (e) { this.setError(500, e as OpenapiError); } } + private async getCampaignToDuplicate() { + const { duplicate } = this.getBody(); + if (!duplicate || !duplicate.campaign) return; + + const campaign = await tryber.tables.WpAppqEvdCampaign.do() + .select( + "id", + "desired_number_of_testers", + "min_allowed_media", + "cust_bug_vis", + "campaign_type", + "campaign_pts" + ) + .where("id", duplicate.campaign) + .first(); + + return campaign; + } + + private async duplicateMeta({ + campaignId, + campaignToDuplicate, + }: { + campaignId: number; + campaignToDuplicate: number; + }) { + const meta = await tryber.tables.WpAppqCpMeta.do() + .select() + .where("cp_id", campaignToDuplicate); + + if (meta.length) { + await tryber.tables.WpAppqCpMeta.do().insert( + meta.map((metaItem) => { + const { meta_id, ...rest } = metaItem; + return { + ...rest, + cp_id: campaignId, + }; + }) + ); + } + } + private async createCampaign() { const { os, form_factor } = await this.getDevices(); + const campaignToDuplicate = await this.getCampaignToDuplicate(); + const results = await tryber.tables.WpAppqEvdCampaign.do() .insert({ title: this.getBody().title.tester, @@ -171,11 +222,28 @@ export default class RouteItem extends AdminRoute<{ customer_title: this.getBody().title.customer, os: os.join(","), form_factor: form_factor.join(","), + ...(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, + campaign_pts: campaignToDuplicate.campaign_pts, + } + : {}), }) .returning("id"); const campaignId = results[0].id ?? results[0]; + if (campaignToDuplicate) { + await this.duplicateMeta({ + campaignId, + campaignToDuplicate: campaignToDuplicate.id, + }); + } + const dossier = await tryber.tables.CampaignDossierData.do() .insert({ campaign_id: campaignId, diff --git a/src/schema.ts b/src/schema.ts index f2ad1ddae..a52c80903 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -4121,6 +4121,7 @@ export interface operations { mailMerges?: number; pages?: number; testers?: number; + campaign?: number; }; }; }; From a165c0881ea80976bb854f10c3f0364a3ea5c156 Mon Sep 17 00:00:00 2001 From: Davide Bizzi Date: Mon, 20 May 2024 10:30:19 +0200 Subject: [PATCH 07/12] feat: Hardcode internalid --- src/routes/dossiers/_post/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/routes/dossiers/_post/index.ts b/src/routes/dossiers/_post/index.ts index 0b5c1cae1..e0b69d937 100644 --- a/src/routes/dossiers/_post/index.ts +++ b/src/routes/dossiers/_post/index.ts @@ -222,6 +222,7 @@ export default class RouteItem extends AdminRoute<{ customer_title: this.getBody().title.customer, os: os.join(","), form_factor: form_factor.join(","), + base_bug_internal_id: "UG", ...(campaignToDuplicate ? { desired_number_of_testers: From 7dcd3a8fe30d7ce0676aec13ba40937bc3b9afc5 Mon Sep 17 00:00:00 2001 From: Davide Bizzi Date: Mon, 20 May 2024 10:36:21 +0200 Subject: [PATCH 08/12] chore: Add 206 type --- src/reference/openapi.yml | 11 +++++++++++ src/schema.ts | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/src/reference/openapi.yml b/src/reference/openapi.yml index f286791d7..fb9da6131 100644 --- a/src/reference/openapi.yml +++ b/src/reference/openapi.yml @@ -9759,6 +9759,17 @@ paths: Example 1: value: id: 1 + '206': + description: Partial Content + content: + application/json: + schema: + type: object + properties: + id: + type: integer + x-stoplight: + id: y5n0dny2hhlc8 security: - JWT: [] requestBody: diff --git a/src/schema.ts b/src/schema.ts index a52c80903..5ef83b0b0 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -4111,6 +4111,14 @@ export interface operations { }; }; }; + /** Partial Content */ + 206: { + content: { + "application/json": { + id?: number; + }; + }; + }; }; requestBody: { content: { From d0d29ae5ac8e4229fe0ba3c6a05c989ff2bfe99a Mon Sep 17 00:00:00 2001 From: Davide Bizzi Date: Mon, 20 May 2024 10:50:21 +0200 Subject: [PATCH 09/12] fix: Use correct env --- src/features/webhookTrigger/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/webhookTrigger/index.ts b/src/features/webhookTrigger/index.ts index 3a2adec6d..d12aa6269 100644 --- a/src/features/webhookTrigger/index.ts +++ b/src/features/webhookTrigger/index.ts @@ -15,7 +15,7 @@ export class WebhookTrigger data: Extract["data"]; }) { if (type === "status_change") { - this.webhookUrl = process.env.STATUS_CHANGE_WEBHOOK_URL || ""; + this.webhookUrl = process.env.STATUS_CHANGE_WEBHOOK || ""; } else if (type === "campaign_created") { this.webhookUrl = process.env.CAMPAIGN_CREATION_WEBHOOK || ""; } else { From f10783fb62f0e8ec66ca0d0a613b63fa77c6cc69 Mon Sep 17 00:00:00 2001 From: Davide Bizzi Date: Mon, 20 May 2024 11:02:38 +0200 Subject: [PATCH 10/12] feat: Return hook failed --- src/reference/openapi.yml | 8 ++++++++ src/routes/dossiers/_post/index.ts | 3 ++- src/schema.ts | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/reference/openapi.yml b/src/reference/openapi.yml index 30716fc60..d82fcca58 100644 --- a/src/reference/openapi.yml +++ b/src/reference/openapi.yml @@ -9755,6 +9755,14 @@ paths: properties: id: type: integer + message: + type: string + x-stoplight: + id: 8a0ic1hhs5mpz + enum: + - HOOK_FAILED + required: + - id examples: Example 1: value: diff --git a/src/routes/dossiers/_post/index.ts b/src/routes/dossiers/_post/index.ts index e0b69d937..93e2efd4c 100644 --- a/src/routes/dossiers/_post/index.ts +++ b/src/routes/dossiers/_post/index.ts @@ -148,8 +148,9 @@ export default class RouteItem extends AdminRoute<{ id: campaignId, }); } catch (e) { - this.setSuccess(206, { + this.setSuccess(201, { id: campaignId, + message: "HOOK_FAILED", }); } } catch (e) { diff --git a/src/schema.ts b/src/schema.ts index 5ef83b0b0..9ad5667f8 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -4107,7 +4107,9 @@ export interface operations { 201: { content: { "application/json": { - id?: number; + id: number; + /** @enum {string} */ + message?: "HOOK_FAILED"; }; }; }; From 20407f4f1c36d033ac55e977d1d521d357dd25a4 Mon Sep 17 00:00:00 2001 From: Davide Bizzi Date: Mon, 20 May 2024 11:21:53 +0200 Subject: [PATCH 11/12] fix: Correct type --- src/reference/openapi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reference/openapi.yml b/src/reference/openapi.yml index d82fcca58..9d9c72387 100644 --- a/src/reference/openapi.yml +++ b/src/reference/openapi.yml @@ -3321,7 +3321,7 @@ paths: id: type: integer start: - type: integer + type: number end: type: integer mediaId: From 05ed9cf5eaeff4b972577bd06406bfe2cf0a2250 Mon Sep 17 00:00:00 2001 From: Davide Bizzi Date: Mon, 20 May 2024 11:29:38 +0200 Subject: [PATCH 12/12] chore: Use correct ype --- src/reference/openapi.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/reference/openapi.yml b/src/reference/openapi.yml index 9d9c72387..16a9bc1f8 100644 --- a/src/reference/openapi.yml +++ b/src/reference/openapi.yml @@ -2864,9 +2864,9 @@ paths: id: type: integer start: - type: integer + type: number end: - type: integer + type: number mediaId: type: integer url: @@ -3323,7 +3323,7 @@ paths: start: type: number end: - type: integer + type: number mediaId: type: integer description: