|
| 1 | +import app from "@src/app"; |
| 2 | +import { tryber } from "@src/features/database"; |
| 3 | +import request from "supertest"; |
| 4 | + |
| 5 | +const baseRequest = { |
| 6 | + project: 10, |
| 7 | + testType: 10, |
| 8 | + title: { |
| 9 | + customer: "Campaign Title for Customer", |
| 10 | + tester: "Campaign Title for Tester", |
| 11 | + }, |
| 12 | + startDate: "2019-08-24T14:15:22Z", |
| 13 | + deviceList: [], |
| 14 | +}; |
| 15 | + |
| 16 | +describe("Route POST /dossiers - plan", () => { |
| 17 | + beforeEach(async () => { |
| 18 | + await tryber.tables.WpAppqCampaignType.do().insert({ |
| 19 | + id: 10, |
| 20 | + category_id: 1, |
| 21 | + name: "Test Campaign Type", |
| 22 | + description: "Test Description", |
| 23 | + }); |
| 24 | + await tryber.tables.WpAppqProject.do().insert([ |
| 25 | + { |
| 26 | + id: 1, |
| 27 | + display_name: "Test Project", |
| 28 | + customer_id: 1, |
| 29 | + edited_by: 1, |
| 30 | + }, |
| 31 | + { |
| 32 | + id: 10, |
| 33 | + display_name: "New Project", |
| 34 | + customer_id: 10, |
| 35 | + edited_by: 1, |
| 36 | + }, |
| 37 | + ]); |
| 38 | + await tryber.tables.WpAppqCustomer.do().insert([ |
| 39 | + { |
| 40 | + id: 1, |
| 41 | + company: "Test Customer", |
| 42 | + pm_id: 1, |
| 43 | + }, |
| 44 | + { |
| 45 | + id: 10, |
| 46 | + company: "New Customer", |
| 47 | + pm_id: 1, |
| 48 | + }, |
| 49 | + ]); |
| 50 | + await tryber.tables.CpReqPlans.do().insert({ |
| 51 | + id: 1, |
| 52 | + name: "Test Plan", |
| 53 | + config: "{}", |
| 54 | + project_id: 1, |
| 55 | + workspace_id: 1, |
| 56 | + }); |
| 57 | + await tryber.tables.WpAppqEvdCampaign.do().insert({ |
| 58 | + id: 1, |
| 59 | + project_id: 1, |
| 60 | + campaign_type_id: 1, |
| 61 | + title: "Test Campaign", |
| 62 | + customer_title: "Test Customer Campaign", |
| 63 | + start_date: "2019-08-24T14:15:22Z", |
| 64 | + end_date: "2019-08-24T14:15:22Z", |
| 65 | + platform_id: 0, |
| 66 | + os: "1", |
| 67 | + page_manual_id: 0, |
| 68 | + page_preview_id: 0, |
| 69 | + pm_id: 1, |
| 70 | + customer_id: 0, |
| 71 | + plan_id: 1, |
| 72 | + }); |
| 73 | + await tryber.tables.CampaignDossierData.do().insert({ |
| 74 | + id: 1, |
| 75 | + campaign_id: 1, |
| 76 | + link: "https://example.com", |
| 77 | + created_by: 1, |
| 78 | + updated_by: 1, |
| 79 | + }); |
| 80 | + }); |
| 81 | + |
| 82 | + it("should update the plan project and workspace", async () => { |
| 83 | + const response = await request(app) |
| 84 | + .put("/dossiers/1") |
| 85 | + .send({ |
| 86 | + ...baseRequest, |
| 87 | + }) |
| 88 | + .set("Authorization", "Bearer admin"); |
| 89 | + |
| 90 | + const plan = await tryber.tables.CpReqPlans.do() |
| 91 | + .select("project_id", "workspace_id") |
| 92 | + .where({ id: 1 }) |
| 93 | + .first(); |
| 94 | + |
| 95 | + if (!plan) throw new Error("Plan not found"); |
| 96 | + |
| 97 | + expect(plan.project_id).toBe(10); |
| 98 | + expect(plan.workspace_id).toBe(10); |
| 99 | + }); |
| 100 | +}); |
0 commit comments