@becollective/utils 1.10.2 → 2.0.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/.semaphore/utils.yml +1 -1
- package/index.ts +7 -0
- package/lib/FeatureFlag.d.ts +12 -0
- package/lib/FeatureFlag.js +51 -0
- package/lib/constants/allowedHtmlTags.d.ts +7 -0
- package/lib/constants/allowedHtmlTags.js +8 -0
- package/lib/constants/avatarColours.d.ts +35 -0
- package/lib/constants/avatarColours.js +36 -0
- package/lib/constants/countries.d.ts +253 -0
- package/lib/constants/countries.js +254 -0
- package/lib/constants/currencies.d.ts +29 -0
- package/lib/constants/currencies.js +36 -0
- package/lib/constants/customFields.d.ts +11 -0
- package/lib/constants/customFields.js +12 -0
- package/lib/constants/distancesUnits.d.ts +11 -0
- package/lib/constants/distancesUnits.js +13 -0
- package/lib/constants/groups.d.ts +13 -0
- package/lib/constants/groups.js +85 -0
- package/lib/constants/insuranceStatuses.d.ts +15 -0
- package/lib/constants/insuranceStatuses.js +7 -0
- package/lib/constants/insuranceTypes.d.ts +35 -0
- package/lib/constants/insuranceTypes.js +36 -0
- package/lib/constants/languages.d.ts +2 -0
- package/lib/constants/languages.js +194 -0
- package/lib/constants/locales.d.ts +119 -0
- package/lib/constants/locales.js +191 -0
- package/lib/constants/notifications.d.ts +47 -0
- package/lib/constants/notifications.js +31 -0
- package/lib/constants/opportunities.d.ts +72 -0
- package/lib/constants/opportunities.js +82 -0
- package/lib/constants/qualificationTypes.d.ts +4 -0
- package/lib/constants/qualificationTypes.js +18 -0
- package/lib/constants/rules.d.ts +13 -0
- package/lib/constants/rules.js +21 -0
- package/lib/constants/subscriptions.d.ts +9 -0
- package/lib/constants/subscriptions.js +10 -0
- package/lib/constants/surveys.d.ts +16 -0
- package/lib/constants/surveys.js +17 -0
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +76 -0
- package/lib/date-time.d.ts +28 -0
- package/lib/date-time.js +79 -0
- package/lib/forms.d.ts +1 -0
- package/lib/forms.js +728 -0
- package/lib/locality.d.ts +5 -0
- package/lib/locality.js +15 -0
- package/lib/money.d.ts +7 -0
- package/lib/money.js +32 -0
- package/lib/opportunity.d.ts +1 -0
- package/lib/opportunity.js +11 -0
- package/lib/opportunityUser.d.ts +8 -0
- package/lib/opportunityUser.js +29 -0
- package/lib/password.d.ts +8 -0
- package/lib/password.js +43 -0
- package/lib/rrule/date.d.ts +4 -0
- package/lib/rrule/date.js +30 -0
- package/lib/rrule/index.d.ts +2 -0
- package/lib/rrule/index.js +18 -0
- package/lib/rrule/parsing.d.ts +6 -0
- package/lib/rrule/parsing.js +130 -0
- package/lib/rrule/parsing.test.d.ts +1 -0
- package/lib/rrule/parsing.test.js +11 -0
- package/lib/rrule.d.ts +49 -0
- package/lib/rrule.js +303 -0
- package/lib/src/FeatureFlag.d.ts +12 -0
- package/lib/src/FeatureFlag.js +51 -0
- package/lib/src/date-time.d.ts +28 -0
- package/lib/src/date-time.js +79 -0
- package/lib/src/forms.d.ts +1 -0
- package/lib/src/forms.js +728 -0
- package/lib/src/locality.d.ts +5 -0
- package/lib/src/locality.js +15 -0
- package/lib/src/money.d.ts +7 -0
- package/lib/src/money.js +32 -0
- package/lib/src/opportunity.d.ts +1 -0
- package/lib/src/opportunity.js +11 -0
- package/lib/src/opportunityUser.d.ts +8 -0
- package/lib/src/opportunityUser.js +29 -0
- package/lib/src/password.d.ts +8 -0
- package/lib/src/password.js +43 -0
- package/package.json +15 -29
- package/src/FeatureFlag.ts +26 -10
- package/src/constants/allowedHtmlTags.ts +6 -0
- package/src/constants/avatarColours.ts +34 -0
- package/src/constants/countries.ts +252 -0
- package/src/constants/currencies.ts +33 -0
- package/src/constants/customFields.ts +10 -0
- package/src/constants/distancesUnits.ts +11 -0
- package/src/constants/groups.ts +83 -0
- package/src/constants/insuranceStatuses.ts +5 -0
- package/src/constants/insuranceTypes.ts +34 -0
- package/src/constants/languages.ts +192 -0
- package/src/constants/locales.ts +189 -0
- package/src/constants/notifications.ts +30 -0
- package/src/constants/opportunities.ts +84 -0
- package/src/constants/qualificationTypes.ts +17 -0
- package/src/constants/rules.ts +22 -0
- package/src/constants/subscriptions.ts +8 -0
- package/src/constants/surveys.ts +15 -0
- package/src/constants.ts +40 -0
- package/src/{date-time.js → date-time.ts} +18 -11
- package/src/forms.ts +807 -0
- package/src/{opportunityUser.js → opportunityUser.ts} +5 -1
- package/src/{password.js → password.ts} +2 -0
- package/src/rrule/date.ts +25 -0
- package/src/rrule/index.ts +2 -0
- package/src/rrule/parsing.ts +136 -0
- package/src/rrule.ts +367 -0
- package/tests/{date-time.test.js → date-time.test.ts} +48 -46
- package/tests/featureFlag.test.ts +36 -39
- package/tests/forms.test-data.json +43 -0
- package/tests/forms.test-schema.json +144 -0
- package/tests/forms.test-uischema.json +117 -0
- package/tests/forms.test.ts +674 -0
- package/tests/{money.test.js → money.test.ts} +2 -3
- package/tests/{password.test.js → password.test.ts} +7 -6
- package/tests/rrule/parsing.test.ts +12 -0
- package/tests/rrule.test.ts +625 -0
- package/tsconfig.json +15 -12
- package/bundle.js +0 -270
- package/index.js +0 -25
- package/rollup.config.js +0 -25
- /package/src/{locality.js → locality.ts} +0 -0
- /package/src/{money.js → money.ts} +0 -0
- /package/src/{opportunity.js → opportunity.ts} +0 -0
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const validator = require('../src/forms');
|
|
3
|
+
const testSchema = require('./forms.test-schema.json');
|
|
4
|
+
const testUischema = require('./forms.test-uischema.json');
|
|
5
|
+
const testData = require('./forms.test-data.json');
|
|
6
|
+
|
|
7
|
+
let schema;
|
|
8
|
+
let uischema;
|
|
9
|
+
let data;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
// Deep cloning test data so we can mutate it inside tests.
|
|
13
|
+
schema = JSON.parse(JSON.stringify(testSchema));
|
|
14
|
+
uischema = JSON.parse(JSON.stringify(testUischema));
|
|
15
|
+
data = JSON.parse(JSON.stringify(testData));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('validateSchema', () => {
|
|
19
|
+
const { validateSchema } = validator;
|
|
20
|
+
|
|
21
|
+
test('should fail when array type has duplicate values', () => {
|
|
22
|
+
const t = {
|
|
23
|
+
data: {
|
|
24
|
+
type: 'object',
|
|
25
|
+
required: [],
|
|
26
|
+
properties: {
|
|
27
|
+
foo: {
|
|
28
|
+
title: 'Foobar',
|
|
29
|
+
type: 'array',
|
|
30
|
+
uniqueItems: true,
|
|
31
|
+
items: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
anyOf: [
|
|
34
|
+
{
|
|
35
|
+
type: 'string',
|
|
36
|
+
enum: ['a'],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
type: 'string',
|
|
40
|
+
enum: ['d'],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: 'string',
|
|
44
|
+
enum: ['a'],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
ui: {
|
|
52
|
+
'ui:order': ['foo'],
|
|
53
|
+
foo: {
|
|
54
|
+
'ui:widget': 'WidgetTickbox',
|
|
55
|
+
'ui:title': 'Foobar',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return expect(validateSchema(t.data, t.ui)).rejects.toEqual([
|
|
61
|
+
{
|
|
62
|
+
key: 'foo',
|
|
63
|
+
message: 'must NOT have duplicate items (items ## 0 and 2 are identical)',
|
|
64
|
+
property: 'items.anyOf',
|
|
65
|
+
},
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('should fail when schema has property without a title', () => {
|
|
70
|
+
const t = {
|
|
71
|
+
data: {
|
|
72
|
+
type: 'object',
|
|
73
|
+
required: [],
|
|
74
|
+
properties: {
|
|
75
|
+
foo: {
|
|
76
|
+
title: '',
|
|
77
|
+
type: 'string',
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
ui: {
|
|
82
|
+
'ui:order': ['foo'],
|
|
83
|
+
foo: {
|
|
84
|
+
'ui:widget': 'WidgetDropDown',
|
|
85
|
+
'ui:title': '',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return expect(validateSchema(t.data, t.ui)).rejects.toEqual([
|
|
91
|
+
{
|
|
92
|
+
key: 'foo',
|
|
93
|
+
message: 'must NOT have fewer than 1 characters',
|
|
94
|
+
property: 'title',
|
|
95
|
+
},
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('should fail when array is empty', () => {
|
|
100
|
+
const t = {
|
|
101
|
+
data: {
|
|
102
|
+
type: 'object',
|
|
103
|
+
required: [],
|
|
104
|
+
properties: {
|
|
105
|
+
foobar: {
|
|
106
|
+
title: '',
|
|
107
|
+
type: 'array',
|
|
108
|
+
items: {
|
|
109
|
+
type: 'object',
|
|
110
|
+
anyOf: [],
|
|
111
|
+
},
|
|
112
|
+
uniqueItems: true,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
ui: {
|
|
117
|
+
'ui:order': ['foobar'],
|
|
118
|
+
foobar: {
|
|
119
|
+
'ui:widget': 'WidgetDropDown',
|
|
120
|
+
'ui:title': '',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return expect(validateSchema(t.data, t.ui)).rejects.toEqual([
|
|
126
|
+
{
|
|
127
|
+
key: 'foobar',
|
|
128
|
+
message: 'must NOT have fewer than 1 characters',
|
|
129
|
+
property: 'title',
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
key: 'foobar',
|
|
133
|
+
message: 'must NOT have fewer than 1 items',
|
|
134
|
+
property: 'items.anyOf',
|
|
135
|
+
},
|
|
136
|
+
]);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('should succeed, returning true when schema and uischema are valid', () => {
|
|
140
|
+
return expect(validateSchema(schema, uischema)).resolves.toBe(true);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('should fail when schema has missing data', () => {
|
|
144
|
+
delete schema.properties.B1WsCeOaz;
|
|
145
|
+
|
|
146
|
+
return expect(validateSchema(schema, uischema)).rejects.toEqual([
|
|
147
|
+
{ key: '0', name: 'order-item-not-found', value: 'B1WsCeOaz' },
|
|
148
|
+
]);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('should fail when uischema has missing data', () => {
|
|
152
|
+
delete uischema.B1WsCeOaz;
|
|
153
|
+
|
|
154
|
+
return expect(validateSchema(schema, uischema)).rejects.toEqual([
|
|
155
|
+
{ key: '0', name: 'ui-data-schema-mismatch', value: 'B1WsCeOaz' },
|
|
156
|
+
]);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('should fail when uischema is invalid', () => {
|
|
160
|
+
uischema.foo = {};
|
|
161
|
+
|
|
162
|
+
return expect(validateSchema(schema, uischema)).rejects.toEqual([
|
|
163
|
+
{ name: 'invalid-uischema-property', object: 'foo' },
|
|
164
|
+
]);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('should fail when required is missing from schema', () => {
|
|
168
|
+
delete schema.required;
|
|
169
|
+
|
|
170
|
+
return expect(validateSchema(schema, uischema)).rejects.toEqual({ name: 'missing-required' });
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('should fail an invalid type is provided', () => {
|
|
174
|
+
schema.properties.B1WsCeOaz.type = 'foo';
|
|
175
|
+
|
|
176
|
+
return expect(validateSchema(schema, uischema)).rejects.toEqual([
|
|
177
|
+
{
|
|
178
|
+
name: 'invalid-schema-type',
|
|
179
|
+
object: { title: 'Who are you?', type: 'foo' },
|
|
180
|
+
},
|
|
181
|
+
]);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('should fail an invalid reportable field is provided', () => {
|
|
185
|
+
schema.properties.B1WsCe555.bcReportable = 'BC_SHOULD_FAIL';
|
|
186
|
+
|
|
187
|
+
return expect(validateSchema(schema, uischema)).rejects.toEqual([
|
|
188
|
+
{
|
|
189
|
+
name: 'invalid-reportable-field',
|
|
190
|
+
object: {
|
|
191
|
+
title: 'Do you own your own vehicle?',
|
|
192
|
+
type: 'string',
|
|
193
|
+
bcReportable: 'BC_SHOULD_FAIL',
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
]);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('should fail when schema has duplicated title', () => {
|
|
200
|
+
const properties = {
|
|
201
|
+
SbQY_SSBz: {
|
|
202
|
+
title: 'age',
|
|
203
|
+
type: 'string',
|
|
204
|
+
},
|
|
205
|
+
SyDtPZrkm: {
|
|
206
|
+
type: 'string',
|
|
207
|
+
title: 'spacer',
|
|
208
|
+
bcType: 'spacer',
|
|
209
|
+
},
|
|
210
|
+
cSCgS2dlE: {
|
|
211
|
+
title: 'Paragraph',
|
|
212
|
+
text: '<p>Rich text</p>',
|
|
213
|
+
type: 'string',
|
|
214
|
+
bcType: 'textParagraph',
|
|
215
|
+
},
|
|
216
|
+
sBFu87LVd: {
|
|
217
|
+
title: 'Notes',
|
|
218
|
+
type: 'string',
|
|
219
|
+
},
|
|
220
|
+
SyDtPZrks: {
|
|
221
|
+
type: 'string',
|
|
222
|
+
title: 'spacer',
|
|
223
|
+
bcType: 'spacer',
|
|
224
|
+
},
|
|
225
|
+
eoXtMLT0x: {
|
|
226
|
+
title: 'Age',
|
|
227
|
+
type: 'number',
|
|
228
|
+
properties: {},
|
|
229
|
+
bcType: 'number',
|
|
230
|
+
},
|
|
231
|
+
cSCgS2slE: {
|
|
232
|
+
title: 'Paragraph',
|
|
233
|
+
text: '<p>Rich text</p>',
|
|
234
|
+
type: 'string',
|
|
235
|
+
bcType: 'textParagraph',
|
|
236
|
+
},
|
|
237
|
+
L5p0dLuKs: {
|
|
238
|
+
title: 'Ask a question',
|
|
239
|
+
type: 'array',
|
|
240
|
+
uniqueItems: true,
|
|
241
|
+
items: {
|
|
242
|
+
type: 'string',
|
|
243
|
+
anyOf: [
|
|
244
|
+
{
|
|
245
|
+
type: 'string',
|
|
246
|
+
enum: ['Yes'],
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
type: 'string',
|
|
250
|
+
enum: ['No'],
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
},
|
|
254
|
+
isDisabled: true,
|
|
255
|
+
},
|
|
256
|
+
kJFggxvpo: {
|
|
257
|
+
title: 'Ask a multiple choice question',
|
|
258
|
+
type: 'array',
|
|
259
|
+
uniqueItems: true,
|
|
260
|
+
items: {
|
|
261
|
+
type: 'string',
|
|
262
|
+
anyOf: [
|
|
263
|
+
{
|
|
264
|
+
type: 'string',
|
|
265
|
+
enum: ['yes'],
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
type: 'string',
|
|
269
|
+
enum: ['no'],
|
|
270
|
+
},
|
|
271
|
+
],
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
const result = validator.validatePropertiesTitleUniqueness(properties, 'duplicate');
|
|
276
|
+
expect(result).toHaveLength(2);
|
|
277
|
+
expect(result[0].key).toEqual('SbQY_SSBz');
|
|
278
|
+
expect(result[1].key).toEqual('eoXtMLT0x');
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe('validateData', () => {
|
|
283
|
+
const { validateData } = validator;
|
|
284
|
+
|
|
285
|
+
test('should return true when schema and data are valid', () => {
|
|
286
|
+
return expect(validateData(schema, data)).resolves.toBe(undefined);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
test('should return true when file is marked as required and data does not include file', () => {
|
|
290
|
+
// This requirement is due to how our backend is handling file data.
|
|
291
|
+
const schema = {
|
|
292
|
+
type: 'object',
|
|
293
|
+
required: ['FILE_FIELD'],
|
|
294
|
+
properties: {
|
|
295
|
+
FILE_FIELD: {
|
|
296
|
+
title: 'Upload a file',
|
|
297
|
+
type: 'string',
|
|
298
|
+
bcType: 'file',
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
};
|
|
302
|
+
const data = {};
|
|
303
|
+
|
|
304
|
+
return expect(validateData(schema, data)).resolves.toBe(undefined);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
describe('stripEmptyArraysFromData', () => {
|
|
309
|
+
const { stripEmptyArraysFromData } = validator;
|
|
310
|
+
|
|
311
|
+
test('should return true when input data has empty array and that array is removed', () => {
|
|
312
|
+
const emptyArrayData = JSON.parse(JSON.stringify(data));
|
|
313
|
+
emptyArrayData['rkF-kbOaz'] = [];
|
|
314
|
+
|
|
315
|
+
const expectedData = JSON.parse(JSON.stringify(data));
|
|
316
|
+
delete expectedData['rkF-kbOaz'];
|
|
317
|
+
|
|
318
|
+
return expect(stripEmptyArraysFromData(emptyArrayData)).toEqual(expectedData);
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
describe('dataTypeIsValid', () => {
|
|
323
|
+
const isValid = validator.dataTypeIsValid;
|
|
324
|
+
const optionsSchema = {
|
|
325
|
+
type: 'string',
|
|
326
|
+
title: 'Fruits',
|
|
327
|
+
items: {
|
|
328
|
+
type: 'string',
|
|
329
|
+
enum: ['Apples', 'Bananas', 'Pears'],
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
describe('string', () => {
|
|
334
|
+
test('should return true when schema has items.enum and arg is a string value that is in enum', () => {
|
|
335
|
+
expect(isValid.string('Apples', optionsSchema)).toBe(true);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test('should return false when schema has items.enum and arg is a string value that is not in enum', () => {
|
|
339
|
+
expect(isValid.string('Berries', optionsSchema)).toBe(false);
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test('should return true when arg is string', () => {
|
|
343
|
+
expect(isValid.string('Hello')).toBe(true);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test('should return false when arg is number', () => {
|
|
347
|
+
expect(isValid.string(1)).toBe(false);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
test('should return false when arg is array', () => {
|
|
351
|
+
expect(isValid.string([])).toBe(false);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test('should return false when arg is object', () => {
|
|
355
|
+
expect(isValid.string({})).toBe(false);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test('should return false when arg is boolean', () => {
|
|
359
|
+
expect(isValid.string(true)).toBe(false);
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
describe('number', () => {
|
|
364
|
+
test('should return true when arg is number', () => {
|
|
365
|
+
expect(isValid.number(1)).toBe(true);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
test('should return false when arg is string', () => {
|
|
369
|
+
expect(isValid.number('Hello')).toBe(false);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
test('should return false when arg is array', () => {
|
|
373
|
+
expect(isValid.number([])).toBe(false);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
test('should return false when arg is object', () => {
|
|
377
|
+
expect(isValid.number({})).toBe(false);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test('should return false when arg is boolean', () => {
|
|
381
|
+
expect(isValid.number(true)).toBe(false);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
test('should return true when number with decimal places < 10', () => {
|
|
385
|
+
expect(isValid.number(1.123456789)).toBe(true);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
test('should return false when number with decimal places > 10', () => {
|
|
389
|
+
expect(isValid.number(1.12345678901)).toBe(false);
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
describe('boolean', () => {
|
|
394
|
+
test('should return true when arg is boolean', () => {
|
|
395
|
+
expect(isValid.boolean(false)).toBe(true);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
test('should return false when arg is number', () => {
|
|
399
|
+
expect(isValid.boolean(1)).toBe(false);
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
test('should return false when arg is array', () => {
|
|
403
|
+
expect(isValid.boolean([])).toBe(false);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
test('should return false when arg is object', () => {
|
|
407
|
+
expect(isValid.boolean({})).toBe(false);
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
test('should return false when arg is string', () => {
|
|
411
|
+
expect(isValid.boolean('true')).toBe(false);
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
describe('date', () => {
|
|
416
|
+
test('should return true when arg is date string', () => {
|
|
417
|
+
expect(isValid.date('2021-12-04T14:00:00.000Z')).toBe(true);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
test('should return true when arg is date string in YYYY-MM-DD format', () => {
|
|
421
|
+
expect(isValid.date('2021-12-04')).toBe(true);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
test('should return false when arg is a date string with year > 9999', () => {
|
|
425
|
+
expect(isValid.date('10000-12-04T14:00:00.000Z')).toBe(false);
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
test('should return false when arg is a date string with year < 1000', () => {
|
|
429
|
+
expect(isValid.date('1-12-04T14:00:00.000Z')).toBe(false);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test('should return false when arg is date object', () => {
|
|
433
|
+
expect(isValid.date(new Date())).toBe(false);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
test('should return false when arg is number', () => {
|
|
437
|
+
expect(isValid.date(123)).toBe(false);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test('should return false when arg is array', () => {
|
|
441
|
+
expect(isValid.date([])).toBe(false);
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
test('should return false when arg is object', () => {
|
|
445
|
+
expect(isValid.date({})).toBe(false);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
test('should return false when arg is string', () => {
|
|
449
|
+
expect(isValid.date('apples')).toBe(false);
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
describe('dateRange', () => {
|
|
454
|
+
const dateRangeISO = {
|
|
455
|
+
from: '2018-05-26T14:00:00.000Z',
|
|
456
|
+
to: '2018-05-30T14:00:00.000Z',
|
|
457
|
+
};
|
|
458
|
+
const dateRangeDateObj = {
|
|
459
|
+
from: new Date('2018-05-26T14:00:00.000Z'),
|
|
460
|
+
to: new Date('2018-05-30T13:59:59.000Z'),
|
|
461
|
+
};
|
|
462
|
+
const ISODate = '2018-05-24T14:00:00.000Z';
|
|
463
|
+
|
|
464
|
+
test('should return true when arg is a date range object with ISO String dates', () => {
|
|
465
|
+
expect(isValid.dateRange(dateRangeISO)).toBe(true);
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
test('should return true when from and to date are the same', () => {
|
|
469
|
+
expect(
|
|
470
|
+
isValid.dateRange({
|
|
471
|
+
from: ISODate,
|
|
472
|
+
to: ISODate,
|
|
473
|
+
})
|
|
474
|
+
).toBe(true);
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
test('should return false when arg is date range object with Date objects', () => {
|
|
478
|
+
expect(isValid.dateRange(dateRangeDateObj)).toBe(false);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
test('should return false when arg is date ISO String', () => {
|
|
482
|
+
expect(isValid.dateRange(new Date().toISOString())).toBe(false);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
test('should return false when arg is date object', () => {
|
|
486
|
+
expect(isValid.dateRange(new Date())).toBe(false);
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
test('should return false when arg is number', () => {
|
|
490
|
+
expect(isValid.dateRange(123)).toBe(false);
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
test('should return false when arg is array', () => {
|
|
494
|
+
expect(isValid.dateRange([])).toBe(false);
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
test('should return false when arg is object', () => {
|
|
498
|
+
expect(isValid.dateRange({})).toBe(false);
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
test('should return false when arg is string', () => {
|
|
502
|
+
expect(isValid.dateRange('apples')).toBe(false);
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
describe('phone', () => {
|
|
507
|
+
const validPhone = '+61434111222';
|
|
508
|
+
|
|
509
|
+
test('should return true when phone number is valid', () => {
|
|
510
|
+
expect(isValid.phone(validPhone)).toBe(true);
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
test("should return false when phone number isn't provided", () => {
|
|
514
|
+
expect(isValid.phone()).toBe(false);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
test("should return false when phone number isn't in the E.164 format", () => {
|
|
518
|
+
expect(isValid.phone('0433222333')).toBe(false);
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
describe('array', () => {
|
|
523
|
+
const sport = {
|
|
524
|
+
schema: {
|
|
525
|
+
type: 'array',
|
|
526
|
+
title: 'What sport do you like?',
|
|
527
|
+
items: {
|
|
528
|
+
anyOf: [
|
|
529
|
+
{
|
|
530
|
+
type: 'string',
|
|
531
|
+
enum: ['Soccer'],
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
type: 'string',
|
|
535
|
+
enum: ['Basketball'],
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
type: 'string',
|
|
539
|
+
enum: ['Football'],
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
type: 'string',
|
|
543
|
+
enum: ['Cricket'],
|
|
544
|
+
},
|
|
545
|
+
],
|
|
546
|
+
},
|
|
547
|
+
uniqueItems: true,
|
|
548
|
+
},
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
test('should return true when value exists in enum', () => {
|
|
552
|
+
expect(isValid.array(['Soccer'], sport.schema)).toBe(true);
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
test('should return false when schema is an empty object', () => {
|
|
556
|
+
expect(isValid.array(['Soccer'], {})).toBe(false);
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
test("should return false when value doesn't exists in enum", () => {
|
|
560
|
+
expect(isValid.array(['Tennis'], sport.schema)).toBe(false);
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
test('should return false when no value is passed in', () => {
|
|
564
|
+
expect(isValid.array(undefined, sport.schema)).toBe(false);
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
test('should return false when empty array is passed in', () => {
|
|
568
|
+
expect(isValid.array([], sport.schema)).toBe(false);
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
describe('skills', () => {
|
|
573
|
+
const skills = {
|
|
574
|
+
schema: {
|
|
575
|
+
title: 'Skills Required',
|
|
576
|
+
type: 'array',
|
|
577
|
+
uniqueItems: true,
|
|
578
|
+
bcType: 'skills',
|
|
579
|
+
items: {
|
|
580
|
+
type: 'string',
|
|
581
|
+
anyOf: [
|
|
582
|
+
{
|
|
583
|
+
enum: ['skillId1'],
|
|
584
|
+
title: 'Office Reception',
|
|
585
|
+
type: 'string',
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
enum: ['skillId2'],
|
|
589
|
+
title: 'Executive Administration',
|
|
590
|
+
type: 'string',
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
enum: ['skillId3'],
|
|
594
|
+
title: 'Office Management',
|
|
595
|
+
type: 'string',
|
|
596
|
+
},
|
|
597
|
+
],
|
|
598
|
+
},
|
|
599
|
+
},
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
test('should return true when value exists in enum', () => {
|
|
603
|
+
expect(isValid.skills(['skillId1'], skills.schema)).toBe(true);
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
test('should return false when schema is an empty object', () => {
|
|
607
|
+
expect(isValid.skills(['skillId2'], {})).toBe(false);
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
test("should return false when value doesn't exists in enum", () => {
|
|
611
|
+
expect(isValid.skills(['skillId7'], skills.schema)).toBe(false);
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
test('should return false when no value is passed in', () => {
|
|
615
|
+
expect(isValid.skills(undefined, skills.schema)).toBe(false);
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
test('should return false when empty array is passed in', () => {
|
|
619
|
+
expect(isValid.skills([], skills.schema)).toBe(false);
|
|
620
|
+
});
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
describe('qualifications', () => {
|
|
624
|
+
const qualifications = {
|
|
625
|
+
schema: {
|
|
626
|
+
title: 'Qualifications Required',
|
|
627
|
+
type: 'array',
|
|
628
|
+
uniqueItems: true,
|
|
629
|
+
bcType: 'skills',
|
|
630
|
+
items: {
|
|
631
|
+
type: 'string',
|
|
632
|
+
enum: ['drivers-licence', 'working-with-children'],
|
|
633
|
+
},
|
|
634
|
+
},
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
test('should return true when value exists in enum', () => {
|
|
638
|
+
expect(isValid.qualifications(['drivers-licence'], qualifications.schema)).toBe(true);
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
test('should return false when schema is an empty object', () => {
|
|
642
|
+
expect(isValid.qualifications(['drivers-licence'], {})).toBe(false);
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
test("should return false when value doesn't exists in enum", () => {
|
|
646
|
+
expect(isValid.qualifications(['cook-food'], qualifications.schema)).toBe(false);
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
test('should return false when no value is passed in', () => {
|
|
650
|
+
expect(isValid.qualifications(undefined, qualifications.schema)).toBe(false);
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
test('should return false when empty array is passed in', () => {
|
|
654
|
+
expect(isValid.qualifications([], qualifications.schema)).toBe(false);
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
describe('getValidatorForTypeData', () => {
|
|
660
|
+
test('should resolve with a defined validator', () => {
|
|
661
|
+
const v= validator.getValidatorForTypeData('string');
|
|
662
|
+
expect(typeof v).toBe('function');
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
test('should reject with an undefined validator', () => {
|
|
666
|
+
try {
|
|
667
|
+
validator.getValidatorForTypeData();
|
|
668
|
+
}
|
|
669
|
+
catch(e) {
|
|
670
|
+
expect(e).toMatchObject({ name: 'Datatype not found' });
|
|
671
|
+
}
|
|
672
|
+
// return expect(validator.getValidatorForTypeData()).rejects.
|
|
673
|
+
});
|
|
674
|
+
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { getCurrencyFromCurrencyCode, makeMoneyString } = require('../bundle.js');
|
|
1
|
+
import { currencies } from '@becollective/constants';
|
|
2
|
+
import { getCurrencyFromCurrencyCode, makeMoneyString } from '../lib/money';
|
|
4
3
|
|
|
5
4
|
describe('getCurrencyFromCurrencyCode', () => {
|
|
6
5
|
test('Returns the correct currency', () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import * as util from '../lib/password';
|
|
2
2
|
|
|
3
3
|
describe('password.valiate', () => {
|
|
4
4
|
test('validate a valid password', async () => {
|
|
@@ -36,11 +36,12 @@ describe('password.valiate', () => {
|
|
|
36
36
|
util.password.validate(password);
|
|
37
37
|
}).not.toThrow('invalid-minimum-rules');
|
|
38
38
|
}, 1000);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
39
|
+
// will not execute with TypeScript
|
|
40
|
+
// test('validate a missing password property', async () => {
|
|
41
|
+
// expect(() => {
|
|
42
|
+
// util.password.validate();
|
|
43
|
+
// }).toThrow('not-string');
|
|
44
|
+
// }, 1000);
|
|
44
45
|
test('validate a non-string', async () => {
|
|
45
46
|
const password = { foo: 'bar' };
|
|
46
47
|
expect(() => {
|