Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: convert req.hashedFields to Set #617

Merged
merged 4 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/controllers/admin-forms.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,13 +598,13 @@ function makeModule(connection) {
switch (authType) {
case 'SP': {
res.locals.uinFin = 'S1234567A'
req.hashedFields = {}
res.locals.hashedFields = new Set()
let actualFormFields = req.form.form_fields
let actualMyInfoFields = actualFormFields.filter(
(field) => field.myInfo && field.myInfo.attr,
)
for (let field of actualMyInfoFields) {
req.hashedFields[field.myInfo.attr] = true
res.locals.hashedFields.add(field.myInfo.attr)
}
break
}
Expand Down
12 changes: 6 additions & 6 deletions src/app/controllers/email-submissions.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ exports.validateEmailSubmission = function (req, res, next) {
* @param {Function} next - Express next middleware function
*/
exports.prepareEmailSubmission = (req, res, next) => {
const { hashedFields } = req
const { hashedFields } = res.locals

const concatArray = (dataValue, srcValue) => {
if (_.isArray(dataValue)) {
Expand Down Expand Up @@ -332,11 +332,11 @@ exports.prepareEmailSubmission = (req, res, next) => {
* @param {String} response.fieldType
* @param {Object} response.myInfo
* @param {String} response.myInfo.attr
* @param {Object} hashedFields req.hashedFields
* @param {Set} hashedFields req.hashedFields
* @returns {Boolean} true if response is verified
*/
const isMyInfoVerifiedResponse = (response, hashedFields) => {
return !!(hashedFields && hashedFields[_.get(response, 'myInfo.attr')])
return !!(hashedFields && hashedFields.has(_.get(response, 'myInfo.attr')))
}

/**
Expand Down Expand Up @@ -382,7 +382,7 @@ const getAnswerForCheckbox = (response) => {
* @param {String} response.answer
* @param {String} response.fieldType
* @param {Boolean} response.isVisible
* @param {Boolean} hashedFields Fields hashed to verify answers provided by MyInfo
* @param {Set} hashedFields Fields hashed to verify answers provided by MyInfo
* @returns {Object} an object containing three sets of formatted responses
*/
const getFormattedResponse = (response, hashedFields) => {
Expand Down Expand Up @@ -418,7 +418,7 @@ const getFormattedResponse = (response, hashedFields) => {
/**
* Transforms a question for inclusion in the admin email table.
* @param {Object} response
* @param {Object} hashedFields
* @param {Set} hashedFields
*/
const getFormDataPrefixedQuestion = (response, hashedFields) => {
const { question, fieldType, isUserVerified } = response
Expand Down Expand Up @@ -472,7 +472,7 @@ const getFieldTypePrefix = (fieldType) => {
* Determines the prefix for a question based on whether it is verified
* by MyInfo.
* @param {Object} response
* @param {Object} hashedFields Hash for verifying MyInfo fields
* @param {Set} hashedFields Hash for verifying MyInfo fields
* @returns {String}
*/
const getMyInfoPrefix = (response, hashedFields) => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/controllers/myinfo.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ exports.verifyMyInfoVals = async function (req, res, next) {
_.uniq(clientMyInfoFields.map((field) => field.attr)),
_.keys(hashedFields),
)
req.hashedFields = _.pick(hashedFields, verifiedKeys)
res.locals.hashedFields = new Set(verifiedKeys)
return next()
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,7 @@ describe('Email Submissions Controller', () => {
const fieldId = new ObjectID()

const attr = 'passportnumber'
reqFixtures.hashedFields = {
[attr]: 'foobar',
}
resLocalFixtures.hashedFields = new Set([attr])
const responseField = {
_id: String(fieldId),
question: 'myinfo',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ describe('MyInfo Controller', () => {
next = jasmine.createSpy().and.callFake(() => {
expect(
_.isEqual(
new Set(_.keys(req.hashedFields)),
res.locals.hashedFields,
new Set(_.keys(ALL_MYINFO_HASHES)),
),
).toBeTruthy()
Expand Down