From 72c9b5a11e70643bffee99f5aa161281d5f3069a Mon Sep 17 00:00:00 2001 From: swtmply Date: Fri, 21 Jul 2023 11:38:57 +0800 Subject: [PATCH] IO-2327 job import test cases --- client/cypress.env.json | 4 + .../cypress/e2e/job-import/job-import.cy.js | 207 +++++++----------- client/cypress/support/commands.js | 36 +++ .../owner-detail-jobs.component.jsx | 1 + .../owners-list/owners-list.component.jsx | 1 + 5 files changed, 127 insertions(+), 122 deletions(-) create mode 100644 client/cypress.env.json diff --git a/client/cypress.env.json b/client/cypress.env.json new file mode 100644 index 000000000..bc164ffaa --- /dev/null +++ b/client/cypress.env.json @@ -0,0 +1,4 @@ +{ + "graphql_dev_endpoint": "https://db.dev.bodyshop.app/v1/graphql", + "uploaded_by_email": "john@imex.dev" +} diff --git a/client/cypress/e2e/job-import/job-import.cy.js b/client/cypress/e2e/job-import/job-import.cy.js index ee13c6dd9..b3bc2aa46 100644 --- a/client/cypress/e2e/job-import/job-import.cy.js +++ b/client/cypress/e2e/job-import/job-import.cy.js @@ -11,6 +11,25 @@ const query = `mutation INSERT_AVAILABLE_JOB($job: available_jobs_insert_input!) } }`; +const createJobEstimate = (job, bodyshopid) => { + return { + owner: { + data: { + shopid: bodyshopid, + ...job.owner.data, + }, + }, + vehicle: { + data: { + shopid: bodyshopid, + ...job.vehicle.data, + }, + }, + shopid: bodyshopid, + ...job, + }; +}; + describe( "Importing an available job", { @@ -23,7 +42,7 @@ describe( cy.visit("/manage/available"); // intercept bodyshop query for id - cy.intercept("POST", "https://db.dev.bodyshop.app/v1/graphql", (req) => { + cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "QUERY_BODYSHOP") { req.alias = "bodyshop"; } @@ -36,8 +55,8 @@ describe( }); }); - it.only("Enters a job programatically", () => { - cy.intercept("POST", "https://db.dev.bodyshop.app/v1/graphql", (req) => { + it("Enters a job programatically", () => { + cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "QUERY_AVAILABLE_JOBS") { req.alias = "availableJobs"; } @@ -47,53 +66,20 @@ describe( const token = request.headers.authorization; cy.get("@bodyshopid").then((bodyshopid) => { - const job_est_data = { - owner: { - data: { - shopid: bodyshopid, - ...job.owner.data, - }, - }, - vehicle: { - data: { - shopid: bodyshopid, - ...job.vehicle.data, - }, - }, - shopid: bodyshopid, - ...job, - }; + const job_est_data = createJobEstimate(job, bodyshopid); - cy.request({ - url: "http://localhost:4000/test/query", - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: token, - }, - body: { - query, - job: { - est_data: job_est_data, - uploaded_by: "john@imex.dev", - cieca_id: job.ciecaid, - bodyshopid, - clm_amt: job.clm_total, - clm_no: job.clm_no, - ins_co_nm: job.ins_co_nm, - ownr_name: `${job.owner.data.ownr_fn} ${job.owner.data.ownr_ln}`, - vehicle_info: `${job.v_model_yr} ${job.v_make_desc} ${job.v_model_desc}`, - }, - }, - }) - .its("body.insert_available_jobs_one") - .should("have.property", "id"); + cy.insertAvailableJob({ + bodyshopid, + job, + token, + job_est_data, + }); }); }); }); it("creates a new owner record for the job", () => { - cy.intercept("POST", "https://db.dev.bodyshop.app/v1/graphql", (req) => { + cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "QUERY_AVAILABLE_JOBS") { req.alias = "availableJobs"; } @@ -108,14 +94,17 @@ describe( .parent() .as("row"); - cy.get('[data-cy="add-job-as-new-button"]').should("be.enabled").click(); + cy.get("@row") + .find('[data-cy="add-job-as-new-button"]') + .should("be.enabled") + .click(); cy.get('[data-cy="new_owner_checkbox"]').should("be.checked"); cy.get('[data-cy="existing-owners-ok-button"]') .should("be.enabled") .click(); - cy.intercept("POST", "https://db.dev.bodyshop.app/v1/graphql", (req) => { + cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "INSERT_JOB") { req.alias = "insertJob"; } @@ -153,7 +142,7 @@ describe( }); it("imports a supplement for an existing job", () => { - cy.intercept("POST", "https://db.dev.bodyshop.app/v1/graphql", (req) => { + cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "QUERY_AVAILABLE_JOBS") { req.alias = "availableJobs"; } @@ -162,30 +151,16 @@ describe( cy.wait("@availableJobs").then(({ request }) => { const token = request.headers.authorization; - cy.request({ - url: "http://localhost:4000/test/query", - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: token, - }, - body: { - query, - job: { - est_data: jobSupplement, - uploaded_by: "john@imex.dev", - cieca_id: jobSupplement.ciecaid, - bodyshopid: jobSupplement.owner.data.shopid, - clm_amt: jobSupplement.clm_total, - clm_no: jobSupplement.clm_no, - ins_co_nm: jobSupplement.ins_co_nm, - ownr_name: `${jobSupplement.owner.data.ownr_fn} ${jobSupplement.owner.data.ownr_ln}`, - vehicle_info: `${jobSupplement.v_model_yr} ${jobSupplement.v_make_desc} ${jobSupplement.v_model_desc}`, - }, - }, - }) - .its("body.insert_available_jobs_one") - .should("have.property", "id"); + cy.get("@bodyshopid").then((bodyshopid) => { + const job_est_data = createJobEstimate(jobSupplement, bodyshopid); + + cy.insertAvailableJob({ + bodyshopid, + job: jobSupplement, + token, + job_est_data, + }); + }); }); cy.get('[data-cy="refetch-available-jobs-button"]') @@ -239,7 +214,7 @@ describe( }); it("imports a supplement and override estimate header", () => { - cy.intercept("POST", "https://db.dev.bodyshop.app/v1/graphql", (req) => { + cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "QUERY_AVAILABLE_JOBS") { req.alias = "availableJobs"; } @@ -248,30 +223,16 @@ describe( cy.wait("@availableJobs").then(({ request }) => { const token = request.headers.authorization; - cy.request({ - url: "http://localhost:4000/test/query", - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: token, - }, - body: { - query, - job: { - est_data: jobSupplement, - uploaded_by: "john@imex.dev", - cieca_id: jobSupplement.ciecaid, - bodyshopid: jobSupplement.owner.data.shopid, - clm_amt: jobSupplement.clm_total, - clm_no: jobSupplement.clm_no, - ins_co_nm: jobSupplement.ins_co_nm, - ownr_name: `${jobSupplement.owner.data.ownr_fn} ${jobSupplement.owner.data.ownr_ln}`, - vehicle_info: `${jobSupplement.v_model_yr} ${jobSupplement.v_make_desc} ${jobSupplement.v_model_desc}`, - }, - }, - }) - .its("body.insert_available_jobs_one") - .should("have.property", "id"); + cy.get("@bodyshopid").then((bodyshopid) => { + const job_est_data = createJobEstimate(jobSupplement, bodyshopid); + + cy.insertAvailableJob({ + bodyshopid, + job: jobSupplement, + token, + job_est_data, + }); + }); }); cy.get('[data-cy="refetch-available-jobs-button"]') @@ -327,8 +288,8 @@ describe( ); }); - it.skip("imports a job with an existing owner", () => { - cy.intercept("POST", "https://db.dev.bodyshop.app/v1/graphql", (req) => { + it("imports a job with an existing owner", () => { + cy.intercept("POST", Cypress.env("graphql_dev_endpoint"), (req) => { if (req.body.operationName === "QUERY_AVAILABLE_JOBS") { req.alias = "availableJobs"; } @@ -337,30 +298,16 @@ describe( cy.wait("@availableJobs").then(({ request }) => { const token = request.headers.authorization; - cy.request({ - url: "http://localhost:4000/test/query", - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: token, - }, - body: { - query, - job: { - est_data: job2, - uploaded_by: "john@imex.dev", - cieca_id: job2.ciecaid, - bodyshopid: job2.owner.data.shopid, - clm_amt: job2.clm_total, - clm_no: job2.clm_no, - ins_co_nm: job2.ins_co_nm, - ownr_name: `${job2.owner.data.ownr_fn} ${job2.owner.data.ownr_ln}`, - vehicle_info: `${job2.v_model_yr} ${job2.v_make_desc} ${job2.v_model_desc}`, - }, - }, - }) - .its("body.insert_available_jobs_one") - .should("have.property", "id"); + cy.get("@bodyshopid").then((bodyshopid) => { + const job_est_data = createJobEstimate(job2, bodyshopid); + + cy.insertAvailableJob({ + bodyshopid, + job: job2, + token, + job_est_data, + }); + }); }); cy.get('[data-cy="refetch-available-jobs-button"]') @@ -386,8 +333,24 @@ describe( cy.visit("/manage/owners"); // Navigate to owner records + cy.get('[data-cy="owners-table"]') + .find(".ant-table-tbody") + .find("> tr:not(.ant-table-measure-row)") + .as("owners-table") + .should("not.have.class", "ant-table-placeholder"); // Get owner name + cy.get("@owners-table") + .contains(`${job2.owner.data.ownr_fn} ${job2.owner.data.ownr_ln}`) + .click(); + // check list if claim number is there + cy.get('[data-cy="owner-jobs-table"]') + .find(".ant-table-tbody") + .find("> tr:not(.ant-table-measure-row)") + .as("owner-jobs-table") + .should("not.have.class", "ant-table-placeholder"); + // Get owner name + cy.get("@owner-jobs-table").contains(job2.clm_no).should("exist"); }); } ); diff --git a/client/cypress/support/commands.js b/client/cypress/support/commands.js index 5a28da167..e0c6ed0f9 100644 --- a/client/cypress/support/commands.js +++ b/client/cypress/support/commands.js @@ -82,3 +82,39 @@ Cypress.Commands.add("antdFormSelect", (name, text, cb) => { } }); }); + +Cypress.Commands.add( + "insertAvailableJob", + ({ bodyshopid, job, job_est_data, token }) => { + const query = `mutation INSERT_AVAILABLE_JOB($job: available_jobs_insert_input!) { + insert_available_jobs_one(object: $job) { + id + } + }`; + + cy.request({ + url: "http://localhost:4000/test/query", + method: "POST", + headers: { + "Content-Type": "application/json", + Authorization: token, + }, + body: { + query, + job: { + est_data: job_est_data, + uploaded_by: Cypress.env("uploaded_by_email"), + cieca_id: job.ciecaid, + bodyshopid, + clm_amt: job.clm_total, + clm_no: job.clm_no, + ins_co_nm: job.ins_co_nm, + ownr_name: `${job.owner.data.ownr_fn} ${job.owner.data.ownr_ln}`, + vehicle_info: `${job.v_model_yr} ${job.v_make_desc} ${job.v_model_desc}`, + }, + }, + }) + .its("body.insert_available_jobs_one") + .should("have.property", "id"); + } +); diff --git a/client/src/components/owner-detail-jobs/owner-detail-jobs.component.jsx b/client/src/components/owner-detail-jobs/owner-detail-jobs.component.jsx index c69712a0b..0253ca8a0 100644 --- a/client/src/components/owner-detail-jobs/owner-detail-jobs.component.jsx +++ b/client/src/components/owner-detail-jobs/owner-detail-jobs.component.jsx @@ -75,6 +75,7 @@ function OwnerDetailJobsComponent({ bodyshop, owner }) { } >