From ee39cdf1f8abcd20f2224bb2c24dd5424beafbf8 Mon Sep 17 00:00:00 2001 From: sinatragianpaolo Date: Mon, 17 Jun 2024 23:44:30 +0200 Subject: [PATCH 1/4] refactor(patch-ux): remove insights from body --- src/reference/openapi.yml | 84 --------------------------------------- src/schema.ts | 16 -------- 2 files changed, 100 deletions(-) diff --git a/src/reference/openapi.yml b/src/reference/openapi.yml index 970965644..8551835d3 100644 --- a/src/reference/openapi.yml +++ b/src/reference/openapi.yml @@ -3290,61 +3290,6 @@ paths: type: string usersNumber: type: integer - insights: - type: array - items: - type: object - properties: - id: - type: integer - title: - type: string - description: - type: string - maxLength: 350 - severityId: - type: integer - order: - type: integer - clusterIds: - oneOf: - - type: array - items: - type: integer - - type: string - enum: - - all - videoParts: - type: array - items: - type: object - properties: - id: - type: integer - start: - type: number - end: - type: number - mediaId: - type: integer - description: - type: string - maxLength: 150 - order: - type: integer - required: - - start - - end - - mediaId - - description - - order - required: - - title - - description - - severityId - - order - - clusterIds - - videoParts sentiments: type: array items: @@ -3391,7 +3336,6 @@ paths: required: - goal - usersNumber - - insights - sentiments - methodology - questions @@ -3411,21 +3355,6 @@ paths: methodology: description: Methodology Description type: quantitative - insights: - - id: 5 - title: string - description: string - severityId: 0 - order: 0 - clusterIds: - - 0 - videoParts: - - id: 7 - start: 0 - end: 0 - mediaId: 0 - description: string - order: 0 sentiments: - clusterId: 0 value: 4 @@ -3451,19 +3380,6 @@ paths: methodology: description: Methodology Description type: qualitative - insights: - - title: string - description: string - severityId: 0 - order: 0 - clusterIds: - - 0 - videoParts: - - start: 0 - end: 0 - mediaId: 0 - description: string - order: 0 sentiments: - clusterId: 0 value: 4 diff --git a/src/schema.ts b/src/schema.ts index bd748dcd9..e65595d22 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -2030,22 +2030,6 @@ export interface operations { | { goal: string; usersNumber: number; - insights: { - id?: number; - title: string; - description: string; - severityId: number; - order: number; - clusterIds: number[] | "all"; - videoParts: { - id?: number; - start: number; - end: number; - mediaId: number; - description: string; - order: number; - }[]; - }[]; sentiments: { id?: number; clusterId: number; From 88a1940850ec7f49476c09754d1665383629c1b3 Mon Sep 17 00:00:00 2001 From: sinatragianpaolo Date: Tue, 18 Jun 2024 00:00:26 +0200 Subject: [PATCH 2/4] feat: Remove unused code for insights in PATCH /campaigns/{campaignId}/ux --- .../campaignId/ux/_patch/from-draft.spec.ts | 470 ------------------ .../campaignId/ux/_patch/from-publish.spec.ts | 235 --------- .../campaigns/campaignId/ux/_patch/index.ts | 200 -------- .../campaignId/ux/_patch/no-data.spec.ts | 164 ------ 4 files changed, 1069 deletions(-) diff --git a/src/routes/campaigns/campaignId/ux/_patch/from-draft.spec.ts b/src/routes/campaigns/campaignId/ux/_patch/from-draft.spec.ts index 8c95a020f..ab46108ef 100644 --- a/src/routes/campaigns/campaignId/ux/_patch/from-draft.spec.ts +++ b/src/routes/campaigns/campaignId/ux/_patch/from-draft.spec.ts @@ -68,26 +68,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft", () => { methodology_type: methodology.type, }); - await tryber.tables.UxCampaignInsights.do().insert({ - id: 1, - campaign_id: 1, - version: 1, - title: "Draft insight", - description: "Draft description", - severity_id: 1, - cluster_ids: "1", - finding_id: 10, - enabled: 1, - }); - - await tryber.tables.UxCampaignVideoParts.do().insert({ - id: 1, - insight_id: 1, - start: 0, - end: 10, - description: "My video", - media_id: 1, - }); await tryber.tables.UxCampaignQuestions.do().insert([ { id: 1, @@ -137,8 +117,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft", () => { }); afterEach(async () => { await tryber.tables.UxCampaignData.do().delete(); - await tryber.tables.UxCampaignInsights.do().delete(); - await tryber.tables.UxCampaignVideoParts.do().delete(); await tryber.tables.UxCampaignQuestions.do().delete(); await tryber.tables.UxCampaignSentiments.do().delete(); }); @@ -150,7 +128,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [], methodology, @@ -171,163 +148,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft", () => { ); }); - it("Should disable the insights as draft if the insights are not sent ", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [], - sentiments: [], - questions: [], - methodology, - }); - - const insights = await tryber.tables.UxCampaignInsights.do() - .select() - .where({ enabled: 1 }); - expect(insights).toHaveLength(0); - }); - - it("Should thrown an error if trying to edit an insight that not exists", async () => { - const response = await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [ - { - id: 1000, - title: "Draft invalid insight", - description: "Draft invalid description", - severityId: 2, - clusterIds: "all", - order: 0, - videoParts: [], - }, - ], - sentiments: [], - questions: [], - methodology, - }); - - expect(response.status).toBe(500); - - const insights = await tryber.tables.UxCampaignInsights.do().select(); - expect(insights).toHaveLength(1); - expect(insights[0]).toEqual( - expect.objectContaining({ - campaign_id: 1, - cluster_ids: "1", - description: "Draft description", - id: 1, - order: 0, - severity_id: 1, - title: "Draft insight", - version: 1, - }) - ); - }); - - it("Should insert a insights as draft if an item without id is sent", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [ - { - id: 1, - title: "Draft insight", - description: "Draft description", - severityId: 1, - clusterIds: [1], - order: 0, - videoParts: [], - }, - { - title: "New insight", - description: "New description", - severityId: 2, - clusterIds: "all", - order: 1, - videoParts: [], - }, - ], - sentiments: [], - questions: [], - methodology, - }); - - const insights = await tryber.tables.UxCampaignInsights.do().select(); - expect(insights).toHaveLength(2); - expect(insights[0]).toEqual( - expect.objectContaining({ - campaign_id: 1, - cluster_ids: "1", - description: "Draft description", - order: 0, - severity_id: 1, - finding_id: 10, - title: "Draft insight", - version: 1, - }) - ); - expect(insights[1]).toEqual( - expect.objectContaining({ - campaign_id: 1, - cluster_ids: "0", - description: "New description", - order: 1, - severity_id: 2, - finding_id: 11, - title: "New insight", - version: 1, - }) - ); - }); - - it("Should update a insights as draft if an item with id is sent", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [ - { - id: 1, - title: "Updated insight", - description: "Updated description", - severityId: 2, - clusterIds: "all", - order: 1, - videoParts: [], - }, - ], - sentiments: [], - questions: [], - methodology, - }); - - const insights = await tryber.tables.UxCampaignInsights.do().select(); - expect(insights).toHaveLength(1); - expect(insights[0]).toEqual( - expect.objectContaining({ - campaign_id: 1, - cluster_ids: "0", - description: "Updated description", - order: 1, - severity_id: 2, - title: "Updated insight", - version: 1, - }) - ); - }); - it("Should insert a question as draft if an item without id is sent", async () => { await request(app) .patch("/campaigns/1/ux") @@ -335,7 +155,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [ { @@ -376,7 +195,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [ { @@ -406,7 +224,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [ { id: 1, @@ -445,7 +262,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [], methodology: { ...methodology, type: "quali-quantitative" }, @@ -478,7 +294,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [], methodology: { ...methodology, description: "The new description" }, @@ -513,7 +328,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft", () => { .send({ goal: "New Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [], methodology, @@ -546,7 +360,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft", () => { .send({ goal: "Test Goal", usersNumber: 6, - insights: [], sentiments: [], questions: [], methodology, @@ -603,288 +416,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft", () => { ); }); - it("Should create a new version of insights on publish", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - status: "publish", - }); - - const insights = await tryber.tables.UxCampaignInsights.do().select(); - expect(insights).toHaveLength(2); - expect(insights[0]).toEqual( - expect.objectContaining({ - campaign_id: 1, - version: 1, - title: "Draft insight", - description: "Draft description", - severity_id: 1, - cluster_ids: "1", - }) - ); - expect(insights[1]).toEqual( - expect.objectContaining({ - campaign_id: 1, - version: 2, - title: "Draft insight", - description: "Draft description", - severity_id: 1, - cluster_ids: "1", - finding_id: 10, - }) - ); - }); - - it("Should remove insight videopart if empty", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [ - { - id: 1, - title: "My insight", - description: "My description", - severityId: 1, - order: 0, - clusterIds: "all", - videoParts: [], - }, - ], - sentiments: [], - questions: [], - methodology, - }); - - const videoParts = await tryber.tables.UxCampaignVideoParts.do().select(); - expect(videoParts).toHaveLength(0); - }); - - it("Should add insight videopart as draft", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [ - { - id: 1, - title: "My insight", - description: "My description", - severityId: 1, - order: 0, - clusterIds: "all", - videoParts: [ - { - id: 1, - start: 0, - end: 10, - mediaId: 1, - description: "My video", - order: 0, - }, - { - start: 10, - end: 100, - mediaId: 1, - description: "My second video", - order: 1, - }, - ], - }, - ], - sentiments: [], - questions: [], - methodology, - }); - - const data = await tryber.tables.UxCampaignInsights.do().select(); - expect(data).toHaveLength(1); - const insightId = data[0].id; - const videoParts = await tryber.tables.UxCampaignVideoParts.do().select(); - expect(videoParts).toHaveLength(2); - expect(videoParts[0]).toEqual( - expect.objectContaining({ - start: 0, - end: 10, - media_id: 1, - description: "My video", - order: 0, - insight_id: insightId, - }) - ); - expect(videoParts[1]).toEqual( - expect.objectContaining({ - start: 10, - end: 100, - media_id: 1, - description: "My second video", - order: 1, - insight_id: insightId, - }) - ); - }); - - it("Should update insight videopart as draft", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [ - { - id: 1, - title: "My insight", - description: "My description", - severityId: 1, - order: 0, - clusterIds: "all", - videoParts: [ - { - id: 1, - start: 10, - end: 100, - mediaId: 1, - description: "Updated video", - order: 1, - }, - ], - }, - ], - sentiments: [], - questions: [], - methodology, - }); - - const data = await tryber.tables.UxCampaignInsights.do().select(); - expect(data).toHaveLength(1); - const insightId = data[0].id; - const videoParts = await tryber.tables.UxCampaignVideoParts.do().select(); - expect(videoParts).toHaveLength(1); - expect(videoParts[0]).toEqual( - expect.objectContaining({ - start: 10, - end: 100, - media_id: 1, - description: "Updated video", - order: 1, - insight_id: insightId, - }) - ); - }); - - it("Should insert new insight with videopart as draft", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [ - { - title: "My new insight", - description: "My new description", - severityId: 1, - order: 0, - clusterIds: "all", - videoParts: [ - { - start: 10, - end: 100, - mediaId: 1, - description: "New video", - order: 0, - }, - ], - }, - ], - sentiments: [], - questions: [], - methodology, - }); - - const data = await tryber.tables.UxCampaignInsights.do() - .select() - .where({ enabled: 1 }); - expect(data).toHaveLength(1); - expect(data[0]).toEqual( - expect.objectContaining({ - campaign_id: 1, - cluster_ids: "0", - description: "My new description", - order: 0, - severity_id: 1, - title: "My new insight", - version: 1, - finding_id: 11, - }) - ); - const insightId = data[0].id; - const videoParts = await tryber.tables.UxCampaignVideoParts.do().select(); - expect(videoParts).toHaveLength(1); - expect(videoParts[0]).toEqual( - expect.objectContaining({ - start: 10, - end: 100, - media_id: 1, - description: "New video", - order: 0, - insight_id: insightId, - }) - ); - }); - - it("Should create a new version of videoparts on publish", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - status: "publish", - }); - - const publishInsight = await tryber.tables.UxCampaignInsights.do() - .select() - .where({ - version: 1, - campaign_id: 1, - }) - .first(); - - const draftInsight = await tryber.tables.UxCampaignInsights.do() - .select() - .where({ - version: 2, - campaign_id: 1, - }) - .first(); - expect(publishInsight).toBeDefined(); - expect(draftInsight).toBeDefined(); - - if (!publishInsight || !draftInsight) throw new Error("Insight not found"); - - const publishVideoParts = await tryber.tables.UxCampaignVideoParts.do() - .select() - .where({ - insight_id: publishInsight.id, - }) - .first(); - - const draftVideoPart = await tryber.tables.UxCampaignVideoParts.do() - .select() - .where({ - insight_id: draftInsight.id, - }) - .first(); - - expect(publishVideoParts).toBeDefined(); - expect(draftVideoPart).toBeDefined(); - }); - it("Should create a new version of questions on publish", async () => { const questionsBeforePatch = await tryber.tables.UxCampaignQuestions.do() .select() @@ -991,7 +522,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [ { id: 1, diff --git a/src/routes/campaigns/campaignId/ux/_patch/from-publish.spec.ts b/src/routes/campaigns/campaignId/ux/_patch/from-publish.spec.ts index 85c59f35b..72fff29a3 100644 --- a/src/routes/campaigns/campaignId/ux/_patch/from-publish.spec.ts +++ b/src/routes/campaigns/campaignId/ux/_patch/from-publish.spec.ts @@ -68,49 +68,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from publish", () => { }, ]); - await tryber.tables.UxCampaignInsights.do().insert([ - { - id: 1, - campaign_id: 1, - version: 1, - title: "Publish insight", - description: "Publish description", - severity_id: 1, - cluster_ids: "1", - finding_id: 10, - enabled: 1, - }, - { - id: 2, - campaign_id: 1, - version: 2, - title: "Draft insight", - description: "Draft description", - severity_id: 1, - cluster_ids: "1", - finding_id: 20, - enabled: 1, - }, - ]); - - await tryber.tables.UxCampaignVideoParts.do().insert([ - { - id: 1, - media_id: 1, - insight_id: 1, - start: 0, - end: 10, - description: "Publish video part", - }, - { - id: 2, - media_id: 1, - insight_id: 1, - start: 0, - end: 10, - description: "Draft video part", - }, - ]); await tryber.tables.UxCampaignQuestions.do().insert([ { id: 1, @@ -135,8 +92,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from publish", () => { afterEach(async () => { await tryber.tables.UxCampaignData.do().delete(); - await tryber.tables.UxCampaignInsights.do().delete(); - await tryber.tables.UxCampaignVideoParts.do().delete(); await tryber.tables.UxCampaignQuestions.do().delete(); }); @@ -147,7 +102,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from publish", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [], methodology, @@ -175,52 +129,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from publish", () => { ); }); - it("Should disable insights from the draft", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [], - sentiments: [], - questions: [], - methodology, - }); - - const data = await tryber.tables.UxCampaignInsights.do().select(); - - expect(data).toHaveLength(2); - expect(data[0]).toEqual( - expect.objectContaining({ - id: 1, - campaign_id: 1, - cluster_ids: "1", - description: "Publish description", - order: 0, - severity_id: 1, - title: "Publish insight", - version: 1, - finding_id: 10, - enabled: 1, - }) - ); - expect(data[1]).toEqual( - expect.objectContaining({ - id: 2, - campaign_id: 1, - cluster_ids: "1", - description: "Draft description", - order: 0, - severity_id: 1, - title: "Draft insight", - version: 2, - finding_id: 20, - enabled: 0, - }) - ); - }); - it("Should update a methodology description in the draft", async () => { const draftBefore = await tryber.tables.UxCampaignData.do() .select("methodology_description") @@ -232,7 +140,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from publish", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [], methodology: { ...methodology, description: "New description" }, @@ -259,7 +166,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from publish", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [], methodology: { ...methodology, type: "quantitative" }, @@ -287,7 +193,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from publish", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [{ name: "Updated Draft Question", id: 2 }], methodology, @@ -312,7 +217,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from publish", () => { .send({ goal: "New Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [], methodology, @@ -337,7 +241,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from publish", () => { .send({ goal: "Test Goal", usersNumber: 6, - insights: [], sentiments: [], questions: [], methodology, @@ -350,142 +253,4 @@ describe("PATCH /campaigns/{campaignId}/ux - from publish", () => { expect(updatedDraft?.users).not.toEqual(draftBefore?.users); expect(updatedDraft?.users).toEqual(6); }); - - it("Should insert a insights in the draft", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [ - { - id: 2, - title: "Draft insight", - description: "Draft description", - severityId: 1, - clusterIds: [1], - order: 0, - videoParts: [], - }, - { - title: "New insight", - description: "New description", - severityId: 2, - clusterIds: "all", - order: 1, - videoParts: [], - }, - ], - sentiments: [], - questions: [], - methodology, - }); - - const insights = await tryber.tables.UxCampaignInsights.do().select(); - expect(insights).toHaveLength(3); - expect(insights[0]).toEqual( - expect.objectContaining({ - campaign_id: 1, - cluster_ids: "1", - description: "Publish description", - order: 0, - severity_id: 1, - title: "Publish insight", - version: 1, - }) - ); - - expect(insights[1]).toEqual( - expect.objectContaining({ - campaign_id: 1, - cluster_ids: "1", - description: "Draft description", - order: 0, - severity_id: 1, - title: "Draft insight", - version: 2, - }) - ); - expect(insights[2]).toEqual( - expect.objectContaining({ - campaign_id: 1, - cluster_ids: "0", - description: "New description", - order: 1, - severity_id: 2, - title: "New insight", - version: 2, - }) - ); - }); - - it("Should insert a insights video part in the draft", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [ - { - id: 2, - title: "Draft insight", - description: "Draft description", - severityId: 1, - clusterIds: [1], - order: 0, - videoParts: [ - { - id: 2, - start: 0, - end: 10, - mediaId: 1, - description: "Draft video part", - order: 0, - }, - { - start: 10, - end: 100, - mediaId: 1, - description: "New video part", - order: 1, - }, - ], - }, - { - title: "New insight", - description: "New description", - severityId: 2, - clusterIds: "all", - order: 1, - videoParts: [], - }, - ], - sentiments: [], - questions: [], - methodology, - }); - - const videoPart = await tryber.tables.UxCampaignVideoParts.do().select(); - expect(videoPart).toHaveLength(3); - expect(videoPart[0]).toEqual( - expect.objectContaining({ - id: 1, - description: "Publish video part", - }) - ); - expect(videoPart[1]).toEqual( - expect.objectContaining({ - id: 2, - description: "Draft video part", - }) - ); - expect(videoPart[2]).toEqual( - expect.objectContaining({ - id: 3, - description: "New video part", - }) - ); - }); }); diff --git a/src/routes/campaigns/campaignId/ux/_patch/index.ts b/src/routes/campaigns/campaignId/ux/_patch/index.ts index 46666df4f..5c74af590 100644 --- a/src/routes/campaigns/campaignId/ux/_patch/index.ts +++ b/src/routes/campaigns/campaignId/ux/_patch/index.ts @@ -35,57 +35,14 @@ export default class PatchUx extends UserRoute<{ return this.setNoAccessError(); } - if (await this.isThereNonExistingMediaInBody()) { - this.setError(400, new OpenapiError(`Media not found`)); - return false; - } - if (this.invalidSentimentsValues()) { this.setError(500, new OpenapiError(`Sentiment values are invalid`)); throw new OpenapiError(`Sentiment values are invalid`); } - if (this.thereAreInvalidFindingIds()) { - this.setError(500, new OpenapiError(`Insight not found`)); - throw new OpenapiError(`Insights with id not found`); - } - return true; } - private async isThereNonExistingMediaInBody() { - const body = this.getBody(); - if (!("status" in body)) { - const { insights } = body; - if (insights) { - const videoParts = insights.flatMap((i) => i.videoParts || []); - const mediaIds = videoParts.map((v) => v.mediaId); - const media = await tryber.tables.WpAppqUserTaskMedia.do() - .select() - .whereIn("id", mediaIds); - if ([...new Set(media)].length !== [...new Set(mediaIds)].length) { - return true; - } - } - } - return false; - } - - private thereAreInvalidFindingIds() { - const body = this.getBody(); - if ("status" in body) return false; - const { insights } = body; - const toUpdate = insights.filter((i) => i.id); - const currentInsights = this.lastDraft?.findings || []; - const currentInsightIds = currentInsights.map((i) => i.id); - - const notFoundIds = toUpdate - .map((i) => i.id) - .filter((id) => !currentInsightIds.includes(id as number)); - - return notFoundIds.length > 0; - } - private invalidSentimentsValues() { const body = this.getBody(); if ("status" in body) return false; @@ -136,7 +93,6 @@ export default class PatchUx extends UserRoute<{ } await this.updateUxData(); - await this.updateInsights(); await this.updateQuestions(); await this.updateSentiments(); } @@ -172,13 +128,6 @@ export default class PatchUx extends UserRoute<{ .where({ campaign_id: this.campaignId }); } - private async updateInsights() { - await this.removeFindings(); - - await this.insertNewFindings(); - await this.updateExistingFindings(); - } - private async updateQuestions() { await this.removeQuestions(); await this.insertNewQuestions(); @@ -326,155 +275,6 @@ export default class PatchUx extends UserRoute<{ } } - private async removeFindings() { - const body = this.getBody(); - if ("status" in body) return; - const { insights } = body; - - const toUpdate = insights.filter((i) => i.id); - const currentInsights = this.lastDraft?.findings || []; - const currentInsightIds = currentInsights.map((i) => i.id); - - const toRemove = currentInsightIds.filter( - (id) => !toUpdate.map((i) => i.id).includes(id as number) - ); - - if (toRemove.length) { - await tryber.tables.UxCampaignInsights.do() - .update("enabled", 0) - .whereIn( - "id", - currentInsightIds.filter( - (id) => !toUpdate.map((i) => i.id).includes(id as number) - ) - ); - - await tryber.tables.UxCampaignVideoParts.do() - .delete() - .whereIn( - "insight_id", - currentInsightIds.filter( - (id) => !toUpdate.map((i) => i.id).includes(id as number) - ) - ); - } - } - - private async insertNewFindings() { - const body = this.getBody(); - if ("status" in body) return; - const { insights } = body; - - const toInsert = insights.filter((i) => !i.id); - if (toInsert.length) { - for (const item of toInsert) { - const maxFindingId = await tryber.tables.UxCampaignInsights.do() - .max("finding_id", { as: "max" }) - .first(); - - const insight = await tryber.tables.UxCampaignInsights.do() - .insert({ - campaign_id: this.campaignId, - cluster_ids: - item.clusterIds === "all" ? "0" : item.clusterIds.join(","), - description: item.description, - order: item.order, - severity_id: item.severityId, - title: item.title, - version: this.version, - finding_id: maxFindingId?.max ? maxFindingId?.max + 1 : 1, - }) - .returning("id"); - if (item.videoParts && item.videoParts.length) { - const insightId = insight[0].id ?? insight[0]; - await tryber.tables.UxCampaignVideoParts.do().insert( - item.videoParts.map((v) => ({ - start: v.start, - end: v.end, - media_id: v.mediaId, - description: v.description, - order: v.order, - insight_id: insightId, - })) - ); - } - } - } - } - - private async updateExistingFindings() { - const body = this.getBody(); - if ("status" in body) return; - const { insights } = body; - const updatedFindings = insights.filter((i) => i.id); - - if (updatedFindings.length) { - for (const item of updatedFindings) { - await tryber.tables.UxCampaignInsights.do() - .update({ - cluster_ids: - item.clusterIds === "all" ? "0" : item.clusterIds.join(","), - description: item.description, - order: item.order, - severity_id: item.severityId, - title: item.title, - version: this.version, - }) - .where({ - id: item.id, - }); - - const newVideoParts = item.videoParts.filter((i) => !i.id); - - if (newVideoParts.length) { - await tryber.tables.UxCampaignVideoParts.do().insert( - newVideoParts.map((v) => ({ - start: v.start, - end: v.end, - media_id: v.mediaId, - description: v.description, - order: v.order, - insight_id: item.id, - })) - ); - } - const updatedVideoParts = item.videoParts.filter((i) => i.id); - - const currentVideoParts = (this.lastDraft?.findings || []).flatMap( - (f) => (f.id == item.id && f.videoParts ? f.videoParts : []) - ); - - const currentVideoPartIds = currentVideoParts.map((i) => i.id); - const updatedVideoPartsIds = updatedVideoParts.map((i) => i.id); - - const toRemove = currentVideoPartIds.filter( - (id) => !updatedVideoPartsIds.includes(id as number) - ); - - if (toRemove.length) { - await tryber.tables.UxCampaignVideoParts.do() - .delete() - .whereIn("id", toRemove); - } - - for (const videoPart of updatedVideoParts) { - await tryber.tables.UxCampaignVideoParts.do() - .update({ - start: videoPart.start, - end: videoPart.end, - media_id: videoPart.mediaId, - description: videoPart.description, - order: videoPart.order, - insight_id: item.id, - }) - .where({ - id: videoPart.id, - }); - } - } - } - } - private async publish() { const draftData = this.lastDraft?.data; if (!draftData) { diff --git a/src/routes/campaigns/campaignId/ux/_patch/no-data.spec.ts b/src/routes/campaigns/campaignId/ux/_patch/no-data.spec.ts index f3355d15b..ec27d2ada 100644 --- a/src/routes/campaigns/campaignId/ux/_patch/no-data.spec.ts +++ b/src/routes/campaigns/campaignId/ux/_patch/no-data.spec.ts @@ -59,8 +59,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from empty", () => { afterEach(async () => { await tryber.tables.UxCampaignData.do().delete(); - await tryber.tables.UxCampaignInsights.do().delete(); - await tryber.tables.UxCampaignVideoParts.do().delete(); await tryber.tables.UxCampaignQuestions.do().delete(); await tryber.tables.UxCampaignSentiments.do().delete(); await tryber.tables.WpAppqUsecaseCluster.do().delete(); @@ -73,16 +71,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from empty", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [ - { - title: "My insight", - description: "My description", - severityId: 1, - order: 0, - clusterIds: "all", - videoParts: [], - }, - ], sentiments: [], questions: [], methodology, @@ -102,71 +90,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from empty", () => { ); }); - it("Should insert insight as draft", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [ - { - title: "My insight", - description: "My description", - severityId: 1, - order: 0, - clusterIds: "all", - videoParts: [], - }, - ], - sentiments: [], - questions: [], - methodology, - }); - const data = await tryber.tables.UxCampaignInsights.do().select(); - expect(data).toHaveLength(1); - expect(data[0]).toEqual( - expect.objectContaining({ - cluster_ids: "0", - description: "My description", - order: 0, - severity_id: 1, - title: "My insight", - }) - ); - }); - - it("Should insert insight as draft with correct finding_id", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [ - { - title: "My insight", - description: "My description", - severityId: 1, - order: 0, - clusterIds: "all", - videoParts: [], - }, - ], - sentiments: [], - questions: [], - methodology, - }); - - const data = await tryber.tables.UxCampaignInsights.do().select(); - expect(data).toHaveLength(1); - expect(data[0]).toEqual( - expect.objectContaining({ - finding_id: 1, - }) - ); - }); - it("Should insert question as draft", async () => { await request(app) .patch("/campaigns/1/ux") @@ -174,7 +97,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from empty", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [{ name: "Is there life on Mars?" }], methodology, @@ -198,7 +120,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from empty", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [{ value: 5, clusterId: 1, comment: "My comment" }], questions: [], methodology, @@ -218,53 +139,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from empty", () => { ); }); - it("Should insert insight videopart as draft", async () => { - await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [ - { - title: "My insight", - description: "My description", - severityId: 1, - order: 0, - clusterIds: "all", - videoParts: [ - { - start: 0, - end: 10, - mediaId: 1, - description: "My video", - order: 0, - }, - ], - }, - ], - sentiments: [], - questions: [], - methodology, - }); - - const data = await tryber.tables.UxCampaignInsights.do().select(); - expect(data).toHaveLength(1); - const insightId = data[0].id; - const videoParts = await tryber.tables.UxCampaignVideoParts.do().select(); - expect(videoParts).toHaveLength(1); - expect(videoParts[0]).toEqual( - expect.objectContaining({ - start: 0, - end: 10, - media_id: 1, - description: "My video", - order: 0, - insight_id: insightId, - }) - ); - }); - it("Should insert methodology type as draft", async () => { await request(app) .patch("/campaigns/1/ux") @@ -272,7 +146,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from empty", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [], methodology, @@ -294,7 +167,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from empty", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [], @@ -316,7 +188,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from empty", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [], @@ -338,7 +209,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from empty", () => { .send({ goal: "Test Goal", usersNumber: 6, - insights: [], sentiments: [], questions: [], @@ -353,40 +223,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from empty", () => { expect(data?.version).toEqual(1); }); - it("Should return 400 if inserting video part with invalid media id", async () => { - const response = await request(app) - .patch("/campaigns/1/ux") - .set("Authorization", "Bearer admin") - .send({ - goal: "Test Goal", - usersNumber: 5, - insights: [ - { - title: "My insight", - description: "My description", - severityId: 1, - order: 0, - clusterIds: "all", - videoParts: [ - { - start: 0, - end: 10, - mediaId: 99, - description: "My video", - order: 0, - }, - ], - }, - ], - sentiments: [], - questions: [], - - methodology, - }); - - expect(response.status).toBe(400); - }); - it("Should return 400 on publish", async () => { const response = await request(app) .patch("/campaigns/1/ux") From 337d826a078d1f30b6e6d54ddb35537755be8c71 Mon Sep 17 00:00:00 2001 From: sinatragianpaolo Date: Tue, 18 Jun 2024 12:45:24 +0200 Subject: [PATCH 3/4] Remove unused code for insights in PATCH /campaigns/{campaignId}/ux --- .../ux/_patch/delete-sentiments.spec.ts | 1 - .../ux/_patch/draft-modified.spec.ts | 102 ------------------ .../campaignId/ux/_patch/index.spec.ts | 1 - .../campaigns/campaignId/ux/_patch/index.ts | 39 ------- 4 files changed, 143 deletions(-) diff --git a/src/routes/campaigns/campaignId/ux/_patch/delete-sentiments.spec.ts b/src/routes/campaigns/campaignId/ux/_patch/delete-sentiments.spec.ts index 9ae4f1bfc..3bd8d672f 100644 --- a/src/routes/campaigns/campaignId/ux/_patch/delete-sentiments.spec.ts +++ b/src/routes/campaigns/campaignId/ux/_patch/delete-sentiments.spec.ts @@ -34,7 +34,6 @@ const campaign = { const requestBody = { goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [], methodology: { diff --git a/src/routes/campaigns/campaignId/ux/_patch/draft-modified.spec.ts b/src/routes/campaigns/campaignId/ux/_patch/draft-modified.spec.ts index 5337c80df..610bd26c6 100644 --- a/src/routes/campaigns/campaignId/ux/_patch/draft-modified.spec.ts +++ b/src/routes/campaigns/campaignId/ux/_patch/draft-modified.spec.ts @@ -59,81 +59,12 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft modified", () => { published: 0, }, ]); - - await tryber.tables.UxCampaignInsights.do().insert([ - { - id: 1, - campaign_id: 123, - version: 1, - title: "Publish insight", - description: "Publish description", - severity_id: 1, - cluster_ids: "1", - finding_id: 10, - enabled: 1, - }, - { - id: 2, - campaign_id: 123, - version: 1, - title: "Publish insight 2", - description: "Publish description 2", - severity_id: 1, - cluster_ids: "1", - finding_id: 20, - enabled: 1, - }, - // Draft modified insights - { - id: 3, - campaign_id: 123, - version: 2, - title: "Publish insight", - description: "Publish description", - severity_id: 1, - cluster_ids: "1", - finding_id: 10, - enabled: 1, - }, - { - id: 4, - campaign_id: 123, - version: 2, - title: "Publish insight 2", - description: "Publish description 2", - severity_id: 1, - cluster_ids: "1", - finding_id: 20, - enabled: 1, - }, - ]); - - await tryber.tables.UxCampaignVideoParts.do().insert([ - { - id: 1, - media_id: 1, - insight_id: 2, - start: 0, - end: 10, - description: "Publish video part", - }, - { - id: 2, - media_id: 1, - insight_id: 4, - start: 0, - end: 10, - description: "Publish video part", - }, - ]); }); afterAll(async () => { await tryber.tables.WpAppqEvdCampaign.do().delete(); await tryber.tables.UxCampaignData.do().delete(); await tryber.tables.WpAppqUserTaskMedia.do().delete(); - await tryber.tables.UxCampaignInsights.do().delete(); - await tryber.tables.UxCampaignVideoParts.do().delete(); await tryber.tables.UxCampaignQuestions.do().delete(); }); @@ -144,35 +75,6 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft modified", () => { .send({ goal: "Test Goal", usersNumber: 5, - insights: [ - { - id: 3, - title: "Publish insight", - description: "Publish description", - order: 0, - severityId: 1, - clusterIds: [1], - videoParts: [], - }, - { - id: 4, - title: "Publish insight 2", - description: "Publish description 2", - order: 0, - severityId: 1, - clusterIds: [1], - videoParts: [ - { - id: 2, - order: 0, - start: 0, - end: 10, - mediaId: 1, - description: "Publish video part", - }, - ], - }, - ], sentiments: [], questions: [], methodology, @@ -198,9 +100,5 @@ describe("PATCH /campaigns/{campaignId}/ux - from draft modified", () => { campaign_id: 123, }) ); - - const videoParts = await tryber.tables.UxCampaignVideoParts.do().select(); - - expect(videoParts.length).toBe(2); }); }); diff --git a/src/routes/campaigns/campaignId/ux/_patch/index.spec.ts b/src/routes/campaigns/campaignId/ux/_patch/index.spec.ts index 87d18745d..7f1206ae8 100644 --- a/src/routes/campaigns/campaignId/ux/_patch/index.spec.ts +++ b/src/routes/campaigns/campaignId/ux/_patch/index.spec.ts @@ -21,7 +21,6 @@ const campaign = { const requestBody = { goal: "Test Goal", usersNumber: 5, - insights: [], sentiments: [], questions: [], methodology: { diff --git a/src/routes/campaigns/campaignId/ux/_patch/index.ts b/src/routes/campaigns/campaignId/ux/_patch/index.ts index 5c74af590..656696436 100644 --- a/src/routes/campaigns/campaignId/ux/_patch/index.ts +++ b/src/routes/campaigns/campaignId/ux/_patch/index.ts @@ -283,7 +283,6 @@ export default class PatchUx extends UserRoute<{ } await this.publishData(); - await this.publishInsight(); await this.publishQuestions(); await this.publishSentiments(); this.version++; @@ -353,42 +352,4 @@ export default class PatchUx extends UserRoute<{ } } } - - private async publishInsight() { - const draftData = this.lastDraft?.data; - if (!draftData) throw new OpenapiError("No draft found"); - - let findingOrder = 0; - for (const insight of draftData.findings) { - const insertedInsight = await tryber.tables.UxCampaignInsights.do() - .insert({ - campaign_id: this.campaignId, - cluster_ids: - insight.clusters === "all" - ? "0" - : insight.clusters.map((c) => c.id).join(","), - description: insight.description, - order: findingOrder++, - severity_id: insight.severity.id, - title: insight.title, - version: this.version + 1, - finding_id: insight.findingId, - }) - .returning("id"); - - const insertedInsightId = insertedInsight[0].id ?? insertedInsight[0]; - - let videoPartOrder = 0; - for (const videoPart of insight.videoParts) { - await tryber.tables.UxCampaignVideoParts.do().insert({ - start: videoPart.start, - end: videoPart.end, - media_id: videoPart.mediaId, - description: videoPart.description, - order: videoPartOrder++, - insight_id: insertedInsightId, - }); - } - } - } } From f7c60d730a30aac3a5dc66b6d5e02e9462e09c96 Mon Sep 17 00:00:00 2001 From: sinatragianpaolo Date: Tue, 18 Jun 2024 15:30:19 +0200 Subject: [PATCH 4/4] refactor(get-campaigns-campaign-ux): remove insights and videopart --- src/reference/openapi.yml | 209 ------------------ src/routes/campaigns/campaignId/ux/UxData.ts | 188 +--------------- .../campaigns/campaignId/ux/_get/data.spec.ts | 163 -------------- .../ux/_get/deleted-clusters.spec.ts | 51 ----- .../campaignId/ux/_get/draft-modified.spec.ts | 112 +--------- .../campaigns/campaignId/ux/_get/index.ts | 1 - src/schema.ts | 25 --- 7 files changed, 9 insertions(+), 740 deletions(-) diff --git a/src/reference/openapi.yml b/src/reference/openapi.yml index 8551835d3..3c78f6e4c 100644 --- a/src/reference/openapi.yml +++ b/src/reference/openapi.yml @@ -2820,79 +2820,6 @@ paths: type: string usersNumber: type: integer - insights: - type: array - items: - type: object - properties: - id: - type: integer - title: - type: string - severity: - type: object - required: - - id - - name - properties: - id: - type: integer - name: - type: string - description: - type: string - clusters: - oneOf: - - type: string - enum: - - all - - type: array - items: - type: object - properties: - id: - type: integer - name: - type: string - required: - - id - - name - videoParts: - type: array - items: - type: object - properties: - id: - type: integer - start: - type: number - end: - type: number - mediaId: - type: integer - url: - type: string - streamUrl: - type: string - description: - type: string - poster: - type: string - required: - - id - - start - - end - - mediaId - - url - - streamUrl - - description - required: - - id - - title - - severity - - description - - clusters - - videoParts sentiments: type: array items: @@ -2970,41 +2897,6 @@ paths: name: Usability Test description: Methodology Description type: qualitative - insights: - - id: 1 - title: My insight - description: This is an insight - severity: - id: 1 - name: Minor - clusters: all - videoParts: - - id: 1 - start: 10 - end: 20 - mediaId: 1 - url: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4' - streamUrl: 'http://sample.vodobox.net/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8' - description: This is a video part - - id: 2 - title: My second insight - description: This is another insight - severity: - id: 2 - name: Positive - clusters: - - id: 1 - name: 'UC1: Cart' - - id: 2 - name: 'UC2: Login' - videoParts: - - id: 2 - start: 15 - end: 25 - mediaId: 2 - url: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4' - streamUrl: 'http://sample.vodobox.net/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8' - description: This is a video part sentiments: - id: 1 value: 5 @@ -3032,41 +2924,6 @@ paths: name: Usability Test description: Methodology Description type: quantitative - insights: - - id: 1 - title: My insight - description: This is an insight - severity: - id: 1 - name: Minor - clusters: all - videoParts: - - id: 1 - start: 10 - end: 20 - mediaId: 1 - url: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4' - streamUrl: 'http://sample.vodobox.net/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8' - description: This is a video part - - id: 2 - title: My second insight - description: This is another insight - severity: - id: 2 - name: Positive - clusters: - - id: 1 - name: 'UC1: Cart' - - id: 2 - name: 'UC2: Login' - videoParts: - - id: 2 - start: 15 - end: 25 - mediaId: 2 - url: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4' - streamUrl: 'http://sample.vodobox.net/skate_phantom_flex_4k/skate_phantom_flex_4k.m3u8' - description: This is a video part sentiments: - id: 1 value: 5 @@ -3100,72 +2957,6 @@ paths: name: UX Challenge description: UX Challenge type: qualitative - insights: - - id: 70 - title: Malfunzionamento form - description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas tellus lorem, maximus sit amet fermentum ac, venenatis eu sapien. In hac habitasse platea dictumst.' - clusters: - - id: 1 - name: UC 1 - Carrello - severity: - id: 1 - name: Minor - videoParts: - - id: 250 - start: 0 - mediaId: 73579 - end: 97 - description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas tellus lorem, maximus sit amet fermentum ac, venenatis eu sapien' - url: 'https://s3-eu-west-1.amazonaws.com/appq.use-case-media/CP4845/UC19595/T58918/713c9be296e4fb76d0b074947bbe9a56b2807000_1666111033.mp4' - streamUrl: 'https://s3-eu-west-1.amazonaws.com/appq.use-case-media/CP4845/UC19595/T58918/713c9be296e4fb76d0b074947bbe9a56b2807000_1666111033-stream.m3u8' - - id: 251 - start: 22 - mediaId: 73577 - end: 101 - description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' - url: 'https://s3-eu-west-1.amazonaws.com/appq.use-case-media/CP4845/UC19595/T8208/bfc341707a8a3c247926aee8d4efe14f06f5165d_1666101262.mp4' - streamUrl: 'https://s3-eu-west-1.amazonaws.com/appq.use-case-media/CP4845/UC19595/T8208/bfc341707a8a3c247926aee8d4efe14f06f5165d_1666101262-stream.m3u8' - - id: 252 - start: 0 - mediaId: 73578 - end: 152 - description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' - url: 'https://s3-eu-west-1.amazonaws.com/appq.use-case-media/CP4845/UC19595/T11291/91d3f36562a4d2be809c9b1217f591b317f928b4_1666108920.mp4' - streamUrl: 'https://s3-eu-west-1.amazonaws.com/appq.use-case-media/CP4845/UC19595/T11291/91d3f36562a4d2be809c9b1217f591b317f928b4_1666108920-stream.m3u8' - - id: 71 - title: Difficoltà di navigazione - description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' - clusters: - - id: 2 - name: UC 2 - Profilo - severity: - id: 1 - name: Minor - videoParts: - - id: 253 - start: 0 - mediaId: 73580 - end: 102 - description: Lorem ipsum dolor sit amet - url: 'https://s3-eu-west-1.amazonaws.com/appq.use-case-media/CP4845/UC19595/T960/19ebc32b3d71e4a3f2858eea298761d44db5d83b_1666112983.mp4' - streamUrl: 'https://s3-eu-west-1.amazonaws.com/appq.use-case-media/CP4845/UC19595/T960/19ebc32b3d71e4a3f2858eea298761d44db5d83b_1666112983-stream.m3u8' - - id: 72 - title: Criticità Pagina Prodotto - description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas tellus lorem, maximus sit amet fermentum ac, venenatis eu sapien. In hac habitasse platea dictumst. Etiam sodales nibh turpis, at condimentum arcu vehicula eget. Donec sollicitudin dapibus ' - clusters: - - id: 1 - name: UC 1 - Carrello - severity: - id: 2 - name: Major - videoParts: - - id: 254 - start: 0 - mediaId: 73589 - end: 106 - description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas tellus lorem, maximus sit amet fermentum ac, venenatis eu sapien. In hac habitasse platea dictumst. Etiam sodales nibh turpis,' - url: 'https://s3-eu-west-1.amazonaws.com/appq.use-case-media/CP4845/UC19595/T17968/0af496e75fb6ec367749d1c34a2f9a0dec0f2b4a_1666121805.mp4' - streamUrl: 'https://s3-eu-west-1.amazonaws.com/appq.use-case-media/CP4845/UC19595/T17968/0af496e75fb6ec367749d1c34a2f9a0dec0f2b4a_1666121805-stream.m3u8' sentiments: [] questions: - id: 1 diff --git a/src/routes/campaigns/campaignId/ux/UxData.ts b/src/routes/campaigns/campaignId/ux/UxData.ts index 689319aa0..609858e74 100644 --- a/src/routes/campaigns/campaignId/ux/UxData.ts +++ b/src/routes/campaigns/campaignId/ux/UxData.ts @@ -23,30 +23,6 @@ export default class UxData { } | undefined; - private _findings: { - id: number; - finding_id: number; - campaign_id: number; - version: number; - title: string; - description: string; - severity_id: number; - cluster_ids: string; - order: number; - }[] = []; - - private _videoParts: { - id: number; - media_id: number; - insight_id: number; - start: number; - end: number; - description: string; - location: string; - streamUrl: string; - poster?: string; - }[] = []; - private _questions: { id: number; campaign_id: number; @@ -71,19 +47,13 @@ export default class UxData { if (!data) return { data: undefined }; - const findings = await this.getFindings({ version: data.version }); const clusters = await this.getClusters(); - const findingsIds = findings.map((f) => f.id); - const videoParts = findingsIds.length - ? await this.getVideoParts(findingsIds) - : []; - const questions = await this.getQuestions({ version: data.version }); const sentiments = await this.getSentiments({ version: data.version }); - return { data, findings, clusters, videoParts, questions, sentiments }; + return { data, clusters, questions, sentiments }; } private async getSentiments({ version }: { version: number }) { @@ -107,27 +77,6 @@ export default class UxData { .orderBy("version", "DESC"); } - private async getVideoParts(findingsIds: number[]) { - return await tryber.tables.UxCampaignVideoParts.do() - .select( - tryber.ref("id").withSchema("ux_campaign_video_parts"), - "media_id", - "start", - "end", - "description", - "location", - "insight_id" - ) - .join( - "wp_appq_user_task_media", - "wp_appq_user_task_media.id", - "ux_campaign_video_parts.media_id" - ) - .whereIn("insight_id", findingsIds) - .where("location", "like", "%.mp4") - .orderBy("order", "asc"); - } - private async getUxData({ published }: { published: number }) { return await tryber.tables.UxCampaignData.do() .select() @@ -152,88 +101,30 @@ export default class UxData { .orderBy("version", "DESC"); } - private async getFindings({ version }: { version: number }) { - const result = await tryber.tables.UxCampaignInsights.do() - .select() - .where({ - campaign_id: this.campaignId, - version, - }) - .where({ enabled: 1 }) - .orderBy("order", "asc"); - return await this.filterDeletedClusters(result); - } - public async lastPublished() { - const { data, findings, clusters, videoParts, questions, sentiments } = - await this.getOne({ - published: 1, - }); + const { data, clusters, questions, sentiments } = await this.getOne({ + published: 1, + }); - if (findings) this._findings = findings; if (clusters) this._clusters = clusters; - if (videoParts) this._videoParts = await this.verifyUrls(videoParts); if (questions) this._questions = questions; if (sentiments) this._sentiments = sentiments; this._data = data; } public async lastDraft() { - const { data, findings, clusters, videoParts, questions, sentiments } = - await this.getOne({ - published: 0, - }); + const { data, clusters, questions, sentiments } = await this.getOne({ + published: 0, + }); if (!data) return; this._data = data; - if (findings) this._findings = findings; if (clusters) this._clusters = clusters; - if (videoParts) this._videoParts = await this.verifyUrls(videoParts); if (questions) this._questions = questions; if (sentiments) this._sentiments = sentiments; } - private async filterDeletedClusters( - findings: { - id: number; - finding_id: number; - campaign_id: number; - version: number; - title: string; - description: string; - severity_id: number; - cluster_ids: string; - order: number; - }[] - ) { - let res = []; - - // Get all cluster ids - const clusterIds = await this.getClusterIds(); - //remove deleted clusters from findings - for (const f of findings) { - const fClusterIds = f.cluster_ids.split(",").map(Number); - const validClusterIds = fClusterIds.filter((c) => clusterIds.includes(c)); - if (f.cluster_ids === "0") res.push(f); - else if (validClusterIds.length) { - res.push({ ...f, cluster_ids: validClusterIds.join(",") }); - } - } - - return res; - } - - private async getClusterIds() { - const results = await tryber.tables.WpAppqUsecaseCluster.do() - .where({ campaign_id: this.campaignId }) - .select("id"); - - if (!results.length) return []; - - return results.map((c) => c.id); - } - get version() { return this._data?.version; } @@ -243,49 +134,11 @@ export default class UxData { const { id: i, version: v, published: p, ...data } = this._data; return { ...data, - - findings: this.findings, questions: this.questions, sentiments: this.sentiments, }; } - get findings() { - return this._findings.map((f) => { - const severityName = - f.severity_id in this.SEVERITIES - ? this.SEVERITIES[f.severity_id as keyof typeof this.SEVERITIES] - : "Unknown"; - - const videoParts = this._videoParts.filter((v) => v.insight_id === f.id); - - return { - id: f.id, - title: f.title, - description: f.description, - clusters: evaluateClusters(this._clusters), - severity: { id: f.severity_id, name: severityName }, - videoParts: videoParts.map((v) => ({ - id: v.id, - start: v.start, - mediaId: v.media_id, - end: v.end, - description: v.description, - url: v.location, - streamUrl: v.streamUrl, - poster: v.poster, - })), - findingId: f.finding_id, - }; - - function evaluateClusters(clusters: { id: number; name: string }[]) { - if (f.cluster_ids === "0") return "all" as const; - const clusterIds = f.cluster_ids.split(",").map(Number); - return clusters.filter((c) => clusterIds.includes(c.id)); - } - }); - } - get questions() { return this._questions.map((q) => ({ id: q.id, @@ -310,33 +163,6 @@ export default class UxData { return true; } - async verifyUrls( - videoParts: { - id: number; - media_id: number; - insight_id: number; - start: number; - end: number; - description: string; - location: string; - }[] - ) { - const video = []; - for (const v of videoParts) { - const stream = v.location.replace(".mp4", "-stream.m3u8"); - const isValidStream = await checkUrl(stream); - const poster = v.location.replace(".mp4", ".0000000.jpg"); - const isValidPoster = await checkUrl(poster); - video.push({ - ...v, - location: this.mapToDistribution(v.location), - streamUrl: isValidStream ? this.mapToDistribution(stream) : "", - poster: isValidPoster ? this.mapToDistribution(poster) : undefined, - }); - } - return video; - } - private mapToDistribution(url: string) { return mapToDistribution(url); } diff --git a/src/routes/campaigns/campaignId/ux/_get/data.spec.ts b/src/routes/campaigns/campaignId/ux/_get/data.spec.ts index 6c7ebb5b9..5928296e5 100644 --- a/src/routes/campaigns/campaignId/ux/_get/data.spec.ts +++ b/src/routes/campaigns/campaignId/ux/_get/data.spec.ts @@ -56,56 +56,6 @@ describe("GET /campaigns/{campaignId}/ux - data", () => { goal: "This is the goal of the reasearch", users: 100, }); - await tryber.tables.UxCampaignInsights.do().insert([ - { - id: 1, - campaign_id: 1, - version: 1, - title: "Test Insight", - description: "Test Description", - severity_id: 1, - cluster_ids: "1,2", - order: 1, - finding_id: 10, - enabled: 1, - }, - { - id: 2, - campaign_id: 1, - version: 1, - title: "Test Insight All Cluster", - description: "Test Description All Cluster", - severity_id: 1, - cluster_ids: "0", - order: 0, - finding_id: 20, - enabled: 1, - }, - { - id: 3, - campaign_id: 1, - version: 1, - title: "Test Insight Disabled", - description: "Test Description Disabled", - severity_id: 1, - cluster_ids: "0", - order: 0, - finding_id: 30, - enabled: 0, - }, - { - id: 4, - campaign_id: 2, - version: 1, - title: "Test Insight Other CP", - description: "Test Description Other CP", - severity_id: 1, - cluster_ids: "0", - order: 0, - finding_id: 40, - enabled: 1, - }, - ]); await tryber.tables.WpAppqUsecaseCluster.do().insert([ { id: 1, @@ -127,15 +77,6 @@ describe("GET /campaigns/{campaignId}/ux - data", () => { }, ]); - await tryber.tables.UxCampaignVideoParts.do().insert({ - id: 1, - insight_id: 1, - start: 0, - end: 10, - order: 0, - media_id: 1, - description: "Test Description", - }); await tryber.tables.WpAppqUserTaskMedia.do().insert({ id: 1, campaign_task_id: 1, @@ -189,116 +130,12 @@ describe("GET /campaigns/{campaignId}/ux - data", () => { await tryber.tables.WpAppqEvdCampaign.do().delete(); await tryber.tables.UxCampaignData.do().delete(); await tryber.tables.WpAppqCampaignType.do().delete(); - await tryber.tables.UxCampaignInsights.do().delete(); await tryber.tables.WpAppqUsecaseCluster.do().delete(); - await tryber.tables.UxCampaignVideoParts.do().delete(); await tryber.tables.WpAppqUserTaskMedia.do().delete(); await tryber.tables.UxCampaignQuestions.do().delete(); await tryber.tables.UxCampaignSentiments.do().delete(); }); - it("Should return all the enabled findings", async () => { - const response = await request(app) - .get("/campaigns/1/ux") - .set("Authorization", "Bearer admin"); - expect(response.body).toHaveProperty("insights"); - expect(response.body.insights).toHaveLength(2); - expect(response.body.insights[0]).toEqual( - expect.objectContaining({ - title: "Test Insight All Cluster", - description: "Test Description All Cluster", - severity: expect.objectContaining({ - id: 1, - name: "Minor", - }), - clusters: "all", - videoParts: expect.arrayContaining([]), - }) - ); - expect(response.body.insights[1]).toEqual( - expect.objectContaining({ - title: "Test Insight", - description: "Test Description", - severity: expect.objectContaining({ - id: 1, - name: "Minor", - }), - clusters: [ - expect.objectContaining({ - id: 1, - name: "Test Cluster", - }), - expect.objectContaining({ - id: 2, - name: "Test Cluster 2", - }), - ], - videoParts: expect.arrayContaining([]), - }) - ); - }); - - it("Should return all findings of a specific Campaign", async () => { - const response = await request(app) - .get("/campaigns/1/ux") - .set("Authorization", "Bearer admin"); - expect(response.body).toHaveProperty("insights"); - expect(response.body.insights).toHaveLength(2); - expect(response.body.insights).toEqual( - expect.arrayContaining([ - expect.not.objectContaining({ - id: 4, - }), - ]) - ); - }); - - it("Should return the correct ids for each finding", async () => { - const response = await request(app) - .get("/campaigns/1/ux") - .set("Authorization", "Bearer admin"); - expect(response.body).toHaveProperty("insights"); - expect(response.body.insights).toHaveLength(2); - expect(response.body.insights).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - id: 1, - }), - expect.objectContaining({ - id: 2, - }), - ]) - ); - }); - - it("Should return all the video part in a finding", async () => { - const response = await request(app) - .get("/campaigns/1/ux") - .set("Authorization", "Bearer admin"); - expect(response.body).toHaveProperty("insights"); - expect(response.body.insights).toHaveLength(2); - expect(response.body.insights[1]).toEqual( - expect.objectContaining({ - id: 1, - videoParts: expect.arrayContaining([]), - }) - ); - expect(response.body.insights[1].videoParts).toHaveLength(1); - expect(response.body.insights[1].videoParts[0]).toEqual( - expect.objectContaining({ - start: 0, - end: 10, - description: "Test Description", - mediaId: 1, - url: "https://s3.eu-west-1.amazonaws.com/appq.static/ad4fc347f2579800a1920a8be6e181dda0f4b290_1692791543.mp4", - streamUrl: - "https://s3.eu-west-1.amazonaws.com/appq.static/ad4fc347f2579800a1920a8be6e181dda0f4b290_1692791543-stream.m3u8", - poster: - "https://s3.eu-west-1.amazonaws.com/appq.static/ad4fc347f2579800a1920a8be6e181dda0f4b290_1692791543.0000000.jpg", - }) - ); - }); - it("Should return the questions", async () => { const response = await request(app) .get("/campaigns/1/ux") diff --git a/src/routes/campaigns/campaignId/ux/_get/deleted-clusters.spec.ts b/src/routes/campaigns/campaignId/ux/_get/deleted-clusters.spec.ts index 0e9b8d2ad..ae7afa2b7 100644 --- a/src/routes/campaigns/campaignId/ux/_get/deleted-clusters.spec.ts +++ b/src/routes/campaigns/campaignId/ux/_get/deleted-clusters.spec.ts @@ -186,60 +186,9 @@ describe("With draft only", () => { await tryber.tables.WpAppqEvdCampaign.do().delete(); await tryber.tables.WpAppqUsecaseCluster.do().delete(); await tryber.tables.UxCampaignData.do().delete(); - await tryber.tables.UxCampaignInsights.do().delete(); await tryber.tables.UxCampaignSentiments.do().delete(); }); - it("Should not return findings of a deleted clusters", async () => { - const response = await request(app) - .get(`/campaigns/1/ux`) - .set("Authorization", "Bearer admin"); - - expect(response.body.insights.length).toEqual(4); - - expect(response.body.insights).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - id: 1, - }), - expect.objectContaining({ - id: 2, - }), - expect.objectContaining({ - id: 3, - }), - expect.objectContaining({ - id: 6, - }), - ]) - ); - }); - - it("Should remove deleted cluster on returning findings", async () => { - const response = await request(app) - .get(`/campaigns/1/ux`) - .set("Authorization", "Bearer admin"); - - expect(response.body.insights.length).toEqual(4); - expect(response.body.insights).toEqual( - expect.arrayContaining([ - expect.objectContaining({ - id: 1, - }), - expect.objectContaining({ - id: 2, - }), - expect.objectContaining({ - id: 3, - }), - expect.objectContaining({ - id: 6, - clusters: [{ id: 1, name: "Cluster 1" }], - }), - ]) - ); - }); - it("Should return the sentiments if exist the cluster", async () => { const response = await request(app) .get(`/campaigns/1/ux`) diff --git a/src/routes/campaigns/campaignId/ux/_get/draft-modified.spec.ts b/src/routes/campaigns/campaignId/ux/_get/draft-modified.spec.ts index ce287b4e5..29e393f7a 100644 --- a/src/routes/campaigns/campaignId/ux/_get/draft-modified.spec.ts +++ b/src/routes/campaigns/campaignId/ux/_get/draft-modified.spec.ts @@ -30,7 +30,7 @@ const campaign = { customer_title: "Test Customer", }; -describe("GET /campaigns/{campaignId}/ux - draft modified - insight", () => { +describe("GET /campaigns/{campaignId}/ux - draft modified", () => { beforeAll(async () => { await tryber.tables.WpAppqEvdCampaign.do().insert([ { ...campaign, id: 1, campaign_type_id: 10 }, @@ -68,36 +68,11 @@ describe("GET /campaigns/{campaignId}/ux - draft modified - insight", () => { users: 100, }, ]); - await tryber.tables.UxCampaignInsights.do().insert([ - { - campaign_id: 1, - version: 1, - title: "Test Insight", - description: "Test Description", - severity_id: 1, - cluster_ids: "1", - order: 0, - finding_id: 10, - enabled: 1, - }, - { - campaign_id: 1, - version: 2, - title: "Test Modified", - description: "Test Description", - severity_id: 1, - cluster_ids: "1", - order: 0, - finding_id: 20, - enabled: 1, - }, - ]); }); afterAll(async () => { await tryber.tables.WpAppqEvdCampaign.do().delete(); await tryber.tables.WpAppqCampaignType.do().delete(); await tryber.tables.UxCampaignData.do().delete(); - await tryber.tables.UxCampaignInsights.do().delete(); }); it("Should return status published if there are published campaign data and data are not equal to last draft", async () => { @@ -108,7 +83,7 @@ describe("GET /campaigns/{campaignId}/ux - draft modified - insight", () => { }); }); -describe("GET /campaigns/{campaignId}/ux - draft modified - video part", () => { +describe("GET /campaigns/{campaignId}/ux - draft modified", () => { beforeAll(async () => { await tryber.tables.WpAppqEvdCampaign.do().insert([ { ...campaign, id: 1, campaign_type_id: 10 }, @@ -146,42 +121,6 @@ describe("GET /campaigns/{campaignId}/ux - draft modified - video part", () => { users: 100, }, ]); - await tryber.tables.UxCampaignInsights.do().insert([ - { - id: 1, - campaign_id: 1, - version: 1, - title: "Test Insight", - description: "Test Description", - severity_id: 1, - cluster_ids: "1", - order: 0, - finding_id: 10, - enabled: 1, - }, - { - id: 2, - campaign_id: 1, - version: 2, - title: "Test Insight", - description: "Test Description", - severity_id: 1, - cluster_ids: "1", - order: 0, - finding_id: 20, - enabled: 1, - }, - ]); - - await tryber.tables.UxCampaignVideoParts.do().insert({ - id: 1, - insight_id: 1, - start: 0, - end: 10, - order: 0, - media_id: 1, - description: "Test Description", - }); await tryber.tables.WpAppqUserTaskMedia.do().insert({ id: 1, campaign_task_id: 1, @@ -190,15 +129,6 @@ describe("GET /campaigns/{campaignId}/ux - draft modified - video part", () => { tester_id: 1, }); - await tryber.tables.UxCampaignVideoParts.do().insert({ - id: 2, - insight_id: 2, - start: 0, - end: 100, - order: 0, - media_id: 1, - description: "Test Description", - }); await tryber.tables.WpAppqUserTaskMedia.do().insert({ id: 2, campaign_task_id: 1, @@ -211,8 +141,6 @@ describe("GET /campaigns/{campaignId}/ux - draft modified - video part", () => { await tryber.tables.WpAppqEvdCampaign.do().delete(); await tryber.tables.WpAppqCampaignType.do().delete(); await tryber.tables.UxCampaignData.do().delete(); - await tryber.tables.UxCampaignInsights.do().delete(); - await tryber.tables.UxCampaignVideoParts.do().delete(); await tryber.tables.WpAppqUserTaskMedia.do().delete(); }); @@ -261,23 +189,11 @@ describe("GET /campaigns/{campaignId}/ux - draft modified - ux data", () => { users: 100, }, ]); - await tryber.tables.UxCampaignInsights.do().insert({ - campaign_id: 1, - version: 1, - title: "Test Insight", - description: "Test Description", - severity_id: 1, - cluster_ids: "1", - order: 0, - finding_id: 10, - enabled: 1, - }); }); afterAll(async () => { await tryber.tables.WpAppqEvdCampaign.do().delete(); await tryber.tables.UxCampaignData.do().delete(); await tryber.tables.WpAppqCampaignType.do().delete(); - await tryber.tables.UxCampaignInsights.do().delete(); }); it("Should return methodology", async () => { @@ -365,17 +281,6 @@ describe("GET /campaigns/{campaignId}/ux - draft modified - questions", () => { users: 100, }, ]); - await tryber.tables.UxCampaignInsights.do().insert({ - campaign_id: 1, - version: 1, - title: "Test Insight", - description: "Test Description", - severity_id: 1, - cluster_ids: "1", - order: 0, - finding_id: 10, - enabled: 1, - }); await tryber.tables.UxCampaignQuestions.do().insert([ { id: 1, @@ -413,7 +318,6 @@ describe("GET /campaigns/{campaignId}/ux - draft modified - questions", () => { await tryber.tables.WpAppqEvdCampaign.do().delete(); await tryber.tables.UxCampaignData.do().delete(); await tryber.tables.WpAppqCampaignType.do().delete(); - await tryber.tables.UxCampaignInsights.do().delete(); await tryber.tables.UxCampaignQuestions.do().delete(); }); it("Should return questions of last draft version", async () => { @@ -470,17 +374,6 @@ describe("GET /campaigns/{campaignId}/ux - draft modified - sentiments", () => { users: 100, }, ]); - await tryber.tables.UxCampaignInsights.do().insert({ - campaign_id: 1, - version: 1, - title: "Test Insight", - description: "Test Description", - severity_id: 1, - cluster_ids: "1", - order: 0, - finding_id: 10, - enabled: 1, - }); await tryber.tables.WpAppqUsecaseCluster.do().insert([ { id: 1, @@ -548,7 +441,6 @@ describe("GET /campaigns/{campaignId}/ux - draft modified - sentiments", () => { await tryber.tables.WpAppqEvdCampaign.do().delete(); await tryber.tables.UxCampaignData.do().delete(); await tryber.tables.WpAppqCampaignType.do().delete(); - await tryber.tables.UxCampaignInsights.do().delete(); await tryber.tables.UxCampaignQuestions.do().delete(); await tryber.tables.UxCampaignSentiments.do().delete(); await tryber.tables.WpAppqUsecaseCluster.do().delete(); diff --git a/src/routes/campaigns/campaignId/ux/_get/index.ts b/src/routes/campaigns/campaignId/ux/_get/index.ts index 2ecaa13fe..eadc0a6de 100644 --- a/src/routes/campaigns/campaignId/ux/_get/index.ts +++ b/src/routes/campaigns/campaignId/ux/_get/index.ts @@ -87,7 +87,6 @@ export default class Route extends UserRoute<{ | "quantitative" | "quali-quantitative", }, - insights: this.draft.data?.findings || [], sentiments: this.draft.data?.sentiments || [], questions: this.draft.data?.questions || [], }); diff --git a/src/schema.ts b/src/schema.ts index e65595d22..491191bb4 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1956,31 +1956,6 @@ export interface operations { status: "draft" | "published" | "draft-modified"; goal: string; usersNumber: number; - insights?: { - id: number; - title: string; - severity: { - id: number; - name: string; - }; - description: string; - clusters: - | "all" - | { - id: number; - name: string; - }[]; - videoParts: { - id: number; - start: number; - end: number; - mediaId: number; - url: string; - streamUrl: string; - description: string; - poster?: string; - }[]; - }[]; sentiments: { id: number; value: number;