Skip to content

Commit

Permalink
LIME-515 - feature sets functionality for documentCheckingRoute header
Browse files Browse the repository at this point in the history
Signed-off-by: ElliotMurphyGDS <[email protected]>
  • Loading branch information
ElliotMurphyGDS committed Sep 12, 2023
1 parent 8553132 commit be08bb1
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const { setGTM } = require("di-ipv-cri-common-express/src/lib/settings");
const { getGTM } = require("di-ipv-cri-common-express/src/lib/locals");
const steps = require("./app/drivingLicence/steps");
const fields = require("./app/drivingLicence/fields");
const featureSets = require("./app/drivingLicence/featureSets");


const {
API,
Expand Down Expand Up @@ -117,6 +119,7 @@ router.use(getGTM);

router.use(setScenarioHeaders);
router.use(setAxiosDefaults);
router.use(featureSets);

router.use("/oauth2", commonExpress.routes.oauth2);

Expand Down
19 changes: 19 additions & 0 deletions src/app/drivingLicence/controllers/featureSets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const logger = require("hmpo-logger").get();

module.exports = function (req, res, next) {
try {
const featureSet = req.query.featureSet;
const isValidFeatureSet = /^\w{1,32}$/.test(featureSet);
if (!isValidFeatureSet) {
throw new Error("Invalid feature set ID");
}

if (featureSet !== undefined) {
logger.info("feature set is " + featureSet);
req.session.featureSet = featureSet;
}
next();
} catch (error) {
return next(error);
}
};
46 changes: 46 additions & 0 deletions src/app/drivingLicence/controllers/featureSets.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const FeatureSets = require("./featureSets");

describe("feature sets", () => {
let req;
let res;
let next;
let sandbox;

beforeEach(() => {
sandbox = sinon.createSandbox();
const setup = setupDefaultMocks();
req = setup.req;
res = setup.res;
next = setup.next;
});
afterEach(() => sandbox.restore());

context("validateFeatureSet", () => {
beforeEach(() => {
req = {
query: {},
session: {},
};
res = {};
next = sinon.stub();
});

it("should call next if featureSet is valid", async () => {
req.query.featureSet = "F01";
await FeatureSets(req, res, next);
expect(req.session.featureSet).to.equal("F01");
expect(next).to.have.been.calledOnce;
});

it("should throw an error if featureSet is invalid", async () => {
req.query.featureSet = "invalid-featureset";
await FeatureSets(req, res, next);
expect(next).to.have.been.calledWith(
sinon.match
.instanceOf(Error)
.and(sinon.match.has("message", "Invalid feature set ID"))
);
expect(req.session.featureSet).to.be.undefined;
});
});
});
4 changes: 4 additions & 0 deletions src/app/drivingLicence/controllers/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class ValidateController extends BaseController {
session_id: req.session.tokenId,
};

if (req.session.featureSet === "direct") {
headers["document-checking-route"] = "direct";
}

logger.info("validate: calling check-driving-licence lambda", {
req,
res,
Expand Down
59 changes: 59 additions & 0 deletions src/app/drivingLicence/controllers/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,65 @@ describe("validate controller", () => {
expect(req.sessionModel.get("redirect_url")).to.eq(data.redirectUrl);
});

it("should add a document check routing header if a feature set has been set", async () => {
const sessionId = "drivingLicence123";

req.sessionModel.set("drivingLicenceNumber", "SMITH9702105LN99");
req.sessionModel.set("issueNumber", "12");
req.sessionModel.set("postcode", "SW1 EQR");
req.session.tokenId = sessionId;
req.sessionModel.set("surname", "Smith");
req.sessionModel.set("firstName", "Dan");
req.sessionModel.set("middleNames", "Joe");
req.sessionModel.set("dateOfBirth", "10/02/1975");
req.sessionModel.set("expiryDate", "15/01/2035");
req.sessionModel.set("issueDate", "10/02/2005");
req.sessionModel.set("dateOfIssue", "10/02/2005");
req.sessionModel.set("licenceIssuer", "DVLA");
req.session.authParams = {
redirect_uri: "A VALUE",
state: "A VALUE",
};
req.session.featureSet = "hmpoDVAD";

const data = {
redirectUrl:
"https://client.example.com/cb?id=DrivingLicenceIssuer&code=1234",
retry: false,
};

const resolvedPromise = new Promise((resolve) => resolve({ data }));
sandbox.stub(axios, "post").returns(resolvedPromise);

await validate.saveValues(req, res, next);

sandbox.assert.calledWith(
stub,
"check-driving-licence",
{
drivingLicenceNumber: "SMITH9702105LN99",
issueNumber: "12",
postcode: "SW1 EQR",
surname: "Smith",
forenames: ["Dan", "Joe"],
dateOfBirth: "10/02/1975",
expiryDate: "15/01/2035",
issueDate: "10/02/2005",
licenceIssuer: "DVLA",
},
{
headers: {
"document-checking-route": "direct",
session_id: sessionId,
},
}
);

expect(req.session.authParams.redirect_uri).to.eq(
"https://client.example.com"
);
});

it("should set an error object in the session if redirect url is missing", async () => {
req.sessionModel.set("drivingLicenceNumber", "SMITH9702105LN99");
req.sessionModel.set("issueNumber", "12");
Expand Down

0 comments on commit be08bb1

Please sign in to comment.