@defra-fish/dynamics-lib 1.77.0-rc.2 → 1.77.0-rc.3
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/dynamics-lib",
|
|
3
|
-
"version": "1.77.0-rc.
|
|
3
|
+
"version": "1.77.0-rc.3",
|
|
4
4
|
"description": "Framework to support integration with dynamics",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"simple-oauth2": "4.3.0",
|
|
44
44
|
"uuid": "8.3.2"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "fa97e97564ae1c2a49ffb2671f690f4328205942"
|
|
47
47
|
}
|
|
@@ -2,6 +2,7 @@ import { contactAndPermissionForLicensee, contactForLicenseeNoReference, contact
|
|
|
2
2
|
import { Contact } from '../../entities/contact.entity.js'
|
|
3
3
|
import { Permission } from '../../entities/permission.entity.js'
|
|
4
4
|
import { PredefinedQuery } from '../predefined-query.js'
|
|
5
|
+
import { escapeODataStringValue } from '../../client/util.js'
|
|
5
6
|
|
|
6
7
|
jest.mock('dynamics-web-api', () => {
|
|
7
8
|
return {
|
|
@@ -13,11 +14,13 @@ jest.mock('dynamics-web-api', () => {
|
|
|
13
14
|
}
|
|
14
15
|
})
|
|
15
16
|
|
|
17
|
+
jest.mock('../../client/util.js', () => ({
|
|
18
|
+
escapeODataStringValue: jest.fn(value => value)
|
|
19
|
+
}))
|
|
20
|
+
|
|
16
21
|
describe('Contact Queries', () => {
|
|
17
22
|
describe('contactForLicenseeNoReference', () => {
|
|
18
23
|
beforeEach(() => {
|
|
19
|
-
jest.resetAllMocks()
|
|
20
|
-
|
|
21
24
|
const defaultFilter = 'statecode eq 77'
|
|
22
25
|
|
|
23
26
|
jest.spyOn(Contact.definition, 'mappings', 'get').mockReturnValue({
|
|
@@ -56,8 +59,6 @@ describe('Contact Queries', () => {
|
|
|
56
59
|
|
|
57
60
|
describe('contactAndPermissionForLicensee', () => {
|
|
58
61
|
beforeEach(() => {
|
|
59
|
-
jest.resetAllMocks()
|
|
60
|
-
|
|
61
62
|
const defaultFilter = 'statecode eq 77'
|
|
62
63
|
|
|
63
64
|
jest.spyOn(Contact.definition, 'mappings', 'get').mockReturnValue({
|
|
@@ -146,6 +147,7 @@ describe('contactForLicenseeByPersonalDetails', () => {
|
|
|
146
147
|
jest.spyOn(Contact.definition, 'mappings', 'get').mockReturnValue({
|
|
147
148
|
firstName: { field: 'mock_firstname' },
|
|
148
149
|
lastName: { field: 'mock_lastname' },
|
|
150
|
+
premises: { field: 'mock_premises' },
|
|
149
151
|
postcode: { field: 'mock_postcode' },
|
|
150
152
|
birthDate: { field: 'mock_birthdate' }
|
|
151
153
|
})
|
|
@@ -154,18 +156,45 @@ describe('contactForLicenseeByPersonalDetails', () => {
|
|
|
154
156
|
})
|
|
155
157
|
|
|
156
158
|
it.each([
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
159
|
+
{ details: { licenseeFirstName: 'Brenin' }, testfield: 'first name', fieldName: 'licenseeFirstName' },
|
|
160
|
+
{ details: { licenseeLastName: 'Pysgotwr' }, testfield: 'last name', fieldName: 'licenseeLastName' },
|
|
161
|
+
{ details: { licenseePremises: 'Dunmanifestin' }, testfield: 'premises', fieldName: 'licenseePremises' },
|
|
162
|
+
{ details: { licenseePostcode: 'GZ1 1UH' }, testfield: 'post code', fieldName: 'licenseePostcode' }
|
|
163
|
+
])('escapes value of $testfield', ({ testfield: _t, details, fieldName }) => {
|
|
164
|
+
for (let x = 0; x < 4; x++) {
|
|
165
|
+
escapeODataStringValue.mockImplementationOnce(value => `!@£${value}$%%`)
|
|
166
|
+
}
|
|
167
|
+
const query = contactForLicenseeByPersonalDetails({
|
|
168
|
+
licenseeFirstName: 'firstName',
|
|
169
|
+
licenseeLastName: 'lastName',
|
|
170
|
+
licenseePremises: '15',
|
|
171
|
+
licenseePostcode: 'AB1 1AB',
|
|
172
|
+
licenseeBirthDate: '2000-01-01',
|
|
173
|
+
...details
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
expect(query._retrieveRequest.filter).toEqual(expect.stringContaining(`!@£${details[fieldName]}$%%`))
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
it.each([
|
|
180
|
+
['Smeagol', 'Ring', '2000-10-03', '12', 'AB12 3CD'],
|
|
181
|
+
['Frodo', 'Baggins', '1993-09-22', 'Dunmanifestin', 'EF45 6GH'],
|
|
182
|
+
['Samwise', 'Gamgee', '1998-03-06', '1507', 'IJ78 9KL']
|
|
160
183
|
])(
|
|
161
|
-
'should return correct retrieve request when first name is %s, last name is %s, birth date is %s and postcode is %s',
|
|
162
|
-
(licenseeFirstName, licenseeLastName, licenseeBirthDate, licenseePostcode) => {
|
|
163
|
-
const result = contactForLicenseeByPersonalDetails({
|
|
184
|
+
'should return correct retrieve request when first name is %s, last name is %s, birth date is %s, premises is %s and postcode is %s',
|
|
185
|
+
(licenseeFirstName, licenseeLastName, licenseeBirthDate, licenseePremises, licenseePostcode) => {
|
|
186
|
+
const result = contactForLicenseeByPersonalDetails({
|
|
187
|
+
licenseeFirstName,
|
|
188
|
+
licenseeLastName,
|
|
189
|
+
licenseeBirthDate,
|
|
190
|
+
licenseePremises,
|
|
191
|
+
licenseePostcode
|
|
192
|
+
})
|
|
164
193
|
|
|
165
194
|
expect(result._retrieveRequest).toEqual({
|
|
166
195
|
collection: 'contacts',
|
|
167
196
|
expand: [],
|
|
168
|
-
filter: `mock_firstname eq '${licenseeFirstName}' and mock_lastname eq '${licenseeLastName}' and mock_postcode eq '${licenseePostcode}' and mock_birthdate eq ${licenseeBirthDate} and ${Contact.definition.defaultFilter}`,
|
|
197
|
+
filter: `mock_firstname eq '${licenseeFirstName}' and mock_lastname eq '${licenseeLastName}' and mock_premises eq '${licenseePremises}' and mock_postcode eq '${licenseePostcode}' and mock_birthdate eq ${licenseeBirthDate} and ${Contact.definition.defaultFilter}`,
|
|
169
198
|
select: expect.any(Array)
|
|
170
199
|
})
|
|
171
200
|
}
|
|
@@ -55,16 +55,23 @@ export const contactAndPermissionForLicensee = (permissionLast6Characters, licen
|
|
|
55
55
|
* @param {string} licenseeFirstName
|
|
56
56
|
* @param {string} licenseeLastName
|
|
57
57
|
* @param {string} licenseeBirthDate
|
|
58
|
+
* @param {string} licenseePremises
|
|
58
59
|
* @param {string} licenseePostcode
|
|
59
60
|
* @returns {PredefinedQuery<Contact>}
|
|
60
61
|
*/
|
|
61
|
-
export const contactForLicenseeByPersonalDetails = ({
|
|
62
|
-
|
|
62
|
+
export const contactForLicenseeByPersonalDetails = ({
|
|
63
|
+
licenseeFirstName,
|
|
64
|
+
licenseeLastName,
|
|
65
|
+
licenseeBirthDate,
|
|
66
|
+
licenseePremises,
|
|
67
|
+
licenseePostcode
|
|
68
|
+
}) => {
|
|
69
|
+
const { firstName, lastName, premises, postcode, birthDate } = Contact.definition.mappings
|
|
63
70
|
const filter = `${firstName.field} eq '${escapeODataStringValue(licenseeFirstName)}' and ${lastName.field} eq '${escapeODataStringValue(
|
|
64
71
|
licenseeLastName
|
|
65
|
-
)}' and ${
|
|
66
|
-
|
|
67
|
-
}`
|
|
72
|
+
)}' and ${premises.field} eq '${escapeODataStringValue(licenseePremises)}' and ${postcode.field} eq '${escapeODataStringValue(
|
|
73
|
+
licenseePostcode
|
|
74
|
+
)}' and ${birthDate.field} eq ${licenseeBirthDate} and ${Contact.definition.defaultFilter}`
|
|
68
75
|
return new PredefinedQuery({
|
|
69
76
|
root: Contact,
|
|
70
77
|
filter,
|