@defra-fish/gafl-webapp-service
Version:
The websales frontend for the GAFL service
58 lines (48 loc) • 1.91 kB
JavaScript
import { getData } from '../route'
import { CONTACT } from '../../../../../uri'
import { isPhysical } from '../../../../../processors/licence-type-display.js'
import { youOrOther } from '../../../../../processors/message-helper.js'
jest.mock('../../../../../processors/licence-type-display.js', () => ({
isPhysical: jest.fn(() => true)
}))
jest.mock('../../../../../processors/message-helper.js')
describe('licence-fulfilment > route', () => {
const getMockRequest = (permission = {}) => ({
cache: () => ({
helpers: {
transaction: {
getCurrentPermission: () => permission
}
}
})
})
describe('getData', () => {
beforeEach(jest.clearAllMocks)
it('should throw an error if the licence is not physical', async () => {
isPhysical.mockReturnValueOnce(false)
const func = async () => await getData(getMockRequest())
await expect(func).rejects.toThrowRedirectTo(CONTACT.uri)
})
it('should call youOrOther with the permission', async () => {
const permission = Symbol('permission')
await getData(getMockRequest(permission))
expect(youOrOther).toHaveBeenCalledWith(permission)
})
it('should use the value returned by youOrOther', async () => {
const returnedValue = Symbol('value')
youOrOther.mockReturnValueOnce(returnedValue)
const result = await getData(getMockRequest())
expect(result.youOrOther).toEqual(returnedValue)
})
it.each([
[true, 'true'],
[false, 'false'],
[false, undefined]
])('showNotificationBanner is %s when process.env.SHOW_NOTIFICATION_BANNER is %s', async (expectedResult, notification) => {
process.env.SHOW_NOTIFICATION_BANNER = notification
const mockRequest = getMockRequest()
const result = await getData(mockRequest)
expect(result.showNotificationBanner).toEqual(expectedResult)
})
})
})