IO-2327 job import test cases

This commit is contained in:
swtmply
2023-07-21 11:38:57 +08:00
parent 835b90bc4b
commit 72c9b5a11e
5 changed files with 127 additions and 122 deletions

4
client/cypress.env.json Normal file
View File

@@ -0,0 +1,4 @@
{
"graphql_dev_endpoint": "https://db.dev.bodyshop.app/v1/graphql",
"uploaded_by_email": "john@imex.dev"
}

View File

@@ -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");
});
}
);

View File

@@ -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");
}
);

View File

@@ -75,6 +75,7 @@ function OwnerDetailJobsComponent({ bodyshop, owner }) {
}
>
<Table
data-cy="owner-jobs-table"
pagination={{ position: "bottom" }}
columns={columns}
scroll={{ x: true }}

View File

@@ -115,6 +115,7 @@ export default function OwnersListComponent({
}
>
<Table
data-cy="owners-table"
loading={loading}
pagination={{
position: "top",