feature/IO-2769-Job-Totals-testing: Setup testing method for job totals
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
const Dinero = require("dinero.js");
|
||||
const queries = require("../graphql-client/queries");
|
||||
// const adminClient = require("../graphql-client/graphql-client").client;
|
||||
// const _ = require("lodash");
|
||||
const logger = require("../utils/logger");
|
||||
const { captureFixture } = require("./utils/seralizeHelper");
|
||||
const InstanceMgr = require("../utils/instanceMgr").default;
|
||||
|
||||
//****************************************************** */
|
||||
@@ -33,7 +32,15 @@ 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;
|
||||
|
||||
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,
|
||||
@@ -45,9 +52,11 @@ exports.totalsSsu = async function (req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
if (result) {
|
||||
res.status(200).send();
|
||||
if (!result) {
|
||||
throw new Error("Failed to update job totals");
|
||||
}
|
||||
|
||||
res.status(200).send();
|
||||
} catch (error) {
|
||||
logger.log("job-totals-ssu-USA-error", "ERROR", req?.user?.email, id, {
|
||||
jobid: id,
|
||||
@@ -58,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 });
|
||||
@@ -133,6 +142,9 @@ async function TotalsServerSide(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
// Exported for testing purposes.
|
||||
exports.TotalsServerSide = TotalsServerSide;
|
||||
|
||||
async function Totals(req, res) {
|
||||
const { job, id } = req.body;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user