diff --git a/server/job/job-totals-USA.js b/server/job/job-totals-USA.js index 2b92702bb..cf22c3adc 100644 --- a/server/job/job-totals-USA.js +++ b/server/job/job-totals-USA.js @@ -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, { diff --git a/server/job/job-totals.js b/server/job/job-totals.js index 92edcd238..f9c2ec8fa 100644 --- a/server/job/job-totals.js +++ b/server/job/job-totals.js @@ -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, { diff --git a/server/job/test/job-totals.test.js b/server/job/test/job-totals.test.js index d615d169c..6f5af805b 100644 --- a/server/job/test/job-totals.test.js +++ b/server/job/test/job-totals.test.js @@ -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); diff --git a/server/job/utils/seralizeHelper.js b/server/job/utils/seralizeHelper.js index b95779b7b..3d7aae03c 100644 --- a/server/job/utils/seralizeHelper.js +++ b/server/job/utils/seralizeHelper.js @@ -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 };