@defra-fish/recurring-payments-job 1.63.0-rc.3 → 1.63.0-rc.4

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/recurring-payments-job",
3
- "version": "1.63.0-rc.3",
3
+ "version": "1.63.0-rc.4",
4
4
  "description": "Rod Licensing Recurring Payments Job",
5
5
  "type": "module",
6
6
  "engines": {
@@ -36,11 +36,11 @@
36
36
  "test": "echo \"Error: run tests from root\" && exit 1"
37
37
  },
38
38
  "dependencies": {
39
- "@defra-fish/business-rules-lib": "1.63.0-rc.3",
40
- "@defra-fish/connectors-lib": "1.63.0-rc.3",
39
+ "@defra-fish/business-rules-lib": "1.63.0-rc.4",
40
+ "@defra-fish/connectors-lib": "1.63.0-rc.4",
41
41
  "commander": "^7.2.0",
42
42
  "debug": "^4.3.3",
43
43
  "moment-timezone": "^0.5.34"
44
44
  },
45
- "gitHead": "326d589e6fa640bf0a4e895c7dd280699c1cde87"
45
+ "gitHead": "19c5ac3cf85aa9f3dc5e7ebc0f14cfe88936125c"
46
46
  }
@@ -59,8 +59,8 @@ const getMockPaymentRequestResponse = () => [
59
59
  }
60
60
  ]
61
61
 
