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.
|
||||
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, {
|
||||
|
||||
@@ -2,6 +2,7 @@ const Dinero = require("dinero.js");
|
||||
const queries = require("../graphql-client/queries");
|
||||
const logger = require("../utils/logger");
|
||||
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.
|
||||
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, {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
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
|
||||
@@ -48,7 +49,7 @@ describe("TotalsServerSide fixture tests", () => {
|
||||
const fixturePath = path.join(fixturesDir, file);
|
||||
const fixtureData = JSON.parse(fs.readFileSync(fixturePath, "utf8"));
|
||||
|
||||
const { input, output: expectedOutput } = fixtureData;
|
||||
const { environment, input, output: expectedOutput } = fixtureData;
|
||||
|
||||
const req = {
|
||||
body: {
|
||||
@@ -58,7 +59,8 @@ describe("TotalsServerSide fixture tests", () => {
|
||||
user: {}
|
||||
};
|
||||
|
||||
const computedOutput = await TotalsServerSide(req, dummyRes);
|
||||
const computedOutput =
|
||||
environment === "us" ? await TotalsServerSideUS(req, dummyRes) : await TotalsServerSideCA(req, dummyRes);
|
||||
|
||||
const normalizedComputed = normalizeOutput(computedOutput);
|
||||
const normalizedExpected = normalizeOutput(expectedOutput);
|
||||
|
||||
@@ -19,20 +19,25 @@ const serializeDinero = (key, value) => {
|
||||
|
||||
/**
|
||||
* Capture a fixture for job totals.
|
||||
* @param job
|
||||
* @param inputData
|
||||
* @param outputData
|
||||
* @param environment
|
||||
*/
|
||||
const captureFixture = (job, inputData, outputData) => {
|
||||
const captureFixture = (inputData, outputData, environment) => {
|
||||
if (!fs.existsSync(fixtureDir)) {
|
||||
fs.mkdirSync(fixtureDir, { recursive: true });
|
||||
}
|
||||
|
||||
// Use job.id to label the file.
|
||||
const fileName = `${job.id}.json`;
|
||||
const fileName = `${inputData.id}.json`;
|
||||
const filePath = path.join(fixtureDir, fileName);
|
||||
|
||||
const dataToSave = {
|
||||
environment: environment,
|
||||
meta: {
|
||||
ro_number: inputData.ro_number,
|
||||
updated_at: inputData.updated_at
|
||||
},
|
||||
input: inputData,
|
||||
output: outputData
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user