120 lines
4.1 KiB
JavaScript
120 lines
4.1 KiB
JavaScript
const path = require("path");
|
|
const Dinero = require("dinero.js");
|
|
const { gql } = require("graphql-request");
|
|
const queries = require("./server/graphql-client/queries");
|
|
const GraphQLClient = require("graphql-request").GraphQLClient;
|
|
const logger = require("./server/utils/logger");
|
|
const AxiosLib = require("axios").default;
|
|
const axios = AxiosLib.create();
|
|
|
|
// Dinero.defaultCurrency = "USD";
|
|
// Dinero.globalLocale = "en-CA";
|
|
Dinero.globalRoundingMode = "HALF_EVEN";
|
|
const client = require("./server/graphql-client/graphql-client").client;
|
|
require("dotenv").config({
|
|
path: path.resolve(
|
|
process.cwd(),
|
|
`.env.${process.env.NODE_ENV || "development"}`
|
|
),
|
|
});
|
|
|
|
async function RunTheTest() {
|
|
const bodyshopids = ["a7ee1503-ee05-4a02-b80e-bdb11d1cc8ac"];
|
|
const bearerToken = `Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjE5MGFkMTE4YTk0MGFkYzlmMmY1Mzc2YjM1MjkyZmVkZThjMmQwZWUiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoiUm9tZSBEZXZlbG9wbWVudCIsImh0dHBzOi8vaGFzdXJhLmlvL2p3dC9jbGFpbXMiOnsieC1oYXN1cmEtZGVmYXVsdC1yb2xlIjoidXNlciIsIngtaGFzdXJhLWFsbG93ZWQtcm9sZXMiOlsidXNlciJdLCJ4LWhhc3VyYS11c2VyLWlkIjoidDZZbTFORGxDRE9QWnIzRjliZ3VXSDRMaFNYMiJ9LCJpb2FkbWluIjp0cnVlLCJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vcm9tZS1wcm9kLTEiLCJhdWQiOiJyb21lLXByb2QtMSIsImF1dGhfdGltZSI6MTY5NDQ2NjM3OCwidXNlcl9pZCI6InQ2WW0xTkRsQ0RPUFpyM0Y5Ymd1V0g0TGhTWDIiLCJzdWIiOiJ0NlltMU5EbENET1BacjNGOWJndVdINExoU1gyIiwiaWF0IjoxNjk0NTQ4MTIwLCJleHAiOjE2OTQ1NTE3MjAsImVtYWlsIjoicGF0cmlja0Byb21lLmRldiIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJwYXRyaWNrQHJvbWUuZGV2Il19LCJzaWduX2luX3Byb3ZpZGVyIjoicGFzc3dvcmQifX0.hIR3tAIOZFydmuCC5OS1KmIAG3Rq3mB1ZJAcnWUrJRuioNw1DeezAiUvXlb2iQ3Pow3zpyTkZgNMrLhWNpZmywyjPQQaTU7krw2gNhmRfrILmIWjODepvRcp4mcwvdf65WkqXm88S82b-8nkgvPhogvXmYWHrrDFl9EP4nMXdhjJ8rZ-euBcH9wz9o4BehsW4x91JJxeTU_jk4Fa0h6ppG6XdTmPyTlQb79g-WgLbqtyXEIjQr9q_ZbE4br_PLLhFd7SnUV0e-raw3FcK9m4Mc-n37M4KtKEpDbhXM_2MtGSCWbKZ7m3lfydFaV8LlgnCTiX_gSCvoAmCeRyH5w1yQ`;
|
|
const { jobs } = await client.request(
|
|
gql`
|
|
query GET_JOBS($bodyshopids: [uuid!]!) {
|
|
jobs(
|
|
where: { shopid: { _in: $bodyshopids } }
|
|
order_by: { created_at: desc }
|
|
) {
|
|
id
|
|
ro_number
|
|
job_totals
|
|
cieca_ttl
|
|
}
|
|
}
|
|
`,
|
|
{
|
|
bodyshopids,
|
|
}
|
|
);
|
|
|
|
const results = [];
|
|
|
|
for (const job of jobs) {
|
|
try {
|
|
await axios.post(
|
|
`http://localhost:4000/job/totalsssu`,
|
|
{ id: job.id },
|
|
{ headers: { Authorization: bearerToken } }
|
|
);
|
|
const { jobs_by_pk: newjob } = await client.request(
|
|
gql`
|
|
query GET_JOBS($id: uuid!) {
|
|
jobs_by_pk(id: $id) {
|
|
id
|
|
ro_number
|
|
cieca_ttl
|
|
job_totals
|
|
ownr_fn
|
|
ownr_ln
|
|
ownr_co_nm
|
|
ins_co_nm
|
|
comment
|
|
}
|
|
}
|
|
`,
|
|
{
|
|
id: job.id,
|
|
}
|
|
);
|
|
|
|
const result = {
|
|
id: newjob.id,
|
|
owner: `${newjob.ownr_fn} ${newjob.ownr_ln} ${job.ownr_co_nm || ""}`,
|
|
ins_co: newjob.ins_co_nm,
|
|
comment: newjob.comment,
|
|
};
|
|
|
|
const calcTotal = newjob.job_totals.totals.total_repairs.amount;
|
|
const ttlTotal = newjob.cieca_ttl.data.g_ttl_amt * 100;
|
|
result.difference = (calcTotal - ttlTotal) / 100;
|
|
|
|
if (Math.abs(calcTotal - ttlTotal) > 3) {
|
|
//Diff is greater than 5 cents. Fail it.
|
|
result.result = "***FAIL***";
|
|
} else {
|
|
result.result = "PASS";
|
|
}
|
|
console.log(`${result.result} => RO ${job.ro_number} - ${job.id} `);
|
|
|
|
results.push(result);
|
|
} catch (error) {
|
|
results.push({
|
|
ro_number: job.ro_number,
|
|
id: job.id,
|
|
result: "**503 FAILURE**",
|
|
});
|
|
}
|
|
}
|
|
|
|
console.table(results.filter((r) => r.result !== "PASS"));
|
|
const summary = results.reduce(
|
|
(acc, val) => {
|
|
if (val.result === "PASS") {
|
|
return { ...acc, pass: acc.pass + 1 };
|
|
} else {
|
|
return { ...acc, fail: acc.fail + 1 };
|
|
}
|
|
},
|
|
{ pass: 0, fail: 0 }
|
|
);
|
|
console.log(
|
|
"Pass Rate: ",
|
|
((summary.pass / (summary.fail + summary.pass)) * 100).toFixed(1)
|
|
);
|
|
}
|
|
|
|
RunTheTest();
|