62
- const getMockDueRecurringPayment = (referenceNumber = '123', agreementId = 'test-agreement-id') => ({
63
- entity: { agreementId },
62
+ const getMockDueRecurringPayment = ({ agreementId = 'test-agreement-id', id = 'abc-123', referenceNumber = '123' } = {}) => ({
63
+ entity: { id, agreementId },
64
64
  expanded: { activePermission: { entity: { referenceNumber } } }
65
65
  })
66
66
 
@@ -147,10 +147,10 @@ describe('recurring-payments-processor', () => {
147
147
  it('prepares and sends all payment requests, even if some fail', async () => {
148
148
  const agreementIds = [Symbol('agreementId1'), Symbol('agreementId2'), Symbol('agreementId3'), Symbol('agreementId4')]
149
149
  salesApi.getDueRecurringPayments.mockReturnValueOnce([
150
- getMockDueRecurringPayment('fee', agreementIds[0]),
151
- getMockDueRecurringPayment('fi', agreementIds[1]),
152
- getMockDueRecurringPayment('foe', agreementIds[2]),
153
- getMockDueRecurringPayment('fum', agreementIds[3])
150
+ getMockDueRecurringPayment({ referenceNumber: 'fee', agreementId: agreementIds[0] }),
151
+ getMockDueRecurringPayment({ referenceNumber: 'fi', agreementId: agreementIds[1] }),
152
+ getMockDueRecurringPayment({ referenceNumber: 'foe', agreementId: agreementIds[2] }),
153
+ getMockDueRecurringPayment({ referenceNumber: 'fum', agreementId: agreementIds[3] })
154
154
  ])
155
155
 
156
156
  const permissionData = { licensee: { countryCode: 'GB-ENG' } }
@@ -202,9 +202,9 @@ describe('recurring-payments-processor', () => {
202
202
  it('logs an error for every failure', async () => {
203
203
  const errors = [new Error('error 1'), new Error('error 2'), new Error('error 3')]
204
204
  salesApi.getDueRecurringPayments.mockReturnValueOnce([
205
- getMockDueRecurringPayment('fee', 'a1'),
206
- getMockDueRecurringPayment('fi', 'a2'),
207
- getMockDueRecurringPayment('foe', 'a3')
205
+ getMockDueRecurringPayment({ referenceNumber: 'fee', agreementId: 'a1' }),
206
+ getMockDueRecurringPayment({ referenceNumber: 'fi', agreementId: 'a2' }),
207
+ getMockDueRecurringPayment({ referenceNumber: 'foe', agreementId: 'a3' })
208
208
  ])
209
209
  const permissionData = { licensee: { countryCode: 'GB-ENG' } }
210
210
  salesApi.preparePermissionDataForRenewal
@@ -241,7 +241,7 @@ describe('recurring-payments-processor', () => {
241
241
 
242
242
  it('prepares the data for found recurring payments', async () => {
243
243
  const referenceNumber = Symbol('reference')
244
- salesApi.getDueRecurringPayments.mockReturnValueOnce([getMockDueRecurringPayment(referenceNumber)])
244
+ salesApi.getDueRecurringPayments.mockReturnValueOnce([getMockDueRecurringPayment({ referenceNumber })])
245
245
  const mockPaymentResponse = { payment_id: 'test-payment-id', created_date: '2025-01-01T00:00:00.000Z' }
246
246
  sendPayment.mockResolvedValueOnce(mockPaymentResponse)
247
247
  getPaymentStatus.mockResolvedValueOnce(getPaymentStatusSuccess())
@@ -252,7 +252,9 @@ describe('recurring-payments-processor', () => {
252
252
  })
253
253
 
254
254
  it('creates a transaction with the correct data', async () => {
255
- salesApi.getDueRecurringPayments.mockReturnValueOnce([getMockDueRecurringPayment()])
255
+ const id = Symbol('recurring-payment-id')
256
+ const agreementId = Symbol('agreement-id')
257
+ salesApi.getDueRecurringPayments.mockReturnValueOnce([getMockDueRecurringPayment({ agreementId, id })])
256
258
 
257
259
  const isLicenceForYou = Symbol('isLicenceForYou')
258
260
  const isRenewal = Symbol('isRenewal')
@@ -277,7 +279,10 @@ describe('recurring-payments-processor', () => {
277
279
 
278
280
  const expectedData = {
279
281
  dataSource: 'Recurring Payment',
280
- agreementId: 'test-agreement-id',
282
+ recurringPayment: {
283
+ agreementId,
284
+ id
285
+ },
281
286
  permissions: [
282
287
  {
283
288
  isLicenceForYou,
@@ -387,7 +392,7 @@ describe('recurring-payments-processor', () => {
387
392
  const agreementId = Symbol('agreementId')
388
393
  const transactionId = 'transactionId'
389
394
 
390
- salesApi.getDueRecurringPayments.mockReturnValueOnce([getMockDueRecurringPayment('foo', agreementId)])
395
+ salesApi.getDueRecurringPayments.mockReturnValueOnce([getMockDueRecurringPayment({ referenceNumber: 'foo', agreementId: agreementId })])
391
396
 
392
397
  salesApi.preparePermissionDataForRenewal.mockReturnValueOnce({
393
398
  licensee: { countryCode: 'GB-ENG' }
@@ -529,7 +534,7 @@ describe('recurring-payments-processor', () => {
529
534
 
530
535
  it('should call setTimeout with correct delay when there are recurring payments', async () => {
531
536
  const referenceNumber = Symbol('reference')
532
- salesApi.getDueRecurringPayments.mockResolvedValueOnce([getMockDueRecurringPayment(referenceNumber)])
537
+ salesApi.getDueRecurringPayments.mockResolvedValueOnce([getMockDueRecurringPayment({ referenceNumber })])
533
538
  const mockPaymentResponse = { payment_id: 'test-payment-id' }
534
539
  sendPayment.mockResolvedValueOnce(mockPaymentResponse)
535
540
  getPaymentStatus.mockResolvedValueOnce(getPaymentStatusSuccess())
@@ -592,7 +597,7 @@ describe('recurring-payments-processor', () => {
592
597
  'console error displays "Payment failed. Recurring payment agreement for: %s set to be cancelled" when payment is a %status',
593
598
  async (agreementId, mockStatus, status) => {
594
599
  const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(jest.fn())
595
- salesApi.getDueRecurringPayments.mockReturnValueOnce([getMockDueRecurringPayment('reference', agreementId)])
600
+ salesApi.getDueRecurringPayments.mockReturnValueOnce([getMockDueRecurringPayment({ agreementId })])
596
601
  const mockPaymentResponse = { payment_id: 'test-payment-id', created_date: '2025-01-01T00:00:00.000Z' }
597
602
  sendPayment.mockResolvedValueOnce(mockPaymentResponse)
598
603
  getPaymentStatus.mockResolvedValueOnce(mockStatus)
@@ -646,8 +651,8 @@ describe('recurring-payments-processor', () => {
646
651
  references.push(Symbol('reference' + i))
647
652
  }
648
653
  const mockGetDueRecurringPayments = []
649
- references.forEach(reference => {
650
- mockGetDueRecurringPayments.push(getMockDueRecurringPayment(reference))
654
+ references.forEach(referenceNumber => {
655
+ mockGetDueRecurringPayments.push(getMockDueRecurringPayment({ referenceNumber }))
651
656
  })
652
657
  salesApi.getDueRecurringPayments.mockReturnValueOnce(mockGetDueRecurringPayments)
653
658
  const mockPaymentResponse = { payment_id: 'test-payment-id' }
@@ -667,8 +672,14 @@ describe('recurring-payments-processor', () => {
667
672
 
668
673
  it('creates a transaction for each one', async () => {
669
674
  const mockGetDueRecurringPayments = []
675
+ const agreementIds = []
676
+ const ids = []
670
677
  for (let i = 0; i < count; i++) {
671
- mockGetDueRecurringPayments.push(getMockDueRecurringPayment(i))
678
+ const agreementId = Symbol(`agreement-id-${i}`)
679
+ const id = Symbol(`recurring-payment-${i}`)
680
+ agreementIds.push(agreementId)
681
+ ids.push(id)
682
+ mockGetDueRecurringPayments.push(getMockDueRecurringPayment({ agreementId, id, referenceNumber: i }))
672
683
  }
673
684
  salesApi.getDueRecurringPayments.mockReturnValueOnce(mockGetDueRecurringPayments)
674
685
 
@@ -685,11 +696,14 @@ describe('recurring-payments-processor', () => {
685
696
  })
686
697
 
687
698
  const expectedData = []
688
- permits.forEach(permit => {
699
+ permits.forEach((permit, i) => {
689
700
  expectedData.push([
690
701
  {
691
702
  dataSource: 'Recurring Payment',
692
- agreementId: 'test-agreement-id',
703
+ recurringPayment: {
704
+ agreementId: agreementIds[i],
705
+ id: ids[i]
706
+ },
693
707
  permissions: [expect.objectContaining({ permitId: permit })]
694
708
  }
695
709
  ])
@@ -706,7 +720,7 @@ describe('recurring-payments-processor', () => {
706
720
  for (let i = 0; i < count; i++) {
707
721
  const agreementId = Symbol(`agreementId${1}`)
708
722
  agreementIds.push(agreementId)
709
- mockGetDueRecurringPayments.push(getMockDueRecurringPayment(i, agreementId))
723
+ mockGetDueRecurringPayments.push(getMockDueRecurringPayment({ agreementId }))
710
724
  }
711
725
  salesApi.getDueRecurringPayments.mockReturnValueOnce(mockGetDueRecurringPayments)
712
726
 
@@ -749,7 +763,7 @@ describe('recurring-payments-processor', () => {
749
763
  for (let i = 0; i < count; i++) {
750
764
  const agreementId = Symbol(`agreementId${1}`)
751
765
  agreementIds.push(agreementId)
752
- mockGetDueRecurringPayments.push(getMockDueRecurringPayment(i, agreementId))
766
+ mockGetDueRecurringPayments.push(getMockDueRecurringPayment({ agreementId }))
753
767
  }
754
768
  salesApi.getDueRecurringPayments.mockReturnValueOnce(mockGetDueRecurringPayments)
755
769
 
@@ -64,13 +64,13 @@ const requestPayments = async dueRCPayments => {
64
64
 
65
65
  const processRecurringPayment = async record => {
66
66
  const referenceNumber = record.expanded.activePermission.entity.referenceNumber
67
- const agreementId = record.entity.agreementId
68
- const transaction = await createNewTransaction(referenceNumber, agreementId)
67
+ const { agreementId, id } = record.entity
68
+ const transaction = await createNewTransaction(referenceNumber, { agreementId, id })
69
69
  return takeRecurringPayment(agreementId, transaction)
70
70
  }
71
71
 
72
- const createNewTransaction = async (referenceNumber, agreementId) => {
73
- const transactionData = await processPermissionData(referenceNumber, agreementId)
72
+ const createNewTransaction = async (referenceNumber, recurringPayment) => {
73
+ const transactionData = await processPermissionData(referenceNumber, recurringPayment)
74
74
  return salesApi.createTransaction(transactionData)
75
75
  }
76
76
 
@@ -85,12 +85,12 @@ const takeRecurringPayment = async (agreementId, transaction) => {
85
85
  }
86
86
  }
87
87
 
88
- const processPermissionData = async (referenceNumber, agreementId) => {
88
+ const processPermissionData = async (referenceNumber, recurringPayment) => {
89
89
  const data = await salesApi.preparePermissionDataForRenewal(referenceNumber)
90
90
  const licenseeWithoutCountryCode = Object.assign((({ countryCode: _countryCode, ...l }) => l)(data.licensee))
91
91
  return {
92
92
  dataSource: 'Recurring Payment',
93
- agreementId,
93
+ recurringPayment,
94
94
  permissions: [
95
95
  {
96
96
  isLicenceForYou: data.isLicenceForYou,