@defra-fish/gafl-webapp-service
Version:
The websales frontend for the GAFL service
63 lines (56 loc) • 1.8 kB
JavaScript
import updateTransaction from '../update-transaction.js'
import { COMPLETION_STATUS } from '../../../../constants.js'
describe('payment failed update-transaction', () => {
const testScenarios = [
[
'resets paymentCreated and paymentFailed flags to enable retry',
{
[]: true,
[]: true,
[]: true,
otherFlag: true
},
{
[]: false,
[]: false,
[]: true,
otherFlag: true
}
],
[
'works when flags are already false',
{
[]: false,
[]: false
},
{
[]: false,
[]: false
}
]
]
const executeUpdateTransaction = async initialStatus => {
const mockSet = jest.fn()
const mockGet = jest.fn().mockResolvedValueOnce(initialStatus)
const request = {
cache: () => ({
helpers: {
status: {
get: mockGet,
set: mockSet
}
}
})
}
await updateTransaction(request)
return { mockGet, mockSet }
}
it.each(testScenarios)('%s - calls get once', async (description, initialStatus) => {
const { mockGet } = await executeUpdateTransaction(initialStatus)
expect(mockGet).toHaveBeenCalledTimes(1)
})
it.each(testScenarios)('%s - sets correct status', async (description, initialStatus, expectedStatus) => {
const { mockSet } = await executeUpdateTransaction(initialStatus)
expect(mockSet).toHaveBeenCalledWith(expectedStatus)
})
})