Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where transaction id is not recognised #2071

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading