Skip to content

Commit

Permalink
Merge pull request #157 from DEFRA/BAU-improve-snapshot-test-helper-r…
Browse files Browse the repository at this point in the history
…eadability

BAU: refactor snapshot helper to take options object
  • Loading branch information
joseluisgraa authored Jan 24, 2025
2 parents 24c2a70 + f008dbe commit 226e8d2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
20 changes: 9 additions & 11 deletions src/server/common/test-helpers/snapshot-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import { withCsrfProtection } from './csrf.js'
/* global expect, it, beforeAll, afterAll, describe */

/**
* @param {string} describeMessage
* @param {string} shouldMessage
* @param {string} urlPath
* @param {{describes: string, it: string, pageUrl: string }} options
*/
export const describePageSnapshot = (
describeMessage,
shouldMessage,
urlPath
) => {
describe(describeMessage, () => {
export const describePageSnapshot = ({
describes,
it: itDescription,
pageUrl
}) => {
describe(describes, () => {
/** @type {Server} */
let server

Expand All @@ -28,11 +26,11 @@ export const describePageSnapshot = (
await server.stop({ timeout: 0 })
})

it(shouldMessage, async () => {
it(itDescription, async () => {
const { payload } = await server.inject(
withCsrfProtection({
method: 'GET',
url: urlPath
url: pageUrl
})
)

Expand Down
10 changes: 5 additions & 5 deletions src/server/cookies-policy/index.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { describePageSnapshot } from '../common/test-helpers/snapshot-page.js'

describePageSnapshot(
'#destinationSummaryController',
'should render expected response and content',
'/cookies'
)
describePageSnapshot({
describes: '#destinationSummaryController',
it: 'should render expected response and content',
pageUrl: '/cookies'
})

/**
* @import { Server } from '@hapi/hapi'
Expand Down
8 changes: 4 additions & 4 deletions src/server/destination/destination-type/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ describe('DestinationTypePage', () => {
expect(plugin).toHaveProperty('register')
})

describePageSnapshot(
'DestinationTypePage.content',
'should render expected response and content',
describePageSnapshot({
describes: 'DestinationTypePage.content',
it: 'should render expected response and content',
pageUrl
)
})
})

/** @import { PluginBase, PluginNameVersion, Server } from '@hapi/hapi' */
10 changes: 5 additions & 5 deletions src/server/destination/general-licence/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ describe('DestinationGeneralLicencePage', () => {
})
})

describePageSnapshot(
'DestinationGeneralLicenceController',
'should render the expected content',
page.urlPath
)
describePageSnapshot({
describes: 'DestinationGeneralLicenceController',
it: 'should render the expected content',
pageUrl: page.urlPath
})
8 changes: 4 additions & 4 deletions src/server/licence/receiveMethod/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ describe('ReceiveMethodPage', () => {
expect(plugin).toHaveProperty('register')
})

describePageSnapshot(
'DestinationTypePage.content',
'should render expected response and content',
describePageSnapshot({
describes: 'DestinationTypePage.content',
it: 'should render expected response and content',
pageUrl
)
})
})

/** @import { PluginBase, PluginNameVersion, Server } from '@hapi/hapi' */
8 changes: 4 additions & 4 deletions src/server/origin/origin-type/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ describe('OriginTypePage', () => {
expect(plugin).toHaveProperty('register')
})

describePageSnapshot(
'OriginTypePage.content',
'should render expected response and content',
describePageSnapshot({
describes: 'OriginTypePage.content',
it: 'should render expected response and content',
pageUrl
)
})
})

0 comments on commit 226e8d2

Please sign in to comment.