@defra-fish/gafl-webapp-service 1.64.0-rc.20 → 1.64.0-rc.21
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 +4 -4
- package/src/handlers/__tests__/{cancel-rp-authentication-handler.spec.js → cancel-recurring-payment-authentication-handler.spec.js} +27 -20
- package/src/handlers/{cancel-rp-authentication-handler.js → cancel-recurring-payment-authentication-handler.js} +6 -8
- package/src/pages/recurring-payments/cancel/identify/__tests__/route.spec.js +2 -2
- package/src/pages/recurring-payments/cancel/identify/route.js +2 -2
- package/src/processors/__tests__/recurring-payments-write-cache.spec.js +121 -0
- package/src/processors/recurring-payments-write-cache.js +16 -0
- package/src/routes/misc-routes.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra-fish/gafl-webapp-service",
|
|
3
|
-
"version": "1.64.0-rc.
|
|
3
|
+
"version": "1.64.0-rc.21",
|
|
4
4
|
"description": "The websales frontend for the GAFL service",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"prepare": "gulp --gulpfile build/gulpfile.cjs"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@defra-fish/business-rules-lib": "1.64.0-rc.
|
|
40
|
-
"@defra-fish/connectors-lib": "1.64.0-rc.
|
|
39
|
+
"@defra-fish/business-rules-lib": "1.64.0-rc.21",
|
|
40
|
+
"@defra-fish/connectors-lib": "1.64.0-rc.21",
|
|
41
41
|
"@defra/hapi-gapi": "2.0.0",
|
|
42
42
|
"@hapi/boom": "9.1.2",
|
|
43
43
|
"@hapi/catbox-redis": "6.0.2",
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"./gafl-jest-matchers.js"
|
|
80
80
|
]
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "d93d2a58352234a4f929a566809b338516ebeb1c"
|
|
83
83
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import handler from '../cancel-
|
|
1
|
+
import handler from '../cancel-recurring-payment-authentication-handler'
|
|
2
2
|
import { CANCEL_RP_IDENTIFY, CANCEL_RP_DETAILS } from '../../uri.js'
|
|
3
3
|
import { addLanguageCodeToUri } from '../../processors/uri-helper.js'
|
|
4
4
|
import { salesApi } from '@defra-fish/connectors-lib'
|
|
@@ -21,28 +21,35 @@ jest.mock('../../uri.js', () => ({
|
|
|
21
21
|
CANCEL_RP_IDENTIFY: { page: 'cancel-rp-identify page', uri: Symbol('cancel-rp-identify-uri') },
|
|
22
22
|
CANCEL_RP_DETAILS: { uri: Symbol('cancel-rp-details-uri') }
|
|
23
23
|
}))
|
|
24
|
+
jest.mock('../../processors/recurring-payments-write-cache.js')
|
|
24
25
|
|
|
25
26
|
const getSampleRequest = (payloadOverride = {}) => {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
const getCurrentPermission = jest.fn(async () => ({}))
|
|
28
|
+
const setCurrentPermission = jest.fn()
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
cache: () => ({
|
|
32
|
+
helpers: {
|
|
33
|
+
page: {
|
|
34
|
+
getCurrentPermission: jest.fn(async () => ({
|
|
35
|
+
payload: {
|
|
36
|
+
referenceNumber: 'ABC123',
|
|
37
|
+
'date-of-birth-day': '01',
|
|
38
|
+
'date-of-birth-month': '01',
|
|
39
|
+
'date-of-birth-year': '1970',
|
|
40
|
+
postcode: 'AA1 1AA',
|
|
41
|
+
...payloadOverride
|
|
42
|
+
}
|
|
43
|
+
})),
|
|
44
|
+
setCurrentPermission
|
|
45
|
+
},
|
|
46
|
+
status: {
|
|
47
|
+
getCurrentPermission,
|
|
48
|
+
setCurrentPermission
|
|
49
|
+
}
|
|
35
50
|
}
|
|
36
|
-
})
|
|
37
|
-
setCurrentPermission: jest.fn()
|
|
38
|
-
}
|
|
39
|
-
const status = {
|
|
40
|
-
getCurrentPermission: jest.fn().mockResolvedValue({}),
|
|
41
|
-
setCurrentPermission: jest.fn()
|
|
51
|
+
})
|
|
42
52
|
}
|
|
43
|
-
const helpers = { page, status }
|
|
44
|
-
const cache = () => ({ helpers })
|
|
45
|
-
return { cache }
|
|
46
53
|
}
|
|
47
54
|
|
|
48
55
|
const getSampleResponseTooklkit = () => ({
|
|
@@ -197,7 +204,7 @@ describe('Cancel RP Authentication Handler', () => {
|
|
|
197
204
|
recurringPayment: { id: 'rcp-id', status: 0, cancelledDate: null }
|
|
198
205
|
})
|
|
199
206
|
const request = getSampleRequest({ referenceNumber: undefined })
|
|
200
|
-
request.cache().helpers.status.getCurrentPermission.
|
|
207
|
+
request.cache().helpers.status.getCurrentPermission.mockReturnValueOnce({
|
|
201
208
|
referenceNumber: 'A1B2C3'
|
|
202
209
|
})
|
|
203
210
|
const h = getSampleResponseTooklkit()
|
|
@@ -2,7 +2,7 @@ import { CANCEL_RP_IDENTIFY, CANCEL_RP_DETAILS } from '../../src/uri.js'
|
|
|
2
2
|
import { addLanguageCodeToUri } from '../processors/uri-helper.js'
|
|
3
3
|
import { salesApi } from '@defra-fish/connectors-lib'
|
|
4
4
|
import { validation } from '@defra-fish/business-rules-lib'
|
|
5
|
-
import {
|
|
5
|
+
import { setupCancelRecurringPaymentCacheFromAuthResult } from '../processors/recurring-payments-write-cache.js'
|
|
6
6
|
import Joi from 'joi'
|
|
7
7
|
|
|
8
8
|
const buildAuthFailure = (referenceNumber, payload, error) => ({
|
|
@@ -23,7 +23,7 @@ const applyAuthFailure = async (request, h, failure) => {
|
|
|
23
23
|
return h.redirect(addLanguageCodeToUri(request, failure.redirectPath))
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const cancelRecurringPaymentAuthenticationHandler = async (request, h) => {
|
|
27
27
|
const { payload } = await request.cache().helpers.page.getCurrentPermission(CANCEL_RP_IDENTIFY.page)
|
|
28
28
|
const permission = await request.cache().helpers.status.getCurrentPermission()
|
|
29
29
|
|
|
@@ -41,17 +41,15 @@ const cancelRpAuthenticationHandler = async (request, h) => {
|
|
|
41
41
|
if (!authenticationResult) {
|
|
42
42
|
return failures({ referenceNumber: 'not-found' })
|
|
43
43
|
}
|
|
44
|
-
|
|
45
44
|
if (!authenticationResult.recurringPayment) {
|
|
46
45
|
return failures({ recurringPayment: 'not-set-up' })
|
|
47
46
|
}
|
|
48
|
-
|
|
49
|
-
if (authenticationResult.recurringPayment?.status === 1 || authenticationResult.recurringPayment?.cancelledDate) {
|
|
47
|
+
if (authenticationResult.recurringPayment.cancelledDate) {
|
|
50
48
|
return failures({ recurringPayment: 'rcp-cancelled' })
|
|
51
49
|
}
|
|
52
50
|
|
|
53
|
-
await
|
|
54
|
-
|
|
51
|
+
await setupCancelRecurringPaymentCacheFromAuthResult(request, authenticationResult)
|
|
52
|
+
|
|
55
53
|
await request.cache().helpers.status.setCurrentPermission({
|
|
56
54
|
authentication: { authorised: true }
|
|
57
55
|
})
|
|
@@ -59,4 +57,4 @@ const cancelRpAuthenticationHandler = async (request, h) => {
|
|
|
59
57
|
return h.redirectWithLanguageCode(CANCEL_RP_DETAILS.uri)
|
|
60
58
|
}
|
|
61
59
|
|
|
62
|
-
export default
|
|
60
|
+
export default cancelRecurringPaymentAuthenticationHandler
|
|
@@ -26,7 +26,7 @@ describe('cancel recurring payment identify route', () => {
|
|
|
26
26
|
const getMockRequest = (referenceNumber, pageGet = async () => ({})) => ({
|
|
27
27
|
cache: () => ({
|
|
28
28
|
helpers: {
|
|
29
|
-
|
|
29
|
+
transaction: {
|
|
30
30
|
getCurrentPermission: () => ({
|
|
31
31
|
referenceNumber
|
|
32
32
|
}),
|
|
@@ -59,7 +59,7 @@ describe('cancel recurring payment identify route', () => {
|
|
|
59
59
|
.spyOn(validation.permission, 'permissionNumberUniqueComponentValidator')
|
|
60
60
|
.mockReturnValue({ validate: () => ({ error: true }) })
|
|
61
61
|
const request = getMockRequest('BAD123')
|
|
62
|
-
request.cache().helpers.
|
|
62
|
+
request.cache().helpers.transaction.setCurrentPermission = jest.fn()
|
|
63
63
|
await expect(getData(request)).rejects.toBeInstanceOf(GetDataRedirect)
|
|
64
64
|
spy.mockRestore()
|
|
65
65
|
})
|
|
@@ -7,7 +7,7 @@ import GetDataRedirect from '../../../../handlers/get-data-redirect.js'
|
|
|
7
7
|
import { dateOfBirthValidator, getDateErrorFlags } from '../../../../schema/validators/validators.js'
|
|
8
8
|
|
|
9
9
|
export const getData = async request => {
|
|
10
|
-
const permission = await request.cache().helpers.
|
|
10
|
+
const permission = await request.cache().helpers.transaction.getCurrentPermission()
|
|
11
11
|
const page = await request.cache().helpers.page.getCurrentPermission(CANCEL_RP_IDENTIFY.page)
|
|
12
12
|
|
|
13
13
|
if (permission.referenceNumber) {
|
|
@@ -15,7 +15,7 @@ export const getData = async request => {
|
|
|
15
15
|
.permissionNumberUniqueComponentValidator(Joi)
|
|
16
16
|
.validate(permission.referenceNumber)
|
|
17
17
|
if (validatePermissionNumber.error) {
|
|
18
|
-
await request.cache().helpers.
|
|
18
|
+
await request.cache().helpers.transaction.setCurrentPermission({ referenceNumber: null })
|
|
19
19
|
throw new GetDataRedirect(addLanguageCodeToUri(request, CANCEL_RP_IDENTIFY.uri))
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { setupCancelRecurringPaymentCacheFromAuthResult } from '../recurring-payments-write-cache.js'
|
|
2
|
+
|
|
3
|
+
describe('setUpCancelRecurringPaymentCacheFromAuthenticationResult', () => {
|
|
4
|
+
const getSampleAuthResult = overrides => {
|
|
5
|
+
const defaults = {
|
|
6
|
+
referenceNumber: '23270624-2WC3FSD-ABNCY4',
|
|
7
|
+
endDate: '2024-12-31',
|
|
8
|
+
licensee: { firstName: 'Brenin', lastName: 'Pysgotwr' },
|
|
9
|
+
permit: { description: 'Coarse 6 month 15 Rod Licence (Half)' },
|
|
10
|
+
recurringPayment: { lastDigitsCardNumbers: '5678' }
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
permission: {
|
|
15
|
+
referenceNumber: overrides.referenceNumber || defaults.referenceNumber,
|
|
16
|
+
endDate: overrides.endDate || defaults.endDate,
|
|
17
|
+
licensee: {
|
|
18
|
+
...defaults.licensee,
|
|
19
|
+
...(overrides.licensee ? overrides.licensee : {})
|
|
20
|
+
},
|
|
21
|
+
permit: {
|
|
22
|
+
...defaults.permit,
|
|
23
|
+
...(overrides.permit ? overrides.permit : {})
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
recurringPayment: {
|
|
27
|
+
...defaults.recurringPayment,
|
|
28
|
+
...(overrides.recurringPayment ? overrides.recurringPayment : {})
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const getSampleRequest = setCurrentPermission => ({
|
|
34
|
+
cache: () => ({
|
|
35
|
+
helpers: {
|
|
36
|
+
transaction: {
|
|
37
|
+
setCurrentPermission
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
describe('permission caching', () => {
|
|
44
|
+
it.each([
|
|
45
|
+
['referenceNumber', '23270624-2WC3FSD-ABNCY4'],
|
|
46
|
+
['endDate', '2024-12-31'],
|
|
47
|
+
['licensee', { firstName: 'John', lastName: 'Bull' }],
|
|
48
|
+
['permit', { description: 'Coarse 12 month 2 Rod Licence (Full)' }]
|
|
49
|
+
])("Adds permission %s, value '%s', to transaction cache", async (fieldName, fieldValue) => {
|
|
50
|
+
const setCurrentPermission = jest.fn()
|
|
51
|
+
const mockRequest = getSampleRequest(setCurrentPermission)
|
|
52
|
+
const authResult = getSampleAuthResult({ [fieldName]: fieldValue })
|
|
53
|
+
|
|
54
|
+
await setupCancelRecurringPaymentCacheFromAuthResult(mockRequest, authResult)
|
|
55
|
+
|
|
56
|
+
expect(setCurrentPermission).toHaveBeenCalledWith(
|
|
57
|
+
expect.objectContaining({
|
|
58
|
+
permission: expect.objectContaining({
|
|
59
|
+
[fieldName]: fieldValue
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it.each([
|
|
66
|
+
['licensee', { anotherProperty: 'Should not be there' }],
|
|
67
|
+
['permit', { altProp: 'Should not be here' }]
|
|
68
|
+
])('Omits extraneous properties from permission %s', async (fieldName, fieldValue) => {
|
|
69
|
+
const setCurrentPermission = jest.fn()
|
|
70
|
+
const mockRequest = getSampleRequest(setCurrentPermission)
|
|
71
|
+
|
|
72
|
+
const authResult = getSampleAuthResult({ [fieldName]: fieldValue })
|
|
73
|
+
|
|
74
|
+
await setupCancelRecurringPaymentCacheFromAuthResult(mockRequest, authResult)
|
|
75
|
+
|
|
76
|
+
expect(setCurrentPermission).toHaveBeenCalledWith(
|
|
77
|
+
expect.objectContaining({
|
|
78
|
+
permission: expect.not.objectContaining({
|
|
79
|
+
[fieldName]: fieldValue
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
)
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
describe('recurring payment caching', () => {
|
|
87
|
+
it('adds recurring payment payment card number last digits to transaction cache', async () => {
|
|
88
|
+
const setCurrentPermission = jest.fn()
|
|
89
|
+
const mockRequest = getSampleRequest(setCurrentPermission)
|
|
90
|
+
|
|
91
|
+
const authResult = getSampleAuthResult({ recurringPayment: { lastDigitsCardNumbers: '1234' } })
|
|
92
|
+
|
|
93
|
+
await setupCancelRecurringPaymentCacheFromAuthResult(mockRequest, authResult)
|
|
94
|
+
|
|
95
|
+
expect(setCurrentPermission).toHaveBeenCalledWith(
|
|
96
|
+
expect.objectContaining({
|
|
97
|
+
recurringPayment: expect.objectContaining({
|
|
98
|
+
lastDigitsCardNumbers: '1234'
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('omits extraneous properties from recurring payment', async () => {
|
|
105
|
+
const setCurrentPermission = jest.fn()
|
|
106
|
+
const mockRequest = getSampleRequest(setCurrentPermission)
|
|
107
|
+
|
|
108
|
+
const authResult = getSampleAuthResult({ recurringPayment: { someOtherProp: 'Should not be here' } })
|
|
109
|
+
|
|
110
|
+
await setupCancelRecurringPaymentCacheFromAuthResult(mockRequest, authResult)
|
|
111
|
+
|
|
112
|
+
expect(setCurrentPermission).toHaveBeenCalledWith(
|
|
113
|
+
expect.objectContaining({
|
|
114
|
+
recurringPayment: expect.not.objectContaining({
|
|
115
|
+
someOtherProp: 'Should not be here'
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
)
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const setupCancelRecurringPaymentCacheFromAuthResult = async (request, authenticationResult) => {
|
|
2
|
+
const { permission, recurringPayment } = authenticationResult
|
|
3
|
+
const { referenceNumber, endDate, licensee, permit } = permission
|
|
4
|
+
|
|
5
|
+
await request.cache().helpers.transaction.setCurrentPermission({
|
|
6
|
+
permission: {
|
|
7
|
+
referenceNumber,
|
|
8
|
+
endDate,
|
|
9
|
+
licensee: { firstName: licensee.firstName, lastName: licensee.lastName },
|
|
10
|
+
permit: { description: permit.description }
|
|
11
|
+
},
|
|
12
|
+
recurringPayment: {
|
|
13
|
+
lastDigitsCardNumbers: recurringPayment.lastDigitsCardNumbers
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
}
|
|
@@ -33,7 +33,7 @@ import authenticationHandler from '../handlers/authentication-handler.js'
|
|
|
33
33
|
import { addLanguageCodeToUri } from '../processors/uri-helper.js'
|
|
34
34
|
import analytics, { checkAnalyticsCookiesPage } from '../handlers/analytics-handler.js'
|
|
35
35
|
import { welshEnabledAndApplied } from '../processors/page-language-helper.js'
|
|
36
|
-
import cancelRPAuthenticationhander from '../handlers/cancel-
|
|
36
|
+
import cancelRPAuthenticationhander from '../handlers/cancel-recurring-payment-authentication-handler.js'
|
|
37
37
|
|
|
38
38
|
const gtmContainerIdOrNull = () => process.env.GTM_CONTAINER_ID || false
|
|
39
39
|
|