cozy-client 34.4.0 → 34.5.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/dist/CozyClient.js +1 -1
- package/dist/models/paper.js +23 -20
- package/dist/models/paper.spec.js +125 -28
- package/package.json +2 -2
package/dist/CozyClient.js
CHANGED
|
@@ -2644,7 +2644,7 @@ var CozyClient = /*#__PURE__*/function () {
|
|
|
2644
2644
|
CozyClient.hooks = CozyClient.hooks || {};
|
|
2645
2645
|
CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
|
|
2646
2646
|
|
|
2647
|
-
CozyClient.version = "34.
|
|
2647
|
+
CozyClient.version = "34.5.0";
|
|
2648
2648
|
|
|
2649
2649
|
_microee.default.mixin(CozyClient);
|
|
2650
2650
|
|
package/dist/models/paper.js
CHANGED
|
@@ -39,18 +39,17 @@ var isExpiringFrenchNationalIdCard = function isExpiringFrenchNationalIdCard(fil
|
|
|
39
39
|
/**
|
|
40
40
|
* @param {IOCozyFile} file - io.cozy.files document
|
|
41
41
|
* @returns {boolean}
|
|
42
|
-
* @description Tells if a given file
|
|
42
|
+
* @description Tells if a given file has an expiration date set and a notice period set
|
|
43
43
|
*/
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
var
|
|
47
|
-
var _file$metadata5, _file$
|
|
46
|
+
var isExpiringGeneric = function isExpiringGeneric(file) {
|
|
47
|
+
var _file$metadata5, _file$metadata6;
|
|
48
48
|
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
var noticePeriod = (_file$metadata7 = file.metadata) === null || _file$metadata7 === void 0 ? void 0 : _file$metadata7.noticePeriod;
|
|
49
|
+
var expirationDate = (_file$metadata5 = file.metadata) === null || _file$metadata5 === void 0 ? void 0 : _file$metadata5.expirationDate;
|
|
50
|
+
var noticePeriod = (_file$metadata6 = file.metadata) === null || _file$metadata6 === void 0 ? void 0 : _file$metadata6.noticePeriod;
|
|
52
51
|
|
|
53
|
-
if (
|
|
52
|
+
if (expirationDate && noticePeriod) {
|
|
54
53
|
return true;
|
|
55
54
|
}
|
|
56
55
|
|
|
@@ -64,10 +63,10 @@ var isExpiringResidencePermit = function isExpiringResidencePermit(file) {
|
|
|
64
63
|
|
|
65
64
|
|
|
66
65
|
var isExpiringPersonalSportingLicense = function isExpiringPersonalSportingLicense(file) {
|
|
67
|
-
var _file$
|
|
66
|
+
var _file$metadata7, _file$metadata7$quali, _file$metadata8;
|
|
68
67
|
|
|
69
|
-
var label = (_file$
|
|
70
|
-
var referencedDate = (_file$
|
|
68
|
+
var label = (_file$metadata7 = file.metadata) === null || _file$metadata7 === void 0 ? void 0 : (_file$metadata7$quali = _file$metadata7.qualification) === null || _file$metadata7$quali === void 0 ? void 0 : _file$metadata7$quali.label;
|
|
69
|
+
var referencedDate = (_file$metadata8 = file.metadata) === null || _file$metadata8 === void 0 ? void 0 : _file$metadata8.referencedDate;
|
|
71
70
|
var created_at = file.created_at;
|
|
72
71
|
|
|
73
72
|
if (label === 'personal_sporting_licence' && (referencedDate || created_at)) {
|
|
@@ -88,7 +87,7 @@ var isExpiring = function isExpiring(file) {
|
|
|
88
87
|
return true;
|
|
89
88
|
}
|
|
90
89
|
|
|
91
|
-
if (
|
|
90
|
+
if (isExpiringGeneric(file)) {
|
|
92
91
|
return true;
|
|
93
92
|
}
|
|
94
93
|
|
|
@@ -108,17 +107,17 @@ var isExpiring = function isExpiring(file) {
|
|
|
108
107
|
exports.isExpiring = isExpiring;
|
|
109
108
|
|
|
110
109
|
var computeExpirationDate = function computeExpirationDate(file) {
|
|
111
|
-
if (isExpiringFrenchNationalIdCard(file) ||
|
|
112
|
-
var _file$
|
|
110
|
+
if (isExpiringFrenchNationalIdCard(file) || isExpiringGeneric(file)) {
|
|
111
|
+
var _file$metadata9;
|
|
113
112
|
|
|
114
|
-
var expirationDate = (_file$
|
|
113
|
+
var expirationDate = (_file$metadata9 = file.metadata) === null || _file$metadata9 === void 0 ? void 0 : _file$metadata9.expirationDate;
|
|
115
114
|
return new Date(expirationDate);
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
if (isExpiringPersonalSportingLicense(file)) {
|
|
119
|
-
var _file$
|
|
118
|
+
var _file$metadata10;
|
|
120
119
|
|
|
121
|
-
var referencedDate = (_file$
|
|
120
|
+
var referencedDate = (_file$metadata10 = file.metadata) === null || _file$metadata10 === void 0 ? void 0 : _file$metadata10.referencedDate;
|
|
122
121
|
var created_at = file.created_at;
|
|
123
122
|
return (0, _add.default)(new Date(referencedDate !== null && referencedDate !== void 0 ? referencedDate : created_at), {
|
|
124
123
|
days: PERSONAL_SPORTING_LICENCE_PERIOD_DAYS
|
|
@@ -137,10 +136,10 @@ var computeExpirationDate = function computeExpirationDate(file) {
|
|
|
137
136
|
exports.computeExpirationDate = computeExpirationDate;
|
|
138
137
|
|
|
139
138
|
var computeExpirationNoticePeriodInDays = function computeExpirationNoticePeriodInDays(file) {
|
|
140
|
-
if (isExpiringFrenchNationalIdCard(file) ||
|
|
141
|
-
var _file$
|
|
139
|
+
if (isExpiringFrenchNationalIdCard(file) || isExpiringGeneric(file)) {
|
|
140
|
+
var _file$metadata11;
|
|
142
141
|
|
|
143
|
-
var noticePeriodInDays = (_file$
|
|
142
|
+
var noticePeriodInDays = (_file$metadata11 = file.metadata) === null || _file$metadata11 === void 0 ? void 0 : _file$metadata11.noticePeriod;
|
|
144
143
|
return parseInt(noticePeriodInDays, 10);
|
|
145
144
|
}
|
|
146
145
|
|
|
@@ -184,11 +183,15 @@ var computeExpirationNoticeDate = function computeExpirationNoticeDate(file) {
|
|
|
184
183
|
exports.computeExpirationNoticeDate = computeExpirationNoticeDate;
|
|
185
184
|
|
|
186
185
|
var computeExpirationNoticeLink = function computeExpirationNoticeLink(file) {
|
|
186
|
+
var _file$metadata12, _file$metadata12$qual;
|
|
187
|
+
|
|
188
|
+
var qualificationLabel = (_file$metadata12 = file.metadata) === null || _file$metadata12 === void 0 ? void 0 : (_file$metadata12$qual = _file$metadata12.qualification) === null || _file$metadata12$qual === void 0 ? void 0 : _file$metadata12$qual.label;
|
|
189
|
+
|
|
187
190
|
if (isExpiringFrenchNationalIdCard(file)) {
|
|
188
191
|
return 'https://www.service-public.fr/particuliers/vosdroits/N358';
|
|
189
192
|
}
|
|
190
193
|
|
|
191
|
-
if (
|
|
194
|
+
if (isExpiringGeneric(file) && qualificationLabel === 'residence_permit') {
|
|
192
195
|
return 'https://www.service-public.fr/particuliers/vosdroits/N110';
|
|
193
196
|
}
|
|
194
197
|
|
|
@@ -2,6 +2,32 @@ import MockDate from 'mockdate'
|
|
|
2
2
|
|
|
3
3
|
import * as paperModel from './paper'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {object} param - options
|
|
8
|
+
* @param {string} param.qualificationLabel - qualification label
|
|
9
|
+
* @param {string} [param.expirationDate] - expiration date of file
|
|
10
|
+
* @param {string} [param.referencedDate] - reference date of file
|
|
11
|
+
* @param {string} [param.noticePeriod] - period before send notification
|
|
12
|
+
*/
|
|
13
|
+
const buildMockFile = ({
|
|
14
|
+
qualificationLabel,
|
|
15
|
+
expirationDate,
|
|
16
|
+
referencedDate,
|
|
17
|
+
noticePeriod
|
|
18
|
+
}) => {
|
|
19
|
+
return /** @type {import('../types').IOCozyFile} */ ({
|
|
20
|
+
name: qualificationLabel,
|
|
21
|
+
created_at: '2022-09-01T00:00:00.000Z',
|
|
22
|
+
metadata: {
|
|
23
|
+
qualification: { label: qualificationLabel },
|
|
24
|
+
...(expirationDate && { expirationDate }),
|
|
25
|
+
...(referencedDate && { referencedDate }),
|
|
26
|
+
...(noticePeriod && { noticePeriod })
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
5
31
|
describe('Expiration', () => {
|
|
6
32
|
beforeEach(() => {
|
|
7
33
|
MockDate.set('2022-11-01T11:35:58.118Z')
|
|
@@ -10,44 +36,41 @@ describe('Expiration', () => {
|
|
|
10
36
|
MockDate.reset()
|
|
11
37
|
})
|
|
12
38
|
|
|
13
|
-
const
|
|
14
|
-
_id: '
|
|
15
|
-
name: 'national id card',
|
|
16
|
-
created_at: '2022-09-01T00:00:00.000Z',
|
|
17
|
-
metadata: {
|
|
18
|
-
qualification: { label: 'national_id_card' },
|
|
19
|
-
expirationDate: '2022-09-23T11:35:58.118Z',
|
|
20
|
-
noticePeriod: '90'
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const fakeFile02 = {
|
|
24
|
-
_id: '02',
|
|
25
|
-
name: 'personal sporting licence',
|
|
26
|
-
created_at: '2022-09-01T00:00:00.000Z',
|
|
27
|
-
metadata: {
|
|
28
|
-
qualification: { label: 'personal_sporting_licence' },
|
|
29
|
-
referencedDate: '2022-09-23T11:35:58.118Z'
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
const fakeFile03 = {
|
|
33
|
-
_id: '03',
|
|
39
|
+
const fakeFileWithoutMetadata = /** @type {import('../types').IOCozyFile} */ ({
|
|
40
|
+
_id: '00',
|
|
34
41
|
name: 'unknown'
|
|
35
|
-
}
|
|
42
|
+
})
|
|
43
|
+
const fakeNationalIdCardFile = buildMockFile({
|
|
44
|
+
qualificationLabel: 'national_id_card',
|
|
45
|
+
expirationDate: '2022-09-23T11:35:58.118Z',
|
|
46
|
+
noticePeriod: '90'
|
|
47
|
+
})
|
|
48
|
+
const fakePersonalSportingLicenceFile = buildMockFile({
|
|
49
|
+
qualificationLabel: 'personal_sporting_licence',
|
|
50
|
+
referencedDate: '2022-09-23T11:35:58.118Z'
|
|
51
|
+
})
|
|
52
|
+
const fakeResidencePermitFile = buildMockFile({
|
|
53
|
+
qualificationLabel: 'residence_permit',
|
|
54
|
+
expirationDate: '2022-09-23T11:35:58.118Z',
|
|
55
|
+
noticePeriod: '90'
|
|
56
|
+
})
|
|
36
57
|
|
|
37
58
|
describe('computeExpirationDate', () => {
|
|
38
59
|
it('should return expirationDate', () => {
|
|
39
|
-
const res = paperModel.computeExpirationDate(
|
|
60
|
+
const res = paperModel.computeExpirationDate(fakeNationalIdCardFile)
|
|
40
61
|
|
|
41
62
|
expect(res.toISOString()).toBe('2022-09-23T11:35:58.118Z')
|
|
42
63
|
})
|
|
43
64
|
it('should return referencedDate plus 365 days', () => {
|
|
44
|
-
const res = paperModel.computeExpirationDate(
|
|
65
|
+
const res = paperModel.computeExpirationDate(
|
|
66
|
+
fakePersonalSportingLicenceFile
|
|
67
|
+
)
|
|
45
68
|
|
|
46
69
|
expect(res.toISOString()).toBe('2023-09-23T11:35:58.118Z')
|
|
47
70
|
})
|
|
48
71
|
|
|
49
72
|
it('should return "null" if metadata is not found', () => {
|
|
50
|
-
const res = paperModel.computeExpirationDate(
|
|
73
|
+
const res = paperModel.computeExpirationDate(fakeFileWithoutMetadata)
|
|
51
74
|
|
|
52
75
|
expect(res).toBeNull()
|
|
53
76
|
})
|
|
@@ -55,19 +78,93 @@ describe('Expiration', () => {
|
|
|
55
78
|
|
|
56
79
|
describe('computeExpirationNoticeDate', () => {
|
|
57
80
|
it('should return notice date for file with expirationDate metadata', () => {
|
|
58
|
-
const res = paperModel.computeExpirationNoticeDate(
|
|
81
|
+
const res = paperModel.computeExpirationNoticeDate(fakeNationalIdCardFile)
|
|
59
82
|
|
|
60
83
|
expect(res.toISOString()).toBe('2022-06-25T11:35:58.118Z')
|
|
61
84
|
})
|
|
62
85
|
it('should return notice date for file with referencedDate metadata', () => {
|
|
63
|
-
const res = paperModel.computeExpirationNoticeDate(
|
|
86
|
+
const res = paperModel.computeExpirationNoticeDate(
|
|
87
|
+
fakePersonalSportingLicenceFile
|
|
88
|
+
)
|
|
64
89
|
|
|
65
90
|
expect(res.toISOString()).toBe('2023-09-08T11:35:58.118Z')
|
|
66
91
|
})
|
|
67
92
|
it('should return null for file without corresponding metadata', () => {
|
|
68
|
-
const res = paperModel.computeExpirationNoticeDate(
|
|
93
|
+
const res = paperModel.computeExpirationNoticeDate(
|
|
94
|
+
fakeFileWithoutMetadata
|
|
95
|
+
)
|
|
69
96
|
|
|
70
97
|
expect(res).toBeNull()
|
|
71
98
|
})
|
|
72
99
|
})
|
|
100
|
+
|
|
101
|
+
describe('computeExpirationNoticeLink', () => {
|
|
102
|
+
it.each`
|
|
103
|
+
file | link
|
|
104
|
+
${fakeNationalIdCardFile} | ${'https://www.service-public.fr/particuliers/vosdroits/N358'}
|
|
105
|
+
${fakeResidencePermitFile} | ${'https://www.service-public.fr/particuliers/vosdroits/N110'}
|
|
106
|
+
`(
|
|
107
|
+
`should return "$link" link for an file with "$file.metadata.qualification.label" qualification label`,
|
|
108
|
+
({ file, link }) => {
|
|
109
|
+
expect(paperModel.computeExpirationNoticeLink(file)).toEqual(link)
|
|
110
|
+
}
|
|
111
|
+
)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
describe('isExpiring', () => {
|
|
115
|
+
const fakeNationalIdCardFileWithoutNoticeDate = buildMockFile({
|
|
116
|
+
qualificationLabel: 'national_id_card',
|
|
117
|
+
expirationDate: '2022-09-23T11:35:58.118Z',
|
|
118
|
+
noticePeriod: ''
|
|
119
|
+
})
|
|
120
|
+
const fakeResidencePermitFileWithoutNoticeDate = buildMockFile({
|
|
121
|
+
qualificationLabel: 'residence_permit',
|
|
122
|
+
expirationDate: '2022-09-23T11:35:58.118Z',
|
|
123
|
+
noticePeriod: ''
|
|
124
|
+
})
|
|
125
|
+
const fakeNationalIdCardFileWithoutExpirationDate = buildMockFile({
|
|
126
|
+
qualificationLabel: 'national_id_card',
|
|
127
|
+
expirationDate: '',
|
|
128
|
+
noticePeriod: '90'
|
|
129
|
+
})
|
|
130
|
+
const fakeResidencePermitFileWithoutExpirationDate = buildMockFile({
|
|
131
|
+
qualificationLabel: 'residence_permit',
|
|
132
|
+
expirationDate: '',
|
|
133
|
+
noticePeriod: '90'
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it.each`
|
|
137
|
+
file | result
|
|
138
|
+
${fakeNationalIdCardFile} | ${true}
|
|
139
|
+
${fakePersonalSportingLicenceFile} | ${true}
|
|
140
|
+
${fakeResidencePermitFile} | ${true}
|
|
141
|
+
`(
|
|
142
|
+
`should return "$result" for each file with "noticePeriod" & "expirationDate" metadata`,
|
|
143
|
+
({ file, result }) => {
|
|
144
|
+
expect(paperModel.isExpiring(file)).toEqual(result)
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
it.each`
|
|
149
|
+
file | result
|
|
150
|
+
${fakeNationalIdCardFileWithoutNoticeDate} | ${false}
|
|
151
|
+
${fakeResidencePermitFileWithoutNoticeDate} | ${false}
|
|
152
|
+
`(
|
|
153
|
+
`should return "$result" for each file without "noticePeriod" metadata`,
|
|
154
|
+
({ file, result }) => {
|
|
155
|
+
expect(paperModel.isExpiring(file)).toEqual(result)
|
|
156
|
+
}
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
it.each`
|
|
160
|
+
file | result
|
|
161
|
+
${fakeNationalIdCardFileWithoutExpirationDate} | ${false}
|
|
162
|
+
${fakeResidencePermitFileWithoutExpirationDate} | ${false}
|
|
163
|
+
`(
|
|
164
|
+
`should return "$result" for each file without "expirationDate" metadata`,
|
|
165
|
+
({ file, result }) => {
|
|
166
|
+
expect(paperModel.isExpiring(file)).toEqual(result)
|
|
167
|
+
}
|
|
168
|
+
)
|
|
169
|
+
})
|
|
73
170
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-client",
|
|
3
|
-
"version": "34.
|
|
3
|
+
"version": "34.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.node.js",
|
|
6
6
|
"browser": "dist/index.js",
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"react-native-ios11-devicecheck": "https://github.com/cozy/react-native-devicecheck#app-attest-v0.1"
|
|
74
74
|
},
|
|
75
75
|
"sideEffects": false,
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "ecbee1a9f002b3c40ff8aa7b01f5418a7d9519af"
|
|
77
77
|
}
|