feature/IO-2769-Job-Totals-testing: Allow for both american and canadian capture + tests
This commit is contained in:
@@ -39,7 +39,14 @@ exports.totalsSsu = async function (req, res) {
|
|||||||
|
|
||||||
// Capture fixture data (input and output), using job.id for the filename.
|
// Capture fixture data (input and output), using job.id for the filename.
|
||||||
if (process.env?.SAVE_TOTALS_DATA) {
|
if (process.env?.SAVE_TOTALS_DATA) {
|
||||||
captureFixture(inputForTotals, inputForTotals, newTotals);
|
captureFixture(
|
||||||
|
inputForTotals,
|
||||||
|
newTotals,
|
||||||
|
InstanceMgr({
|
||||||
|
imex: "ca",
|
||||||
|
rome: "us"
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await client.setHeaders({ Authorization: BearerToken }).request(queries.UPDATE_JOB, {
|
const result = await client.setHeaders({ Authorization: BearerToken }).request(queries.UPDATE_JOB, {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const Dinero = require("dinero.js");
|
|||||||
const queries = require("../graphql-client/queries");
|
const queries = require("../graphql-client/queries");
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
const { captureFixture } = require("./utils/seralizeHelper");
|
const { captureFixture } = require("./utils/seralizeHelper");
|
||||||
|
const { default: InstanceMgr } = require("../utils/instanceMgr");
|
||||||
|
|
||||||
//****************************************************** */
|
//****************************************************** */
|
||||||
//****************************************************** */
|
//****************************************************** */
|
||||||
@@ -39,7 +40,14 @@ exports.totalsSsu = async function (req, res) {
|
|||||||
|
|
||||||
// Capture fixture data (input and output), using job.id for the filename.
|
// Capture fixture data (input and output), using job.id for the filename.
|
||||||
if (process.env?.SAVE_TOTALS_DATA) {
|
if (process.env?.SAVE_TOTALS_DATA) {
|
||||||
captureFixture(inputForTotals, inputForTotals, newTotals);
|
captureFixture(
|
||||||
|
inputForTotals,
|
||||||
|
newTotals,
|
||||||
|
InstanceMgr({
|
||||||
|
imex: "ca",
|
||||||
|
rome: "us"
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await client.setHeaders({ Authorization: BearerToken }).request(queries.UPDATE_JOB, {
|
const result = await client.setHeaders({ Authorization: BearerToken }).request(queries.UPDATE_JOB, {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
import { TotalsServerSide } from "../job-totals";
|
import { TotalsServerSide as TotalsServerSideCA } from "../job-totals"; // Canadian version (imex)
|
||||||
|
import { TotalsServerSide as TotalsServerSideUS } from "../job-totals-USA"; // US version (rome)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is used to replace the values in the object with their
|
* This function is used to replace the values in the object with their
|
||||||
@@ -48,7 +49,7 @@ describe("TotalsServerSide fixture tests", () => {
|
|||||||
const fixturePath = path.join(fixturesDir, file);
|
const fixturePath = path.join(fixturesDir, file);
|
||||||
const fixtureData = JSON.parse(fs.readFileSync(fixturePath, "utf8"));
|
const fixtureData = JSON.parse(fs.readFileSync(fixturePath, "utf8"));
|
||||||
|
|
||||||
const { input, output: expectedOutput } = fixtureData;
|
const { environment, input, output: expectedOutput } = fixtureData;
|
||||||
|
|
||||||
const req = {
|
const req = {
|
||||||
body: {
|
body: {
|
||||||
@@ -58,7 +59,8 @@ describe("TotalsServerSide fixture tests", () => {
|
|||||||
user: {}
|
user: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const computedOutput = await TotalsServerSide(req, dummyRes);
|
const computedOutput =
|
||||||
|
environment === "us" ? await TotalsServerSideUS(req, dummyRes) : await TotalsServerSideCA(req, dummyRes);
|
||||||
|
|
||||||
const normalizedComputed = normalizeOutput(computedOutput);
|
const normalizedComputed = normalizeOutput(computedOutput);
|
||||||
const normalizedExpected = normalizeOutput(expectedOutput);
|
const normalizedExpected = normalizeOutput(expectedOutput);
|
||||||
|
|||||||
@@ -19,20 +19,25 @@ const serializeDinero = (key, value) => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Capture a fixture for job totals.
|
* Capture a fixture for job totals.
|
||||||
* @param job
|
|
||||||
* @param inputData
|
* @param inputData
|
||||||
* @param outputData
|
* @param outputData
|
||||||
|
* @param environment
|
||||||
*/
|
*/
|
||||||
const captureFixture = (job, inputData, outputData) => {
|
const captureFixture = (inputData, outputData, environment) => {
|
||||||
if (!fs.existsSync(fixtureDir)) {
|
if (!fs.existsSync(fixtureDir)) {
|
||||||
fs.mkdirSync(fixtureDir, { recursive: true });
|
fs.mkdirSync(fixtureDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use job.id to label the file.
|
// Use job.id to label the file.
|
||||||
const fileName = `${job.id}.json`;
|
const fileName = `${inputData.id}.json`;
|
||||||
const filePath = path.join(fixtureDir, fileName);
|
const filePath = path.join(fixtureDir, fileName);
|
||||||
|
|
||||||
const dataToSave = {
|
const dataToSave = {
|
||||||
|
environment: environment,
|
||||||
|
meta: {
|
||||||
|
ro_number: inputData.ro_number,
|
||||||
|
updated_at: inputData.updated_at
|
||||||
|
},
|
||||||
input: inputData,
|
input: inputData,
|
||||||
output: outputData
|
output: outputData
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user