Skip to content

Commit

Permalink
Store agreementId in DynamoDb
Browse files Browse the repository at this point in the history
  • Loading branch information
irisfaraway committed Nov 11, 2024
1 parent 992b7aa commit 9f3088b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('The agreed handler', () => {

await agreedHandler(getMockRequest(), getRequestToolkit())

expect(prepareApiTransactionPayload).toHaveBeenCalledWith(expect.any(Object), v4guid)
expect(prepareApiTransactionPayload).toHaveBeenCalledWith(expect.any(Object), v4guid, undefined)
})

it.each(['zxy-098-wvu-765', '467482f1-099d-403d-b6b3-8db7e70d19e3'])(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const debug = db('webapp:agreed-handler')
* @returns {Promise<*>}
*/
const sendToSalesApi = async (request, transaction, status) => {
const apiTransactionPayload = await prepareApiTransactionPayload(request, transaction.id)
const apiTransactionPayload = await prepareApiTransactionPayload(request, transaction.id, transaction.agreementId)
let response
try {
response = await salesApi.createTransaction(apiTransactionPayload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,22 @@ describe('prepareApiTransactionPayload', () => {
})
})

it('adds transaction id to payload', async () => {
it('adds transactionId to payload', async () => {
const transactionId = Symbol('transactionId')

const payload = await prepareApiTransactionPayload(getMockRequest(), transactionId)

expect(payload.transactionId).toBe(transactionId)
})

it('adds agreementId to payload', async () => {
const agreementId = Symbol('agreementId')

const payload = await prepareApiTransactionPayload(getMockRequest(), 'transaction_id', agreementId)

expect(payload.agreementId).toBe(agreementId)
})

const getMockRequest = (overrides = {}, state = {}) => ({
cache: () => ({
helpers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { countries } from './refdata-helper.js'
import { salesApi } from '@defra-fish/connectors-lib'
import { licenceToStart } from '../pages/licence-details/licence-to-start/update-transaction.js'

export const prepareApiTransactionPayload = async (request, transactionId) => {
export const prepareApiTransactionPayload = async (request, transactionId, agreementId) => {
const transactionCache = await request.cache().helpers.transaction.get()
const concessions = await salesApi.concessions.getAll()
const countryList = await countries.getAll()
Expand Down Expand Up @@ -63,7 +63,8 @@ export const prepareApiTransactionPayload = async (request, transactionId) => {
request.state && request.state[process.env.OIDC_SESSION_COOKIE_NAME]
? request.state[process.env.OIDC_SESSION_COOKIE_NAME].oid
: undefined,
transactionId
transactionId,
agreementId
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('createTransactionSchema', () => {
await expect(createTransactionSchema.validateAsync(mockPayload)).rejects.toThrow('"permissions[0].isLicenceForYou" must be a boolean')
})

it('validates successfully when a uuid v4 transaction id is supplied', async () => {
it('validates successfully when a uuid v4 transactionId is supplied', async () => {
const mockPayload = mockTransactionPayload()
mockPayload.transactionId = '25fa0126-55da-4309-9bce-9957990d141e'
await expect(createTransactionSchema.validateAsync(mockPayload)).resolves.not.toThrow()
Expand All @@ -90,11 +90,36 @@ describe('createTransactionSchema', () => {
['uuid6 string', 'a3bb189e-8bf9-3888-9912-ace4e6543002'],
['uuid7 string', '01927705-ffac-77b5-89af-c97451b1bbe2'],
['numeric', 4567]
])('fails validation when provided with a %s', async (_d, transactionId) => {
])('fails validation when provided with a %s for transactionId', async (_d, transactionId) => {
const mockPayload = mockTransactionPayload()
mockPayload.transactionId = transactionId
await expect(createTransactionSchema.validateAsync(mockPayload)).rejects.toThrow()
})

it('validates successfully when a uuid v4 agreementId is supplied', async () => {
const mockPayload = mockTransactionPayload()
mockPayload.agreementId = '25fa0126-55da-4309-9bce-9957990d141e'
await expect(createTransactionSchema.validateAsync(mockPayload)).resolves.not.toThrow()
})

it('validates successfully when agreementId is omitted', async () => {
const mockPayload = mockTransactionPayload()
await expect(createTransactionSchema.validateAsync(mockPayload)).resolves.not.toThrow()
})

it.each([
['uuid1 string', '5a429f62-871b-11ef-b864-0242ac120002'],
['uuid2 string', '000003e8-871b-21ef-8000-325096b39f47'],
['uuid3 string', 'a3bb189e-8bf9-3888-9912-ace4e6543002'],
['uuid5 string', 'a6edc906-2f9f-5fb2-a373-efac406f0ef2'],
['uuid6 string', 'a3bb189e-8bf9-3888-9912-ace4e6543002'],
['uuid7 string', '01927705-ffac-77b5-89af-c97451b1bbe2'],
['numeric', 4567]
])('fails validation when provided with a %s for agreementId', async (_d, agreementId) => {
const mockPayload = mockTransactionPayload()
mockPayload.agreementId = agreementId
await expect(createTransactionSchema.validateAsync(mockPayload)).rejects.toThrow()
})
})

describe('createTransactionResponseSchema', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/sales-api-service/src/schema/transaction.schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const createTransactionRequestSchemaContent = {
}),
createdBy: Joi.string().optional(),
journalId: Joi.string().optional(),
transactionId: Joi.string().guid({ version: 'uuidv4' })
transactionId: Joi.string().guid({ version: 'uuidv4' }),
agreementId: Joi.string().guid({ version: 'uuidv4' })
}

/**
Expand Down

0 comments on commit 9f3088b

Please sign in to comment.