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

remove versions from ux endpoints #349

Merged
merged 10 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 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.41.9",
"@appquality/tryber-database": "^0.41.10",
"@appquality/wp-auth": "^1.0.7",
"@googlemaps/google-maps-services-js": "^3.3.7",
"@sendgrid/mail": "^7.6.0",
Expand Down
51 changes: 13 additions & 38 deletions src/routes/campaigns/campaignId/ux/UxData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { tryber } from "@src/features/database";
import { mapToDistribution } from "@src/features/s3/mapToDistribution";

export default class UxData {
private _data:
Expand All @@ -10,7 +9,6 @@ export default class UxData {
goal: string;
methodology_type: string;
methodology_description: string;
version: number;
published: number;
}
| undefined;
Expand All @@ -19,7 +17,6 @@ export default class UxData {
id: number;
campaign_id: number;
question: string;
version: number;
}[] = [];

private _sentiments: {
Expand All @@ -34,21 +31,21 @@ export default class UxData {

constructor(private campaignId: number) {}

private async getOne({ published }: { published: 0 | 1 }) {
const data = await this.getUxData({ published });
private async getOne() {
const data = await this.getUxData();

if (!data) return { data: undefined };

const clusters = await this.getClusters();

const questions = await this.getQuestions({ version: data.version });
const questions = await this.getQuestions();

const sentiments = await this.getSentiments({ version: data.version });
const sentiments = await this.getSentiments();

return { data, clusters, questions, sentiments };
}

private async getSentiments({ version }: { version: number }) {
private async getSentiments() {
return await tryber.tables.UxCampaignSentiments.do()
.select(
tryber.ref("id").withSchema("ux_campaign_sentiments"),
Expand All @@ -64,16 +61,13 @@ export default class UxData {
)
.where("ux_campaign_sentiments.campaign_id", this.campaignId)
.where("ux_campaign_sentiments.value", ">", 0)
.where("ux_campaign_sentiments.value", "<", 6)
.where({ version })
.orderBy("version", "DESC");
.where("ux_campaign_sentiments.value", "<", 6);
}

private async getUxData({ published }: { published: number }) {
private async getUxData() {
return await tryber.tables.UxCampaignData.do()
.select()
.where({ published: published, campaign_id: this.campaignId })
.orderBy("version", "desc")
.where({ campaign_id: this.campaignId })
.first();
}

Expand All @@ -85,29 +79,14 @@ export default class UxData {
});
}

private async getQuestions({ version }: { version: number }) {
private async getQuestions() {
return await tryber.tables.UxCampaignQuestions.do()
.select()
.where({ campaign_id: this.campaignId })
.where({ version })
.orderBy("version", "DESC");
.where({ campaign_id: this.campaignId });
}

public async lastPublished() {
const { data, clusters, questions, sentiments } = await this.getOne({
published: 1,
});

if (clusters) this._clusters = clusters;
if (questions) this._questions = questions;
if (sentiments) this._sentiments = sentiments;
this._data = data;
}

public async lastDraft() {
const { data, clusters, questions, sentiments } = await this.getOne({
published: 0,
});
public async getLast() {
const { data, clusters, questions, sentiments } = await this.getOne();

if (!data) return;
this._data = data;
Expand All @@ -117,13 +96,9 @@ export default class UxData {
if (sentiments) this._sentiments = sentiments;
}

get version() {
return this._data?.version;
}

get data() {
if (!this._data) return null;
const { id: i, version: v, published: p, ...data } = this._data;
const { id: i, published: p, ...data } = this._data;
return {
...data,
visible: p,
Expand Down
76 changes: 0 additions & 76 deletions src/routes/campaigns/campaignId/ux/_get/cookies.spec.ts

This file was deleted.

37 changes: 0 additions & 37 deletions src/routes/campaigns/campaignId/ux/_get/data.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import app from "@src/app";
import { tryber } from "@src/features/database";
import { getSignedCookie } from "@src/features/s3/cookieSign";
import request from "supertest";

jest.mock("@src/features/checkUrl", () => ({
checkUrl: jest.fn().mockImplementation(() => true),
}));

jest.mock("@src/features/s3/cookieSign");
const mockedGetSignedCookie = jest.mocked(getSignedCookie, true);

mockedGetSignedCookie.mockImplementation(({ url }) => {
return Promise.resolve({
"CloudFront-Policy": "policy",
"CloudFront-Signature": "signature",
"CloudFront-Key-Pair-Id": "keypairid",
});
});

const campaign = {
title: "Test Campaign",
platform_id: 1,
Expand Down Expand Up @@ -68,34 +52,22 @@ describe("GET /campaigns/{campaignId}/ux - data", () => {
subtitle: "Subtitle 3",
},
]);
await tryber.tables.WpAppqUserTaskMedia.do().insert({
id: 1,
campaign_task_id: 1,
user_task_id: 1,
location:
"https://s3.eu-west-1.amazonaws.com/appq.static/ad4fc347f2579800a1920a8be6e181dda0f4b290_1692791543.mp4",
tester_id: 1,
});
await tryber.tables.UxCampaignQuestions.do().insert([
{
campaign_id: 10,
question: "Why the world is round?",
version: 1,
},
{
campaign_id: 10,
question: "How many stars are in the sky?",
version: 1,
},
{
campaign_id: 20,
question: "How many stars are in the universe?",
version: 1,
},
{
campaign_id: 20,
question: "Be or not to be?",
version: 1,
},
]);
await tryber.tables.UxCampaignSentiments.do().insert([
Expand All @@ -104,36 +76,31 @@ describe("GET /campaigns/{campaignId}/ux - data", () => {
campaign_id: 10,
value: 1,
comment: "Low Comment cluster1",
version: 1,
},
{
cluster_id: 2,
campaign_id: 10,
value: 5,
comment: "High Comment cluster2",
version: 1,
},
{
cluster_id: 1,
campaign_id: 2,
value: 5,
comment: "Medium Comment cluster1",
version: 2,
},
{
cluster_id: 1,
campaign_id: 20,
value: 5,
comment: "Medium Comment cluster1",
version: 1,
},
]);
});
afterAll(async () => {
await tryber.tables.WpAppqEvdCampaign.do().delete();
await tryber.tables.WpAppqCampaignType.do().delete();
await tryber.tables.WpAppqUsecaseCluster.do().delete();
await tryber.tables.WpAppqUserTaskMedia.do().delete();
await tryber.tables.UxCampaignQuestions.do().delete();
await tryber.tables.UxCampaignSentiments.do().delete();
});
Expand All @@ -143,7 +110,6 @@ describe("GET /campaigns/{campaignId}/ux - data", () => {
await tryber.tables.UxCampaignData.do().insert([
{
campaign_id: 20,
version: 2,
published: 0,
methodology_description: "Ux Description DATA",
methodology_type: "qualitative",
Expand All @@ -152,7 +118,6 @@ describe("GET /campaigns/{campaignId}/ux - data", () => {
},
{
campaign_id: 10,
version: 1,
published: 0,
methodology_description: "Ux Description DATA",
methodology_type: "qualitative",
Expand Down Expand Up @@ -275,7 +240,6 @@ describe("GET /campaigns/{campaignId}/ux - data", () => {
await tryber.tables.UxCampaignData.do().insert([
{
campaign_id: 20,
version: 2,
published: 1,
methodology_description: "Ux Description DATA",
methodology_type: "qualitative",
Expand All @@ -284,7 +248,6 @@ describe("GET /campaigns/{campaignId}/ux - data", () => {
},
{
campaign_id: 10,
version: 1,
published: 1,
methodology_description: "Ux Description DATA",
methodology_type: "qualitative",
Expand Down
Loading
Loading