-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LIME-515 - feature sets functionality for documentCheckingRoute header
Signed-off-by: ElliotMurphyGDS <[email protected]>
- Loading branch information
1 parent
8553132
commit be08bb1
Showing
5 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters