@defra-fish/sales-api-service 1.63.0-rc.3 → 1.63.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra-fish/sales-api-service",
3
- "version": "1.63.0-rc.3",
3
+ "version": "1.63.0-rc.5",
4
4
  "description": "Rod Licensing Sales API",
5
5
  "type": "module",
6
6
  "engines": {
@@ -35,9 +35,9 @@
35
35
  "test": "echo \"Error: run tests from root\" && exit 1"
36
36
  },
37
37
  "dependencies": {
38
- "@defra-fish/business-rules-lib": "1.63.0-rc.3",
39
- "@defra-fish/connectors-lib": "1.63.0-rc.3",
40
- "@defra-fish/dynamics-lib": "1.63.0-rc.3",
38
+ "@defra-fish/business-rules-lib": "1.63.0-rc.5",
39
+ "@defra-fish/connectors-lib": "1.63.0-rc.5",
40
+ "@defra-fish/dynamics-lib": "1.63.0-rc.5",
41
41
  "@hapi/boom": "^9.1.2",
42
42
  "@hapi/hapi": "^20.1.3",
43
43
  "@hapi/inert": "^6.0.3",
@@ -52,5 +52,5 @@
52
52
  "moment-timezone": "^0.5.34",
53
53
  "uuid": "^8.3.2"
54
54
  },
55
- "gitHead": "326d589e6fa640bf0a4e895c7dd280699c1cde87"
55
+ "gitHead": "313d1d1a8ab65bd841c27cf615f8abeec527f401"
56
56
  }
@@ -96,27 +96,42 @@ describe('createTransactionSchema', () => {
96
96
  await expect(createTransactionSchema.validateAsync(mockPayload)).rejects.toThrow()
97
97
  })
98
98
 
99
- it('validates successfully when an agreementId is supplied', async () => {
99
+ it('validates successfully when recurring payment detail is supplied', async () => {
100
100
  const mockPayload = mockTransactionPayload()
101
- mockPayload.agreementId = 't3jl08v2nqqmujrnhs09pmhtjx'
101
+ mockPayload.recurringPayment = {
102
+ agreementId: 't3jl08v2nqqmujrnhs09pmhtjx',
103
+ id: 'fdc73d20-a0bf-4da6-9a49-2f0a24bd3509'
104
+ }
102
105
  await expect(createTransactionSchema.validateAsync(mockPayload)).resolves.not.toThrow()
103
106
  })
104
107
 
105
- it('validates successfully when agreementId is omitted', async () => {
108
+ it('validates successfully when recurring payment detail is omitted', async () => {
106
109
  const mockPayload = mockTransactionPayload()
107
110
  await expect(createTransactionSchema.validateAsync(mockPayload)).resolves.not.toThrow()
108
111
  })
109
112
 
113
+ it('fails validation if agreement id is omitted from recurring payment detail', async () => {
114
+ const mockPayload = mockTransactionPayload()
115
+ mockPayload.recurringPayment = { id: 'fdc73d20-a0bf-4da6-9a49-2f0a24bd3509' }
116
+ await expect(() => createTransactionSchema.validateAsync(mockPayload)).rejects.toThrow()
117
+ })
118
+
110
119
  it.each([
111
- ['too short string', 'foo'],
112
- ['too long string', 'foobarbazfoobarbazfoobarbaz'],
113
- ['string containing invalid characters', '!3j@08v2nqqmujrnhs09_mhtjx'],
114
- ['null', null],
115
- ['numeric', 4567]
116
- ])('fails validation when provided with a %s for agreementId', async (_d, agreementId) => {
120
+ ['agreement id is too long', { agreementId: 'thisistoolongtobeanagreementid' }],
121
+ ['agreement id is too short', { agreementId: 'tooshorttobeanagreementid' }],
122
+ ['agreement id contains invalid characters', '!3j@08v2nqqmujrnhs09_mhtjx'],
123
+ ['agreement id is null', { agreementId: null }],
124
+ ['agreement id is a numeric', { agreementId: 4567 }],
125
+ ['id is not a guid', { id: 'not-a-guid' }],
126
+ ['id is null', { id: null }]
127
+ ])('fails validation if %s', async (_d, recurringPayment) => {
117
128
  const mockPayload = mockTransactionPayload()
118
- mockPayload.agreementId = agreementId
119
- await expect(createTransactionSchema.validateAsync(mockPayload)).rejects.toThrow()
129
+ mockPayload.recurringPayment = {
130
+ agreementId: 'jhyu78iujhy7u87y6thu87uyj8',
131
+ id: '7a0660ec-8535-4357-b925-e598a9358119',
132
+ ...recurringPayment
133
+ }
134
+ await expect(() => createTransactionSchema.validateAsync(mockPayload)).rejects.toThrow()
120
135
  })
121
136
  })
122
137
 
@@ -36,7 +36,10 @@ const createTransactionRequestSchemaContent = {
36
36
  createdBy: Joi.string().optional(),
37
37
  journalId: Joi.string().optional(),
38
38
  transactionId: Joi.string().guid({ version: 'uuidv4' }).optional(),
39
- agreementId: Joi.string().alphanum().length(AGREEMENT_ID_LENGTH).optional()
39
+ recurringPayment: Joi.object({
40
+ agreementId: Joi.string().alphanum().length(AGREEMENT_ID_LENGTH).required(),
41
+ id: Joi.string().guid()
42
+ }).optional()
40
43
  }
41
44
 
42
45
  /**
@@ -392,7 +392,9 @@ describe('recurring payments service', () => {
392
392
  ...permission
393
393
  }
394
394
  ],
395
- agreementId,
395
+ recurringPayment: {
396
+ agreementId
397
+ },
396
398
  payment: {
397
399
  amount: 35.8,
398
400
  source: 'Gov Pay',
@@ -37,8 +37,8 @@ const getNextDueDate = (startDate, issueDate, endDate) => {
37
37
  }
38
38
 
39
39
  export const generateRecurringPaymentRecord = async (transactionRecord, permission) => {
40
- if (transactionRecord.agreementId) {
41
- const agreementResponse = await getRecurringPaymentAgreement(transactionRecord.agreementId)
40
+ if (transactionRecord.recurringPayment.agreementId) {
41
+ const agreementResponse = await getRecurringPaymentAgreement(transactionRecord.recurringPayment.agreementId)
42
42
  const lastDigitsCardNumbers = agreementResponse.payment_instrument?.card_details?.last_digits_card_number
43
43
  const [{ startDate, issueDate, endDate }] = transactionRecord.permissions
44
44
  return {
@@ -49,7 +49,7 @@ export const generateRecurringPaymentRecord = async (transactionRecord, permissi
49
49
  cancelledDate: null,
50
50
  cancelledReason: null,
51
51
  endDate,
52
- agreementId: transactionRecord.agreementId,
52
+ agreementId: transactionRecord.recurringPayment.agreementId,
53
53
  status: 1,
54
54
  last_digits_card_number: lastDigitsCardNumbers
55
55
  }