Skip to content

Commit

Permalink
Only set a transaction id if one hasn't already been set
Browse files Browse the repository at this point in the history
  • Loading branch information
jaucourt committed Nov 6, 2024
1 parent 9b95146 commit 7da1374
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('The agreed handler', () => {
cache: () => ({
helpers: {
transaction: {
get: async () => ({ id: 'id-111', cost: 0 }),
get: async () => ({ cost: 0 }),
set: async () => {}
},
status: {
Expand Down Expand Up @@ -90,6 +90,26 @@ describe('The agreed handler', () => {
expect(transactionPayload.id).toBe(v4guid)
})

it("doesn't overwrite transaction id if one is already set", async () => {
const setTransaction = jest.fn()
const transactionId = 'abc-123-def-456'
uuidv4.mockReturnValue('def-789-ghi-012')
const mockRequest = getMockRequest({
transaction: {
get: async () => ({ cost: 0, id: transactionId }),
set: setTransaction
}
})

await agreedHandler(mockRequest, getRequestToolkit())

expect(setTransaction).toHaveBeenCalledWith(
expect.objectContaining({
id: transactionId
})
)
})

it('sends a recurring payment creation request to Gov.UK Pay', async () => {
const preparedPayment = Symbol('preparedPayment')
prepareRecurringPayment.mockResolvedValueOnce(preparedPayment)
Expand Down
4 changes: 3 additions & 1 deletion packages/gafl-webapp-service/src/handlers/agreed-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ const finaliseTransaction = async (request, transaction, status) => {
export default async (request, h) => {
const status = await request.cache().helpers.status.get()
const transaction = await request.cache().helpers.transaction.get()
transaction.id = uuidv4()
if (!transaction.id) {
transaction.id = uuidv4()
}

// If the agreed flag is not set to true then throw an exception
if (!status[COMPLETION_STATUS.agreed]) {
Expand Down

0 comments on commit 7da1374

Please sign in to comment.