From c4f26930988b165d5641696fb79b204799c01113 Mon Sep 17 00:00:00 2001 From: Davide Bizzi Date: Fri, 24 Jan 2025 13:26:38 +0100 Subject: [PATCH 1/3] fix: clean up date handling in insert method --- src/routes/dossiers/_post/index.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/routes/dossiers/_post/index.ts b/src/routes/dossiers/_post/index.ts index 30877bbed..88359a00d 100644 --- a/src/routes/dossiers/_post/index.ts +++ b/src/routes/dossiers/_post/index.ts @@ -246,16 +246,13 @@ export default class RouteItem extends UserRoute<{ .insert({ title: this.getBody().title.tester, platform_id: 0, - /* start_date: + start_date: this.getBody().startDate?.toString().slice(0, 19).replace("T", " ") || "", end_date: this.getEndDate()?.toString().slice(0, 19).replace("T", " ") || "", close_date: - this.getCloseDate()?.toString().slice(0, 19).replace("T", " ") || "",*/ - start_date: this.getBody().startDate, - end_date: this.getEndDate(), - close_date: this.getCloseDate(), + this.getCloseDate()?.toString().slice(0, 19).replace("T", " ") || "", page_preview_id: 0, page_manual_id: 0, customer_id: 0, From d19b930ccf57178695a285d4fdb64b4aecf17b5b Mon Sep 17 00:00:00 2001 From: Davide Bizzi Date: Fri, 24 Jan 2025 13:44:33 +0100 Subject: [PATCH 2/3] fix: format date fields in campaign update to ensure proper string representation --- src/routes/dossiers/campaignId/_put/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/routes/dossiers/campaignId/_put/index.ts b/src/routes/dossiers/campaignId/_put/index.ts index b0719ce90..8aca6dcea 100644 --- a/src/routes/dossiers/campaignId/_put/index.ts +++ b/src/routes/dossiers/campaignId/_put/index.ts @@ -120,9 +120,13 @@ export default class RouteItem extends UserRoute<{ await tryber.tables.WpAppqEvdCampaign.do() .update({ title: this.getBody().title.tester, - start_date: this.getBody().startDate, - end_date: this.getEndDate(), - close_date: this.getCloseDate(), + start_date: + this.getBody().startDate?.toString().slice(0, 19).replace("T", " ") || + "", + end_date: + this.getEndDate()?.toString().slice(0, 19).replace("T", " ") || "", + close_date: + this.getCloseDate()?.toString().slice(0, 19).replace("T", " ") || "", pm_id: this.getBody().csm ?? this.getTesterId(), project_id: this.getBody().project, campaign_type_id: this.getBody().testType, From f18bc8c0d030be73a8026155ae1ad548fa149159 Mon Sep 17 00:00:00 2001 From: Davide Bizzi Date: Fri, 24 Jan 2025 13:56:17 +0100 Subject: [PATCH 3/3] fix: update date format in campaign tests to use space instead of 'T' --- src/routes/dossiers/_post/creation.spec.ts | 10 +++++----- src/routes/dossiers/campaignId/_put/index.ts | 1 - src/routes/dossiers/campaignId/_put/update.spec.ts | 12 +++++------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/routes/dossiers/_post/creation.spec.ts b/src/routes/dossiers/_post/creation.spec.ts index b48a3eab8..b8ba68957 100644 --- a/src/routes/dossiers/_post/creation.spec.ts +++ b/src/routes/dossiers/_post/creation.spec.ts @@ -229,7 +229,7 @@ describe("Route POST /dossiers", () => { .where({ id }) .first(); - expect(campaign).toHaveProperty("start_date", "2021-08-24T14:15:22Z"); + expect(campaign).toHaveProperty("start_date", "2021-08-24 14:15:22"); }); it("Should create a campaign with the specified end date ", async () => { @@ -250,7 +250,7 @@ describe("Route POST /dossiers", () => { .where({ id }) .first(); - expect(campaign).toHaveProperty("end_date", "2021-08-20T14:15:22Z"); + expect(campaign).toHaveProperty("end_date", "2021-08-20 14:15:22"); }); it("Should create a campaign with the specified close date ", async () => { @@ -271,7 +271,7 @@ describe("Route POST /dossiers", () => { .where({ id }) .first(); - expect(campaign).toHaveProperty("close_date", "2021-08-20T14:15:22Z"); + expect(campaign).toHaveProperty("close_date", "2021-08-20 14:15:22"); }); it("Should create a campaign with the end date as start date + 7 if left unspecified", async () => { @@ -292,7 +292,7 @@ describe("Route POST /dossiers", () => { .where({ id }) .first(); - expect(campaign).toHaveProperty("end_date", "2021-08-27T14:15:22Z"); + expect(campaign).toHaveProperty("end_date", "2021-08-27 14:15:22"); }); it("Should create a campaign with the close date as start date + 14 if left unspecified", async () => { @@ -313,7 +313,7 @@ describe("Route POST /dossiers", () => { .where({ id }) .first(); - expect(campaign).toHaveProperty("close_date", "2021-09-03T14:15:22Z"); + expect(campaign).toHaveProperty("close_date", "2021-09-03 14:15:22"); }); it("Should create a campaign with current user as pm_id if left unspecified", async () => { diff --git a/src/routes/dossiers/campaignId/_put/index.ts b/src/routes/dossiers/campaignId/_put/index.ts index 8aca6dcea..1a0723670 100644 --- a/src/routes/dossiers/campaignId/_put/index.ts +++ b/src/routes/dossiers/campaignId/_put/index.ts @@ -116,7 +116,6 @@ 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, diff --git a/src/routes/dossiers/campaignId/_put/update.spec.ts b/src/routes/dossiers/campaignId/_put/update.spec.ts index be9f9d4d5..7a73983ac 100644 --- a/src/routes/dossiers/campaignId/_put/update.spec.ts +++ b/src/routes/dossiers/campaignId/_put/update.spec.ts @@ -265,7 +265,7 @@ describe("Route POST /dossiers", () => { .where({ id }) .first(); - expect(campaign).toHaveProperty("start_date", "2021-08-24T14:15:22Z"); + expect(campaign).toHaveProperty("start_date", "2021-08-24 14:15:22"); }); it("Should update the campaign with the specified end date ", async () => { @@ -286,7 +286,7 @@ describe("Route POST /dossiers", () => { .where({ id }) .first(); - expect(campaign).toHaveProperty("end_date", "2021-08-20T14:15:22Z"); + expect(campaign).toHaveProperty("end_date", "2021-08-20 14:15:22"); }); it("Should update the campaign with the specified close date ", async () => { @@ -307,7 +307,7 @@ describe("Route POST /dossiers", () => { .where({ id }) .first(); - expect(campaign).toHaveProperty("close_date", "2021-08-20T14:15:22Z"); + expect(campaign).toHaveProperty("close_date", "2021-08-20 14:15:22"); }); it("Should leave the end date of the campaign unedited if left unspecified", async () => { @@ -328,7 +328,7 @@ describe("Route POST /dossiers", () => { .where({ id }) .first(); - expect(campaign).toHaveProperty("end_date", "2019-08-24T14:15:22Z"); + expect(campaign).toHaveProperty("end_date", "2019-08-24 14:15:22"); }); it("Should leave the close date of the campaign unedited if left unspecified", async () => { @@ -349,7 +349,7 @@ describe("Route POST /dossiers", () => { .where({ id }) .first(); - expect(campaign).toHaveProperty("close_date", "2019-08-25T14:15:22Z"); + expect(campaign).toHaveProperty("close_date", "2019-08-25 14:15:22"); }); it("Should update the campaign with current user as pm_id", async () => { @@ -614,7 +614,6 @@ describe("Route POST /dossiers", () => { const responseGet = await request(app) .get("/dossiers/1") .set("authorization", "Bearer admin"); - console.log(responseGet.body); expect(responseGet.status).toBe(200); expect(responseGet.body).toHaveProperty("countries", ["DE", "FR"]); }); @@ -630,7 +629,6 @@ describe("Route POST /dossiers", () => { const responseGet = await request(app) .get("/dossiers/1") .set("authorization", "Bearer admin"); - console.log(responseGet.body); expect(responseGet.status).toBe(200); expect(responseGet.body).toHaveProperty("languages"); expect(responseGet.body.languages).toHaveLength(1);