@defra-fish/gafl-webapp-service 1.23.0 → 1.24.0-rc.0
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/pages/contact/digital-licence/check-confirmation-contact/__tests__/__snapshots__/check-confirmation-contact.spec.js.snap +2 -2
- package/src/pages/contact/digital-licence/check-confirmation-contact/__tests__/check-confirmation-contact.spec.js +45 -1
- package/src/pages/contact/digital-licence/check-confirmation-contact/check-confirmation-contact.njk +1 -4
- package/src/pages/contact/digital-licence/check-confirmation-contact/route.js +6 -2
- package/src/processors/__tests__/uri-helper.spec.js +27 -0
- package/src/processors/uri-helper.js +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra-fish/gafl-webapp-service",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.0-rc.0",
|
|
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.
|
|
40
|
-
"@defra-fish/connectors-lib": "1.
|
|
39
|
+
"@defra-fish/business-rules-lib": "1.24.0-rc.0",
|
|
40
|
+
"@defra-fish/connectors-lib": "1.24.0-rc.0",
|
|
41
41
|
"@defra/hapi-gapi": "^1.1.0",
|
|
42
42
|
"@hapi/boom": "^9.1.2",
|
|
43
43
|
"@hapi/catbox-redis": "^6.0.2",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"gulp-sourcemaps": "^3.0.0",
|
|
77
77
|
"node-sass": "^6.0.1"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "1076e2f084bbf1e767506b1a1e684f6ad7d3636c"
|
|
80
80
|
}
|
|
@@ -8,8 +8,8 @@ Object {
|
|
|
8
8
|
"preferredMethodOfConfirmation": "email",
|
|
9
9
|
},
|
|
10
10
|
"uri": Object {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
11
|
+
"change": "licence-confirmation-method.url?change=mobile",
|
|
12
|
+
"contact": "contact.url",
|
|
13
13
|
},
|
|
14
14
|
}
|
|
15
15
|
`;
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
import { CONTACT } from '../../../../../uri.js'
|
|
1
|
+
import { CONTACT, LICENCE_CONFIRMATION_METHOD } from '../../../../../uri.js'
|
|
2
2
|
import { HOW_CONTACTED } from '../../../../../processors/mapping-constants.js'
|
|
3
3
|
import { getData } from '../route.js'
|
|
4
4
|
import GetDataRedirect from '../../../../../handlers/get-data-redirect.js'
|
|
5
|
+
import { addLanguageCodeToUri } from '../../../../../processors/uri-helper.js'
|
|
6
|
+
|
|
7
|
+
jest.mock('../../../../../processors/uri-helper.js')
|
|
8
|
+
jest.mock('../../../../../processors/mapping-constants.js', () => ({
|
|
9
|
+
HOW_CONTACTED: {
|
|
10
|
+
none: 'nada',
|
|
11
|
+
email: 'e-mail',
|
|
12
|
+
text: 'mobile-phone'
|
|
13
|
+
}
|
|
14
|
+
}))
|
|
15
|
+
jest.mock('../../../../../uri.js', () => ({
|
|
16
|
+
...jest.requireActual('../../../../../uri.js'),
|
|
17
|
+
CONTACT: { uri: 'contact.url' },
|
|
18
|
+
LICENCE_CONFIRMATION_METHOD: { uri: 'licence-confirmation-method.url' }
|
|
19
|
+
}))
|
|
5
20
|
|
|
6
21
|
describe('.getData', () => {
|
|
7
22
|
const createRequestMock = (options = {}) => ({
|
|
@@ -20,13 +35,42 @@ describe('.getData', () => {
|
|
|
20
35
|
}))
|
|
21
36
|
})
|
|
22
37
|
|
|
38
|
+
beforeEach(jest.resetAllMocks)
|
|
39
|
+
|
|
23
40
|
it('if preferred method of confirmation is none, redirects to contact page', async () => {
|
|
24
41
|
const getDataRedirectError = new GetDataRedirect(CONTACT.uri)
|
|
25
42
|
const func = async () => await getData(createRequestMock({ preferredMethodOfConfirmation: HOW_CONTACTED.none }))
|
|
26
43
|
await expect(func).rejects.toThrow(getDataRedirectError)
|
|
27
44
|
})
|
|
28
45
|
|
|
46
|
+
describe.each([
|
|
47
|
+
{ urlName: 'change', url: `${LICENCE_CONFIRMATION_METHOD.uri}?change=email`, preferredMethodOfConfirmation: HOW_CONTACTED.email },
|
|
48
|
+
{ urlName: 'change', url: `${LICENCE_CONFIRMATION_METHOD.uri}?change=mobile`, preferredMethodOfConfirmation: HOW_CONTACTED.text },
|
|
49
|
+
{ urlName: 'contact', url: CONTACT.uri, preferredMethodOfConfirmation: HOW_CONTACTED.email }
|
|
50
|
+
])('$urlName $confirmation is decorated by addLanguageCodeToUri', ({ urlName, url, preferredMethodOfConfirmation }) => {
|
|
51
|
+
it(`passes request and ${urlName} url to addLanguageCodeToUri`, async () => {
|
|
52
|
+
const request = createRequestMock({ preferredMethodOfConfirmation })
|
|
53
|
+
await getData(request)
|
|
54
|
+
expect(addLanguageCodeToUri).toHaveBeenCalledWith(request, url)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it(`returns decorated value for ${urlName} from addLanguageCodeToUri`, async () => {
|
|
58
|
+
const expectedUrl = Symbol(urlName)
|
|
59
|
+
addLanguageCodeToUri.mockReturnValue(expectedUrl)
|
|
60
|
+
const request = createRequestMock()
|
|
61
|
+
const data = await getData(request)
|
|
62
|
+
expect(data).toEqual(
|
|
63
|
+
expect.objectContaining({
|
|
64
|
+
uri: expect.objectContaining({
|
|
65
|
+
[urlName]: expectedUrl
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
)
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
29
72
|
it('returns the expected data', async () => {
|
|
73
|
+
addLanguageCodeToUri.mockImplementation((_request, uri) => uri)
|
|
30
74
|
expect(await getData(createRequestMock())).toMatchSnapshot()
|
|
31
75
|
})
|
|
32
76
|
})
|
package/src/pages/contact/digital-licence/check-confirmation-contact/check-confirmation-contact.njk
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
{% extends "standard-form.njk" %}
|
|
2
2
|
{% from "back-link/macro.njk" import govukBackLink %}
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
{% if data.licensee.preferredMethodOfConfirmation == 'Email' %}
|
|
6
5
|
{% set contactType = mssgs.email_address %}
|
|
7
6
|
{% set contactInfo = data.licensee.email %}
|
|
8
|
-
{% set changeLinkUrl = data.uri.licenceConfirmationMethod + '?change=email' %}
|
|
9
7
|
{% else %}
|
|
10
8
|
{% set contactType = mssgs.phone_number %}
|
|
11
9
|
{% set contactInfo = data.licensee.mobilePhone %}
|
|
12
|
-
{% set changeLinkUrl = data.uri.licenceConfirmationMethod + '?change=mobile' %}
|
|
13
10
|
{% endif %}
|
|
14
11
|
|
|
15
12
|
{% set title = mssgs.check_conf_contact_title_1 + contactType + mssgs.check_conf_contact_title_2 %}
|
|
@@ -36,7 +33,7 @@
|
|
|
36
33
|
</p>
|
|
37
34
|
|
|
38
35
|
<p class="govuk-body govuk-!-margin-bottom-6">
|
|
39
|
-
<a class="govuk-link" href="{{
|
|
36
|
+
<a class="govuk-link" href="{{ data.uri.change }}">
|
|
40
37
|
{{ mssgs.licence_summary_change }} {{ contactType }}
|
|
41
38
|
</a>
|
|
42
39
|
</p>
|
|
@@ -3,6 +3,7 @@ import { HOW_CONTACTED } from '../../../../processors/mapping-constants.js'
|
|
|
3
3
|
import GetDataRedirect from '../../../../handlers/get-data-redirect.js'
|
|
4
4
|
import pageRoute from '../../../../routes/page-route.js'
|
|
5
5
|
import { nextPage } from '../../../../routes/next-page.js'
|
|
6
|
+
import { addLanguageCodeToUri } from '../../../../processors/uri-helper.js'
|
|
6
7
|
|
|
7
8
|
export const getData = async request => {
|
|
8
9
|
const { licensee } = await request.cache().helpers.transaction.getCurrentPermission()
|
|
@@ -11,11 +12,14 @@ export const getData = async request => {
|
|
|
11
12
|
throw new GetDataRedirect(CONTACT.uri)
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
const whatToChange = licensee.preferredMethodOfConfirmation === HOW_CONTACTED.email ? '?change=email' : '?change=mobile'
|
|
16
|
+
const change = addLanguageCodeToUri(request, `${LICENCE_CONFIRMATION_METHOD.uri}${whatToChange}`)
|
|
17
|
+
|
|
14
18
|
return {
|
|
15
19
|
licensee,
|
|
16
20
|
uri: {
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
contact: addLanguageCodeToUri(request, CONTACT.uri),
|
|
22
|
+
change
|
|
19
23
|
}
|
|
20
24
|
}
|
|
21
25
|
}
|
|
@@ -18,4 +18,31 @@ describe('URI Helpers: addLanguageCodeToURI', () => {
|
|
|
18
18
|
const result = addLanguageCodeToUri(mockRequest, uri)
|
|
19
19
|
expect(result).toEqual(expect.stringMatching(new RegExp(expected)))
|
|
20
20
|
})
|
|
21
|
+
|
|
22
|
+
describe.each([
|
|
23
|
+
['https://my-url.com/path?data=true', 'https://my-url.com/path?data=true&lang=cy'],
|
|
24
|
+
['https://my-url.com/path?data-1=false&data-2=9', 'https://my-url.com/path?data-1=false&data-2=9&lang=cy']
|
|
25
|
+
])('', (urlToDecorate, decoratedUrl) => {
|
|
26
|
+
it('if the supplied url has a querystring already, the language parameter is added to the end with an ampersand', () => {
|
|
27
|
+
const mockRequest = {
|
|
28
|
+
path: '/any/page',
|
|
29
|
+
url: {
|
|
30
|
+
search: '?lang=cy'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const result = addLanguageCodeToUri(mockRequest, urlToDecorate)
|
|
34
|
+
expect(result).toEqual(decoratedUrl)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('if the request.path is used instead of a url and has a querystring, the language parameter is added to the end with an ampersand', () => {
|
|
38
|
+
const mockRequest = {
|
|
39
|
+
path: urlToDecorate,
|
|
40
|
+
url: {
|
|
41
|
+
search: '?lang=cy'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const result = addLanguageCodeToUri(mockRequest, urlToDecorate)
|
|
45
|
+
expect(result).toEqual(decoratedUrl)
|
|
46
|
+
})
|
|
47
|
+
})
|
|
21
48
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const addLanguageCodeToUri = (request, uri) => {
|
|
2
2
|
const path = uri || request.path
|
|
3
|
-
|
|
3
|
+
const languageSpecifier = /.*\?.*/.test(path) ? '&lang=cy' : '?lang=cy'
|
|
4
|
+
return `${path}${/\?.*lang=cy.*$/.test(request.url.search) ? languageSpecifier : ''}`
|
|
4
5
|
}
|