feature/IO-2769-Job-Totals-testing: Setup testing method for job totals

This commit is contained in:
Dave Richer
2025-04-04 13:19:44 -04:00
parent b44b71072f
commit 320ad065d0
6 changed files with 151 additions and 10 deletions

View File

@@ -1,6 +1,7 @@
const Dinero = require("dinero.js");
const queries = require("../graphql-client/queries");
const logger = require("../utils/logger");
const { captureFixture } = require("./utils/seralizeHelper");
//****************************************************** */
//****************************************************** */
@@ -30,7 +31,16 @@ exports.totalsSsu = async function (req, res) {
id: id
});
const newTotals = await TotalsServerSide({ body: { job: job.jobs_by_pk, client: client } }, res, true);
// Extract the job data (the input for TotalsServerSide)
const inputForTotals = job.jobs_by_pk;
// Capture the output of TotalsServerSide
const newTotals = await TotalsServerSide({ body: { job: inputForTotals, client: client } }, res, true);
// Capture fixture data (input and output), using job.id for the filename.
if (process.env?.SAVE_TOTALS_DATA) {
captureFixture(inputForTotals, inputForTotals, newTotals);
}
const result = await client.setHeaders({ Authorization: BearerToken }).request(queries.UPDATE_JOB, {
jobId: id,
@@ -57,7 +67,7 @@ exports.totalsSsu = async function (req, res) {
}
};
//IMPORTANT*** These two functions MUST be mirrrored.
//IMPORTANT*** These two functions MUST be mirrored.
async function TotalsServerSide(req, res) {
const { job, client } = req.body;
await AtsAdjustmentsIfRequired({ job: job, client: client, user: req?.user });
@@ -81,6 +91,9 @@ async function TotalsServerSide(req, res) {
}
}
// Exported for testing purposes
exports.TotalsServerSide = TotalsServerSide;
async function Totals(req, res) {
const { job, id } = req.body;