Skip to content

Commit

Permalink
Lint JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Dec 15, 2023
1 parent 503497b commit b421b73
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
20 changes: 9 additions & 11 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ const getFork = (forks, req) => {

if (fork.value || fork.values) {
const includedValues = toPath(fork.value ? fork.value : fork.values)
if (includedValues.some(v => sessionData.indexOf(v) >= 0)) {
if (includedValues.some((v) => sessionData.indexOf(v) >= 0)) {
return key
}
}

if (fork.excludedValue || fork.excludedValues) {
const excludedValues = toPath(fork.excludedValue
? fork.excludedValue
: fork.excludedValues)
const excludedValues = toPath(
fork.excludedValue ? fork.excludedValue : fork.excludedValues
)

if (!excludedValues.some(v => sessionData.indexOf(v) >= 0)) {
if (!excludedValues.some((v) => sessionData.indexOf(v) >= 0)) {
return key
}
}
Expand All @@ -58,16 +58,14 @@ const getPathWithSearchParams = (originalUrl, path) => {
// Add any path params to params on original URL
const originalParams = getSearchParams(originalUrl)
const pathParams = getSearchParams(path)
for (let [key, value] of originalParams.entries()) {
pathParams.append(key, value);
for (const [key, value] of originalParams.entries()) {
pathParams.append(key, value)
}

// Remove query string from path
path = path.split('?')[0]

return pathParams.size
? `${path}?${pathParams.toString()}`
: path
return pathParams.size ? `${path}?${pathParams.toString()}` : path
}

/**
Expand All @@ -77,7 +75,7 @@ const getPathWithSearchParams = (originalUrl, path) => {
*/
const getSearchParams = (originalUrl) => {
const queryString = originalUrl.split('?')[1]
const searchParams = new URLSearchParams(queryString);
const searchParams = new URLSearchParams(queryString)

return searchParams
}
Expand Down
4 changes: 2 additions & 2 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ describe('Utility functions', () => {

await t.test('and redirects with shorthand', () => {
const forks = {
'/country': req.session.data.country == 'England'
'/country': req.session.data.country === 'England'
}

assert.equal(utils.getFork(forks, req), '/country')
})

await t.test('and redirects if function returns `true`', () => {
const forks = {
'/country': () => req.session.data.country == 'England'
'/country': () => req.session.data.country === 'England'
}

assert.equal(utils.getFork(forks, req), '/country')
Expand Down
4 changes: 2 additions & 2 deletions test/wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('GOV.UK Prototype Wizard', () => {
'forked-to': '/email',
'forked-from': '/do-you-have-a-national-insurance-number'
}
},
}
}

assert.deepEqual(wizard(journey, req), {
Expand All @@ -78,7 +78,7 @@ describe('GOV.UK Prototype Wizard', () => {
data: {
'forked-from': '/do-you-have-a-national-insurance-number',
'forked-to': '/email'
},
}
},
originalUrl: '/do-you-have-a-national-insurance-number',
path: '/do-you-have-a-national-insurance-number'
Expand Down

0 comments on commit b421b73

Please sign in to comment.