@defra-fish/dynamics-lib 1.76.0-rc.5 → 1.77.0-rc.1
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.
|
|
3
|
+
"version": "1.77.0-rc.1",
|
|
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": "2d2758c633c72fb22cd69fd5c9cbf0046568a9a9"
|
|
47
47
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { contactAndPermissionForLicensee, contactForLicenseeNoReference } from '../contact.queries.js'
|
|
1
|
+
import { contactAndPermissionForLicensee, contactForLicenseeNoReference, contactForLicenseeByPersonalDetails } from '../contact.queries.js'
|
|
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'
|
|
@@ -18,12 +18,14 @@ describe('Contact Queries', () => {
|
|
|
18
18
|
beforeEach(() => {
|
|
19
19
|
jest.resetAllMocks()
|
|
20
20
|
|
|
21
|
+
const defaultFilter = 'statecode eq 77'
|
|
22
|
+
|
|
21
23
|
jest.spyOn(Contact.definition, 'mappings', 'get').mockReturnValue({
|
|
22
24
|
postcode: { field: 'mock_postcode' },
|
|
23
25
|
birthDate: { field: 'mock_birthdate' }
|
|
24
26
|
})
|
|
25
27
|
|
|
26
|
-
jest.spyOn(Contact.definition, 'defaultFilter', 'get').mockReturnValue(
|
|
28
|
+
jest.spyOn(Contact.definition, 'defaultFilter', 'get').mockReturnValue(defaultFilter)
|
|
27
29
|
})
|
|
28
30
|
|
|
29
31
|
it('should return a predefined query', () => {
|
|
@@ -36,14 +38,6 @@ describe('Contact Queries', () => {
|
|
|
36
38
|
expect(result._root).toEqual(Contact)
|
|
37
39
|
})
|
|
38
40
|
|
|
39
|
-
it('should use mocked values for mapping postcode and birth date', () => {
|
|
40
|
-
const result = contactForLicenseeNoReference('03/12/1990', 'AB12 3CD')
|
|
41
|
-
expect(result._retrieveRequest.filter).toEqual(
|
|
42
|
-
expect.stringContaining(Contact.definition.mappings.postcode.field),
|
|
43
|
-
expect.stringContaining(Contact.definition.mappings.birthDate.field)
|
|
44
|
-
)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
41
|
it.each([
|
|
48
42
|
['AB12 3CD', '03/12/1990'],
|
|
49
43
|
['EF45 6GH', '05/06/1987'],
|
|
@@ -54,7 +48,7 @@ describe('Contact Queries', () => {
|
|
|
54
48
|
expect(result._retrieveRequest).toEqual({
|
|
55
49
|
collection: 'contacts',
|
|
56
50
|
expand: [],
|
|
57
|
-
filter: `mock_postcode eq '${postcode}' and mock_birthdate eq ${birthDate} and
|
|
51
|
+
filter: `mock_postcode eq '${postcode}' and mock_birthdate eq ${birthDate} and ${Contact.definition.defaultFilter}`,
|
|
58
52
|
select: expect.any(Array)
|
|
59
53
|
})
|
|
60
54
|
})
|
|
@@ -64,10 +58,13 @@ describe('Contact Queries', () => {
|
|
|
64
58
|
beforeEach(() => {
|
|
65
59
|
jest.resetAllMocks()
|
|
66
60
|
|
|
61
|
+
const defaultFilter = 'statecode eq 77'
|
|
62
|
+
|
|
67
63
|
jest.spyOn(Contact.definition, 'mappings', 'get').mockReturnValue({
|
|
68
64
|
id: { field: 'contactid' },
|
|
69
65
|
postcode: { field: 'defra_postcode' }
|
|
70
66
|
})
|
|
67
|
+
jest.spyOn(Permission.definition, 'defaultFilter', 'get').mockReturnValue(defaultFilter)
|
|
71
68
|
})
|
|
72
69
|
|
|
73
70
|
it('should return a predefined query', () => {
|
|
@@ -84,7 +81,7 @@ describe('Contact Queries', () => {
|
|
|
84
81
|
const result = contactAndPermissionForLicensee('ABC123', 'AB12 3CD')
|
|
85
82
|
|
|
86
83
|
expect(result._retrieveRequest.filter).toEqual(
|
|
87
|
-
|
|
84
|
+
`endswith(defra_name, 'ABC123') and ${Permission.definition.defaultFilter} and defra_ContactId/defra_postcode eq 'AB12 3CD'`
|
|
88
85
|
)
|
|
89
86
|
})
|
|
90
87
|
|
|
@@ -116,7 +113,7 @@ describe('Contact Queries', () => {
|
|
|
116
113
|
|
|
117
114
|
expect(result._retrieveRequest).toEqual({
|
|
118
115
|
collection: 'defra_permissions',
|
|
119
|
-
filter: `endswith(defra_name, '${permissionLast6}') and
|
|
116
|
+
filter: `endswith(defra_name, '${permissionLast6}') and ${Permission.definition.defaultFilter} and defra_ContactId/defra_postcode eq '${postcode}'`,
|
|
120
117
|
orderBy: ['defra_issuedate desc', 'defra_ContactId/contactid asc'],
|
|
121
118
|
expand: [
|
|
122
119
|
{
|
|
@@ -141,3 +138,56 @@ describe('Contact Queries', () => {
|
|
|
141
138
|
)
|
|
142
139
|
})
|
|
143
140
|
})
|
|
141
|
+
|
|
142
|
+
describe('contactForLicenseeByPersonalDetails', () => {
|
|
143
|
+
beforeEach(() => {
|
|
144
|
+
const defaultFilter = 'statecode eq 77'
|
|
145
|
+
|
|
146
|
+
jest.spyOn(Contact.definition, 'mappings', 'get').mockReturnValue({
|
|
147
|
+
firstName: { field: 'mock_firstname' },
|
|
148
|
+
lastName: { field: 'mock_lastname' },
|
|
149
|
+
postcode: { field: 'mock_postcode' },
|
|
150
|
+
birthDate: { field: 'mock_birthdate' }
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
jest.spyOn(Contact.definition, 'defaultFilter', 'get').mockReturnValue(defaultFilter)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it.each([
|
|
157
|
+
['Smeagol', 'Ring', '2000-10-03', 'AB12 3CD'],
|
|
158
|
+
['Frodo', 'Baggins', '1993-09-22', 'EF45 6GH'],
|
|
159
|
+
['Samwise', 'Gamgee', '1998-03-06', 'IJ78 9KL']
|
|
160
|
+
])(
|
|
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({ licenseeFirstName, licenseeLastName, licenseeBirthDate, licenseePostcode })
|
|
164
|
+
|
|
165
|
+
expect(result._retrieveRequest).toEqual({
|
|
166
|
+
collection: 'contacts',
|
|
167
|
+
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}`,
|
|
169
|
+
select: expect.any(Array)
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
it('should return a predefined query', () => {
|
|
175
|
+
const result = contactForLicenseeByPersonalDetails({
|
|
176
|
+
licenseeFirstName: 'Gandalf',
|
|
177
|
+
licenseeLastName: 'Grey',
|
|
178
|
+
licenseeBirthDate: '1960-10-03',
|
|
179
|
+
licenseePostcode: 'AB12 3CD'
|
|
180
|
+
})
|
|
181
|
+
expect(result).toBeInstanceOf(PredefinedQuery)
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
it('root should return Contact', () => {
|
|
185
|
+
const result = contactForLicenseeByPersonalDetails({
|
|
186
|
+
licenseeFirstName: 'Aragorn',
|
|
187
|
+
licenseeLastName: 'Elessar',
|
|
188
|
+
licenseeBirthDate: '1989-04-20',
|
|
189
|
+
licenseePostcode: 'AB12 3CD'
|
|
190
|
+
})
|
|
191
|
+
expect(result._root).toEqual(Contact)
|
|
192
|
+
})
|
|
193
|
+
})
|
|
@@ -48,3 +48,26 @@ export const contactAndPermissionForLicensee = (permissionLast6Characters, licen
|
|
|
48
48
|
|
|
49
49
|
return query
|
|
50
50
|
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Gets the query to find a contact using their name, postcode and date of birth
|
|
54
|
+
*
|
|
55
|
+
* @param {string} licenseeFirstName
|
|
56
|
+
* @param {string} licenseeLastName
|
|
57
|
+
* @param {string} licenseeBirthDate
|
|
58
|
+
* @param {string} licenseePostcode
|
|
59
|
+
* @returns {PredefinedQuery<Contact>}
|
|
60
|
+
*/
|
|
61
|
+
export const contactForLicenseeByPersonalDetails = ({ licenseeFirstName, licenseeLastName, licenseeBirthDate, licenseePostcode }) => {
|
|
62
|
+
const { firstName, lastName, postcode, birthDate } = Contact.definition.mappings
|
|
63
|
+
const filter = `${firstName.field} eq '${escapeODataStringValue(licenseeFirstName)}' and ${lastName.field} eq '${escapeODataStringValue(
|
|
64
|
+
licenseeLastName
|
|
65
|
+
)}' and ${postcode.field} eq '${escapeODataStringValue(licenseePostcode)}' and ${birthDate.field} eq ${licenseeBirthDate} and ${
|
|
66
|
+
Contact.definition.defaultFilter
|
|
67
|
+
}`
|
|
68
|
+
return new PredefinedQuery({
|
|
69
|
+
root: Contact,
|
|
70
|
+
filter,
|
|
71
|
+
expand: []
|
|
72
|
+
})
|
|
73
|
+
}
|