Improve backwards compatibility for job totals calculations.
This commit is contained in:
103
job-totals-testing-util.js
Normal file
103
job-totals-testing-util.js
Normal file
@@ -0,0 +1,103 @@
|
||||
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 eyJhbGciOiJSUzI1NiIsImtpZCI6ImQwNTU5YzU5MDgzZDc3YWI2NDUxOThiNTIxZmM4ZmVmZmVlZmJkNjIiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoiUGF0cmljayBGaWMgKERFVikiLCJodHRwczovL2hhc3VyYS5pby9qd3QvY2xhaW1zIjp7IngtaGFzdXJhLWRlZmF1bHQtcm9sZSI6InVzZXIiLCJ4LWhhc3VyYS1hbGxvd2VkLXJvbGVzIjpbInVzZXIiXSwieC1oYXN1cmEtdXNlci1pZCI6ImhOSjhBRHB0REhRQkRFcXNCOFFNWVRqaURuZjEifSwiaXNzIjoiaHR0cHM6Ly9zZWN1cmV0b2tlbi5nb29nbGUuY29tL2ltZXgtZGV2IiwiYXVkIjoiaW1leC1kZXYiLCJhdXRoX3RpbWUiOjE2NzE1Njc4NzUsInVzZXJfaWQiOiJoTko4QURwdERIUUJERXFzQjhRTVlUamlEbmYxIiwic3ViIjoiaE5KOEFEcHRESFFCREVxc0I4UU1ZVGppRG5mMSIsImlhdCI6MTY3NDE2ODAxOCwiZXhwIjoxNjc0MTcxNjE4LCJlbWFpbCI6InBhdHJpY2tAaW1leC5kZXYiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZW1haWwiOlsicGF0cmlja0BpbWV4LmRldiJdfSwic2lnbl9pbl9wcm92aWRlciI6InBhc3N3b3JkIn19.an7UXCMA9VXoPiGAYlDqB_Kn0HREeomVPEh7fl7OHo_eLoShLdvzPo0NlXnDCuhZXD1dUZj-cCZw-pcwKoa05cDoGRTmmgGLaqh43bqqnxOupkb90aHjYzw6Nuz1Cn-PEqkqqZRDbnAbpHWp_2Iaj4zBu1mEQ8_D9rvNuOoH_73-FnQwT4uyT0-SNUlV_9ajn1RprxeaAxk5rahL89eBDi4NF3h24cbjh15pfd4pkEk6H6bI09PuXewA_2Kl8krKMjoOvCA5OA0K7echV1vC4Z2gIHTdvdYKuRUUFK9J7rR5nMGUMVMjmkEEJPTkZzZ4vzsBJyD-BDQmB6bAF2S6Mw`;
|
||||
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 = Math.abs(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);
|
||||
}
|
||||
|
||||
RunTheTest();
|
||||
Reference in New Issue
Block a user