118 lines
4.0 KiB
JavaScript
118 lines
4.0 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 = ["6c63a820-542c-497e-8c82-0cc38fb2bbca"];
|
|
const bearerToken = `Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6Ijk3OWVkMTU1OTdhYjM1Zjc4MjljZTc0NDMwN2I3OTNiN2ViZWIyZjAiLCJ0eXAiOiJKV1QifQ.eyJodHRwczovL2hhc3VyYS5pby9qd3QvY2xhaW1zIjp7IngtaGFzdXJhLWRlZmF1bHQtcm9sZSI6InVzZXIiLCJ4LWhhc3VyYS1hbGxvd2VkLXJvbGVzIjpbInVzZXIiXSwieC1oYXN1cmEtdXNlci1pZCI6InQ2WW0xTkRsQ0RPUFpyM0Y5Ymd1V0g0TGhTWDIifSwiaXNzIjoiaHR0cHM6Ly9zZWN1cmV0b2tlbi5nb29nbGUuY29tL3JvbWUtcHJvZC0xIiwiYXVkIjoicm9tZS1wcm9kLTEiLCJhdXRoX3RpbWUiOjE2NzkzNDc4NzAsInVzZXJfaWQiOiJ0NlltMU5EbENET1BacjNGOWJndVdINExoU1gyIiwic3ViIjoidDZZbTFORGxDRE9QWnIzRjliZ3VXSDRMaFNYMiIsImlhdCI6MTY3OTk1NDk3MiwiZXhwIjoxNjc5OTU4NTcyLCJlbWFpbCI6InBhdHJpY2tAcm9tZS5kZXYiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZW1haWwiOlsicGF0cmlja0Byb21lLmRldiJdfSwic2lnbl9pbl9wcm92aWRlciI6InBhc3N3b3JkIn19.Dnq_xo5tffFf-LK0qD_iieUa_UYe4cJqOxcuJnRGH0aqirMMeQLRR4B_Z3pOsD3T20ML3qZMQNUKx-Ivz1mfyK_aA7_4GKtHRKOpIrAyssw_l5aXuCAEmC8iLQHDGvKi7Vp8LsTMPKqjJSjtaW2zuFqcIGrqncWkBMYSnCKjCFsKjryp35hQiIynAN1W0ajgjmFZHCy7hG1h4wFtLKNXEAGxWA0tE7m7ZZBZk3W7J3nMbYiMuGZfw0y2yYeILQGw3UW6sb9B2Jx2bAR3x-GWhPzQHNZEPolE-andm900cFgdph1z7eBE5P2udc2rp8JsAPdUdovt8ZImhCUeE5wD6g`;
|
|
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
|
|
}
|
|
}
|
|
`,
|
|
{
|
|
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,
|
|
};
|
|
|
|
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) > 5) {
|
|
//Diff is greater than 5 cents. Fail it.
|
|
result.result = "***FAIL***";
|
|
} else {
|
|
result.result = "PASS";
|
|
}
|
|
console.log(`${result.result} => RO ${job.ro_number}`);
|
|
|
|
results.push(result);
|
|
} catch (error) {
|
|
results.push({
|
|
ro_number: job.ro_number,
|
|
id: job.id,
|
|
result: "**503 FAILURE**",
|
|
});
|
|
}
|
|
}
|
|
|
|
console.table(results);
|
|
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();
|