@defra-fish/sales-api-service 1.63.0-rc.10 → 1.63.0-rc.12

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.10",
3
+ "version": "1.63.0-rc.12",
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.10",
39
- "@defra-fish/connectors-lib": "1.63.0-rc.10",
40
- "@defra-fish/dynamics-lib": "1.63.0-rc.10",
38
+ "@defra-fish/business-rules-lib": "1.63.0-rc.12",
39
+ "@defra-fish/connectors-lib": "1.63.0-rc.12",
40
+ "@defra-fish/dynamics-lib": "1.63.0-rc.12",
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": "c4301461b148cbf244c1bb5c834521243ec0a534"
55
+ "gitHead": "077b17c4a39822d8db2419d99e0a8dce2bb4a8ff"
56
56
  }
@@ -33,10 +33,10 @@ const getResponseSampleData = () => ({
33
33
  mobilePhone: null,
34
34
  organisation: null,
35
35
  premises: '1',
36
- street: 'Catharine Place',
36
+ street: 'Test Street',
37
37
  locality: null,
38
- town: 'Bath',
39
- postcode: 'BA1 2PR'
38
+ town: 'Testville',
39
+ postcode: 'TE1 1ST'
40
40
  }
41
41
  },
42
42
  activePermission: {
@@ -166,3 +166,19 @@ describe('cancelRecurringPaymentRequestParamsSchema', () => {
166
166
  expect(() => cancelRecurringPaymentRequestParamsSchema.validateAsync(sampleData).rejects.toThrow())
167
167
  })
168
168
  })
169
+
170
+ describe('cancelRecurringPaymentRequestParamsSchema', () => {
171
+ it('validates expected object', async () => {
172
+ const sampleData = { id: 'abc123' }
173
+ expect(() => cancelRecurringPaymentRequestParamsSchema.validateAsync(sampleData)).not.toThrow()
174
+ })
175
+
176
+ it('throws an error if id missing', async () => {
177
+ expect(() => cancelRecurringPaymentRequestParamsSchema.validateAsync({}).rejects.toThrow())
178
+ })
179
+
180
+ it('throws an error if id is not the correct type', async () => {
181
+ const sampleData = { id: 99 }
182
+ expect(() => cancelRecurringPaymentRequestParamsSchema.validateAsync(sampleData).rejects.toThrow())
183
+ })
184
+ })
@@ -5,6 +5,7 @@ import {
5
5
  findRecurringPaymentsByAgreementId,
6
6
  findById,
7
7
  Permission,
8
+ persist,
8
9
  RecurringPayment
9
10
  } from '@defra-fish/dynamics-lib'
10
11
  import {
@@ -48,7 +49,8 @@ jest.mock('@defra-fish/dynamics-lib', () => ({
48
49
  findRecurringPaymentsByAgreementId: jest.fn(() => ({ toRetrieveRequest: () => {} })),
49
50
  dynamicsClient: {
50
51
  retrieveMultipleRequest: jest.fn(() => ({ value: [] }))
51
- }
52
+ },
53
+ persist: jest.fn()
52
54
  }))
53
55
 
54
56
  jest.mock('@defra-fish/connectors-lib', () => ({
@@ -870,28 +872,29 @@ describe('recurring payments service', () => {
870
872
 
871
873
  describe('cancelRecurringPayment', () => {
872
874
  it('should call findById with RecurringPayment and the provided id', async () => {
875
+ findById.mockReturnValueOnce(getMockRecurringPayment())
873
876
  const id = 'abc123'
874
877
  await cancelRecurringPayment(id)
875
878
  expect(findById).toHaveBeenCalledWith(RecurringPayment, id)
876
879
  })
877
880
 
878
- it('should log a RecurringPayment record when there is one match', async () => {
879
- const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(jest.fn())
880
- const recurringPayment = { entity: getMockRecurringPayment() }
881
+ it('should call persist with the updated RecurringPayment', async () => {
882
+ const recurringPayment = getMockRecurringPayment()
881
883
  findById.mockReturnValueOnce(recurringPayment)
882
884
 
885
+ const cancelledDate = new Date().toISOString().split('T')[0]
886
+ const cancelledReason = { description: 'Payment Failure', id: 910400002, label: 'Payment Failure' }
887
+ const expectedUpdatedRecurringPayment = { ...recurringPayment, cancelledReason, cancelledDate }
888
+
883
889
  await cancelRecurringPayment('id')
884
890
 
885
- expect(consoleLogSpy).toHaveBeenCalledWith('RecurringPayment for cancellation: ', recurringPayment)
891
+ expect(persist).toHaveBeenCalledWith([expect.objectContaining(expectedUpdatedRecurringPayment)])
886
892
  })
887
893
 
888
- it('should log no matches when there are no matches', async () => {
889
- const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(jest.fn())
894
+ it('should raise an error when there are no matches', async () => {
890
895
  findById.mockReturnValueOnce(undefined)
891
896
 
892
- await cancelRecurringPayment('id')
893
-
894
- expect(consoleLogSpy).toHaveBeenCalledWith('No matches found for cancellation')
897
+ await expect(cancelRecurringPayment('id')).rejects.toThrow('Invalid id provided for recurring payment cancellation')
895
898
  })
896
899
  })
897
900
  })
@@ -1,10 +1,11 @@
1
1
  import {
2
+ dynamicsClient,
2
3
  executeQuery,
3
4
  findById,
4
5
  findDueRecurringPayments,
5
6
  findRecurringPaymentsByAgreementId,
6
- RecurringPayment,
7
- dynamicsClient
7
+ persist,
8
+ RecurringPayment
8
9
  } from '@defra-fish/dynamics-lib'
9
10
  import { calculateEndDate, generatePermissionNumber } from './permissions.service.js'
10
11
  import { getObfuscatedDob } from './contacts.service.js'
@@ -14,6 +15,7 @@ import { TRANSACTION_STAGING_TABLE, TRANSACTION_QUEUE } from '../config.js'
14
15
  import { TRANSACTION_STATUS } from '../services/transactions/constants.js'
15
16
  import { retrieveStagedTransaction } from '../services/transactions/retrieve-transaction.js'
16
17
  import { createPaymentJournal, getPaymentJournal, updatePaymentJournal } from '../services/paymentjournals/payment-journals.service.js'
18
+ import { getGlobalOptionSetValue } from './reference-data.service.js'
17
19
  import moment from 'moment'
18
20
  import { AWS, govUkPayApi } from '@defra-fish/connectors-lib'
19
21
  import db from 'debug'
@@ -165,9 +167,14 @@ export const findNewestExistingRecurringPaymentInCrm = async agreementId => {
165
167
  export const cancelRecurringPayment = async id => {
166
168
  const recurringPayment = await findById(RecurringPayment, id)
167
169
  if (recurringPayment) {
168
- console.log('RecurringPayment for cancellation: ', recurringPayment)
170
+ const data = recurringPayment
171
+ data.cancelledDate = new Date().toISOString().split('T')[0]
172
+ data.cancelledReason = await getGlobalOptionSetValue(RecurringPayment.definition.mappings.cancelledReason.ref, 'Payment Failure')
173
+ const updatedRecurringPayment = Object.assign(new RecurringPayment(), data)
174
+ await persist([updatedRecurringPayment])
175
+ return updatedRecurringPayment
169
176
  } else {
170
- console.log('No matches found for cancellation')
177
+ throw new Error('Invalid id provided for recurring payment cancellation')
171
178
  }
172
179
  }
173
180