ejv 1.1.11 → 2.0.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.
Files changed (75) hide show
  1. package/.eslintrc.json +88 -0
  2. package/.mocharc.json +8 -0
  3. package/CHANGELOG.md +109 -68
  4. package/LICENSE +21 -21
  5. package/README-KR.md +596 -592
  6. package/README.md +599 -595
  7. package/build/{constants.js → cjs/constants.js} +45 -46
  8. package/build/cjs/constants.js.map +1 -0
  9. package/build/cjs/ejv.js +1263 -0
  10. package/build/cjs/ejv.js.map +1 -0
  11. package/build/{public_api.js → cjs/index.js} +4 -4
  12. package/build/cjs/index.js.map +1 -0
  13. package/build/cjs/interfaces.js +29 -0
  14. package/build/cjs/interfaces.js.map +1 -0
  15. package/build/cjs/package.json +1 -0
  16. package/build/{tester.js → cjs/tester.js} +88 -83
  17. package/build/cjs/tester.js.map +1 -0
  18. package/build/cjs/util.js +103 -0
  19. package/build/cjs/util.js.map +1 -0
  20. package/build/constants.d.ts +37 -40
  21. package/build/esm/constants.js +115 -0
  22. package/build/esm/constants.js.map +1 -0
  23. package/build/esm/ejv.js +1261 -0
  24. package/build/esm/ejv.js.map +1 -0
  25. package/build/esm/index.js +4 -0
  26. package/build/esm/index.js.map +1 -0
  27. package/build/esm/interfaces.js +33 -0
  28. package/build/esm/interfaces.js.map +1 -0
  29. package/build/esm/package.json +1 -0
  30. package/build/esm/tester.js +240 -0
  31. package/build/esm/tester.js.map +1 -0
  32. package/build/esm/util.js +96 -0
  33. package/build/esm/util.js.map +1 -0
  34. package/build/index.d.ts +3 -0
  35. package/build/interfaces.d.ts +51 -13
  36. package/build/scripts/add-js-extensions.js +46 -0
  37. package/build/scripts/add-js-extensions.js.map +1 -0
  38. package/build/tester.d.ts +16 -17
  39. package/build/util.d.ts +7 -1
  40. package/package.json +50 -39
  41. package/scripts/add-js-extensions.ts +59 -0
  42. package/spec/ArrayScheme.ts +1021 -0
  43. package/spec/CommonScheme.ts +251 -0
  44. package/spec/DateScheme.ts +472 -0
  45. package/spec/NumberScheme.ts +1032 -0
  46. package/spec/ObjectScheme.ts +499 -0
  47. package/spec/RegExpScheme.ts +112 -0
  48. package/spec/StringScheme.ts +1239 -0
  49. package/spec/common-test-util.ts +63 -0
  50. package/spec/ejv.spec.ts +209 -4634
  51. package/spec/testers.spec.ts +833 -832
  52. package/src/constants.ts +155 -156
  53. package/src/ejv.ts +1648 -1071
  54. package/src/index.ts +14 -0
  55. package/src/interfaces.ts +145 -63
  56. package/src/tester.ts +308 -302
  57. package/src/util.ts +124 -59
  58. package/tsconfig.cjs.json +8 -0
  59. package/tsconfig.esm.json +7 -0
  60. package/tsconfig.json +22 -19
  61. package/tsconfig.scripts.json +14 -0
  62. package/tsconfig.types.json +9 -0
  63. package/build/constants.js.map +0 -1
  64. package/build/ejv.js +0 -687
  65. package/build/ejv.js.map +0 -1
  66. package/build/interfaces.js +0 -15
  67. package/build/interfaces.js.map +0 -1
  68. package/build/public_api.d.ts +0 -3
  69. package/build/public_api.js.map +0 -1
  70. package/build/tester.js.map +0 -1
  71. package/build/util.js +0 -68
  72. package/build/util.js.map +0 -1
  73. package/spec/common-test-runner.ts +0 -17
  74. package/src/public_api.ts +0 -3
  75. package/tsconfig.spec.json +0 -19
@@ -0,0 +1,251 @@
1
+ import { describe, it } from 'mocha';
2
+ import { expect } from 'chai';
3
+
4
+ import { ejv } from '../src/ejv';
5
+
6
+ import { EjvError } from '../src/interfaces';
7
+ import { ErrorMsg, ErrorType } from '../src/constants';
8
+ import { createErrorMsg } from '../src/util';
9
+
10
+
11
+ describe('CommonScheme', () => {
12
+ describe('optional', () => {
13
+ describe('default', () => {
14
+ it('undefined value', () => {
15
+ const data = {
16
+ a: undefined
17
+ };
18
+
19
+ const error: EjvError | null = ejv(data, [{
20
+ key: 'a',
21
+ type: 'string'
22
+ }]);
23
+
24
+ expect(error).to.be.instanceof(EjvError);
25
+
26
+ if (!error) {
27
+ throw new Error('spec failed');
28
+ }
29
+
30
+ expect(error.type).to.be.eql(ErrorType.REQUIRED);
31
+ expect(error.message).to.be.eql(createErrorMsg(ErrorMsg.REQUIRED));
32
+ expect(error.path).to.be.eql('a');
33
+ expect(error.data).to.be.deep.equal(data);
34
+ expect(error.errorData).to.be.undefined;
35
+ });
36
+
37
+ it('correct type', () => {
38
+ const error: EjvError | null = ejv({
39
+ a: 'abc'
40
+ }, [{
41
+ key: 'a',
42
+ type: 'string'
43
+ }]);
44
+
45
+ expect(error).to.be.null;
46
+ });
47
+
48
+ it('incorrect type', () => {
49
+ const data = {
50
+ a: 123
51
+ };
52
+
53
+ const error: EjvError | null = ejv(data, [{
54
+ key: 'a',
55
+ type: 'string'
56
+ }]);
57
+
58
+ expect(error).to.be.instanceof(EjvError);
59
+
60
+ if (!error) {
61
+ throw new Error('spec failed');
62
+ }
63
+
64
+ expect(error.type).to.be.eql(ErrorType.TYPE_MISMATCH);
65
+ expect(error.message).to.be.eql(createErrorMsg(ErrorMsg.TYPE_MISMATCH, {
66
+ placeholders: ['string']
67
+ }));
68
+ expect(error.path).to.be.eql('a');
69
+ expect(error.data).to.be.deep.equal(data);
70
+ expect(error.errorData).to.be.eql(123);
71
+ });
72
+ });
73
+
74
+ describe('optional === false', () => {
75
+ it('undefined value', () => {
76
+ const data = {
77
+ a: undefined
78
+ };
79
+
80
+ const error: EjvError | null = ejv(data, [{
81
+ key: 'a',
82
+ type: 'string',
83
+ optional: false
84
+ }]);
85
+
86
+ expect(error).to.be.instanceof(EjvError);
87
+
88
+ if (!error) {
89
+ throw new Error('spec failed');
90
+ }
91
+
92
+ expect(error.type).to.be.eql(ErrorType.REQUIRED);
93
+ expect(error.message).to.be.eql(createErrorMsg(ErrorMsg.REQUIRED));
94
+ expect(error.path).to.be.eql('a');
95
+ expect(error.data).to.be.deep.equal(data);
96
+ expect(error.errorData).to.be.undefined;
97
+ });
98
+
99
+ it('correct type', () => {
100
+ const error: EjvError | null = ejv({
101
+ a: 'abc'
102
+ }, [{
103
+ key: 'a',
104
+ type: 'string',
105
+ optional: false
106
+ }]);
107
+
108
+ expect(error).to.be.null;
109
+ });
110
+
111
+ it('incorrect type', () => {
112
+ const data = {
113
+ a: 123
114
+ };
115
+
116
+ const error: EjvError | null = ejv(data, [{
117
+ key: 'a',
118
+ type: 'string',
119
+ optional: false
120
+ }]);
121
+
122
+ expect(error).to.be.instanceof(EjvError);
123
+
124
+ if (!error) {
125
+ throw new Error('spec failed');
126
+ }
127
+
128
+ expect(error.type).to.be.eql(ErrorType.TYPE_MISMATCH);
129
+ expect(error.message).to.be.eql(createErrorMsg(ErrorMsg.TYPE_MISMATCH, {
130
+ placeholders: ['string']
131
+ }));
132
+ expect(error.path).to.be.eql('a');
133
+ expect(error.data).to.be.deep.equal(data);
134
+ expect(error.errorData).to.be.eql(123);
135
+ });
136
+ });
137
+
138
+ describe('optional === true', () => {
139
+ it('undefined value', () => {
140
+ const error: EjvError | null = ejv({
141
+ a: undefined
142
+ }, [{
143
+ key: 'a',
144
+ type: 'string',
145
+ optional: true
146
+ }]);
147
+
148
+ expect(error).to.be.null;
149
+ });
150
+
151
+ it('correct type', () => {
152
+ const error: EjvError | null = ejv({
153
+ a: 'abc'
154
+ }, [{
155
+ key: 'a',
156
+ type: 'string',
157
+ optional: true
158
+ }]);
159
+
160
+ expect(error).to.be.null;
161
+ });
162
+
163
+ it('incorrect type', () => {
164
+ const data = {
165
+ a: 123
166
+ };
167
+
168
+ const error: EjvError | null = ejv(data, [{
169
+ key: 'a',
170
+ type: 'string',
171
+ optional: true
172
+ }]);
173
+
174
+ expect(error).to.be.instanceof(EjvError);
175
+
176
+ if (!error) {
177
+ throw new Error('spec failed');
178
+ }
179
+
180
+ expect(error.type).to.be.eql(ErrorType.TYPE_MISMATCH);
181
+ expect(error.message).to.be.eql(createErrorMsg(ErrorMsg.TYPE_MISMATCH, {
182
+ placeholders: ['string']
183
+ }));
184
+ expect(error.path).to.be.eql('a');
185
+ expect(error.data).to.be.deep.equal(data);
186
+ expect(error.errorData).to.be.eql(123);
187
+ });
188
+ });
189
+ });
190
+
191
+ describe('nullable', () => {
192
+ it('default', () => {
193
+ const data = {
194
+ a: null
195
+ };
196
+
197
+ const error: EjvError | null = ejv(data, [{
198
+ key: 'a',
199
+ type: 'string'
200
+ }]);
201
+
202
+ expect(error).to.be.instanceof(EjvError);
203
+
204
+ if (!error) {
205
+ throw new Error('spec failed');
206
+ }
207
+
208
+ expect(error.type).to.be.eql(ErrorType.REQUIRED);
209
+ expect(error.message).to.be.eql(createErrorMsg(ErrorMsg.REQUIRED));
210
+ expect(error.path).to.be.eql('a');
211
+ expect(error.data).to.be.deep.equal(data);
212
+ expect(error.errorData).to.be.null;
213
+ });
214
+
215
+ it('nullable === false', () => {
216
+ const data = {
217
+ a: null
218
+ };
219
+
220
+ const error: EjvError | null = ejv(data, [{
221
+ key: 'a',
222
+ type: 'string',
223
+ nullable: false
224
+ }]);
225
+
226
+ expect(error).to.be.instanceof(EjvError);
227
+
228
+ if (!error) {
229
+ throw new Error('spec failed');
230
+ }
231
+
232
+ expect(error.type).to.be.eql(ErrorType.REQUIRED);
233
+ expect(error.message).to.be.eql(createErrorMsg(ErrorMsg.REQUIRED));
234
+ expect(error.path).to.be.eql('a');
235
+ expect(error.data).to.be.deep.equal(data);
236
+ expect(error.errorData).to.be.null;
237
+ });
238
+
239
+ it('nullable === true', () => {
240
+ const error: EjvError | null = ejv({
241
+ a: null
242
+ }, [{
243
+ key: 'a',
244
+ type: 'string',
245
+ nullable: true
246
+ }]);
247
+
248
+ expect(error).to.be.null;
249
+ });
250
+ });
251
+ });
@@ -0,0 +1,472 @@
1
+ import { describe, it } from 'mocha';
2
+ import { expect } from 'chai';
3
+
4
+ import { ejv } from '../src/ejv';
5
+
6
+ import { DateScheme, EjvError, Scheme } from '../src/interfaces';
7
+ import { ErrorMsg, ErrorType } from '../src/constants';
8
+ import { createErrorMsg } from '../src/util';
9
+ import { checkSchemeError, TypeTester, typeTesterArr } from './common-test-util';
10
+
11
+
12
+ describe('DateScheme', () => {
13
+ const now: Date = new Date();
14
+
15
+ const year: number = now.getFullYear();
16
+ const month: number = now.getMonth();
17
+ const date: number = now.getDate();
18
+
19
+ const hours: number = now.getHours();
20
+ const minutes: number = now.getMinutes();
21
+ const seconds: number = now.getSeconds();
22
+ const ms: number = now.getMilliseconds();
23
+
24
+ const nowOnlyDate: Date = new Date();
25
+ nowOnlyDate.setHours(0, 0, 0, 0);
26
+
27
+
28
+ const TestCases: Date[] = [
29
+ // dates
30
+ new Date(year, month, date - 1),
31
+ new Date(year, month, date),
32
+ new Date(year, month, date + 1),
33
+
34
+ // with time
35
+ new Date(year, month, date, hours, minutes, seconds, ms - 1),
36
+ new Date(year, month, date, hours, minutes, seconds, ms),
37
+ new Date(year, month, date, hours, minutes, seconds, ms + 1)
38
+ ];
39
+
40
+ type ResultDefine = {
41
+ scheme: Partial<DateScheme>;
42
+
43
+ error: null | keyof typeof ErrorType;
44
+ placeholder?: string;
45
+ }
46
+
47
+
48
+ function checkError (defines: ResultDefine[]): void {
49
+ if (defines.length !== TestCases.length) {
50
+ throw new Error('invalid spec');
51
+ }
52
+
53
+ defines.forEach((define: ResultDefine, i: number): void => {
54
+ const checkValue: Date = i < 3 ? nowOnlyDate : now;
55
+
56
+ const result: EjvError | null = ejv({
57
+ date: checkValue
58
+ }, [{
59
+ key: 'date',
60
+ type: 'date',
61
+
62
+ ...define.scheme
63
+ }]);
64
+
65
+ if (define.error === null) {
66
+ expect(result).to.be.null;
67
+ }
68
+ else {
69
+ expect(result).to.be.instanceOf(EjvError);
70
+
71
+ if (!result) {
72
+ throw new Error('spec failed');
73
+ }
74
+
75
+ expect(result.type).to.be.eql(ErrorType[define.error]);
76
+ expect(result.message).to.eql(createErrorMsg(ErrorMsg[define.error as keyof typeof ErrorMsg], {
77
+ placeholders: [define.placeholder || '']
78
+ }));
79
+ expect(result.path).to.be.eql('date');
80
+ expect(result.errorData).to.be.instanceof(Date);
81
+ expect(result.errorData).to.be.eql(checkValue);
82
+ }
83
+ });
84
+ }
85
+
86
+
87
+ describe('type', () => {
88
+ describe('mismatch', () => {
89
+ typeTesterArr
90
+ .filter((obj: TypeTester): boolean => obj.type !== 'date')
91
+ .forEach((obj: TypeTester): void => {
92
+ const data = {
93
+ a: obj.value
94
+ };
95
+
96
+ it(obj.type, () => {
97
+ const error: EjvError | null = ejv(data, [{
98
+ key: 'a',
99
+ type: 'date'
100
+ }]);
101
+
102
+ expect(error).to.be.instanceof(EjvError);
103
+
104
+ if (!error) {
105
+ throw new Error('spec failed');
106
+ }
107
+
108
+ expect(error.type).to.be.eql(ErrorType.TYPE_MISMATCH);
109
+ expect(error.message).to.be.eql(createErrorMsg(ErrorMsg.TYPE_MISMATCH, {
110
+ placeholders: ['date']
111
+ }));
112
+ expect(error.path).to.be.eql('a');
113
+ expect(error.data).to.be.deep.equal(data);
114
+ expect(error.errorData).to.be.eql(obj.value);
115
+ });
116
+ });
117
+
118
+ it('multiple types', () => {
119
+ const value = 'ejv';
120
+ const typeArr: string[] = ['boolean', 'date'];
121
+
122
+ const data = {
123
+ a: value
124
+ };
125
+
126
+ const error: EjvError | null = ejv(data, [{
127
+ key: 'a',
128
+ type: typeArr
129
+ }]);
130
+
131
+ expect(error).to.be.instanceof(EjvError);
132
+
133
+ if (!error) {
134
+ throw new Error('spec failed');
135
+ }
136
+
137
+ expect(error.type).to.be.eql(ErrorType.TYPE_MISMATCH_ONE_OF);
138
+ expect(error.message).to.be.eql(createErrorMsg(ErrorMsg.TYPE_MISMATCH_ONE_OF, {
139
+ placeholders: [JSON.stringify(typeArr)]
140
+ }));
141
+ expect(error.path).to.be.eql('a');
142
+ expect(error.data).to.be.deep.equal(data);
143
+ expect(error.errorData).to.be.eql(value);
144
+ });
145
+ });
146
+
147
+ describe('match', () => {
148
+ it('optional', () => {
149
+ expect(ejv({
150
+ a: undefined
151
+ }, [{
152
+ key: 'a',
153
+ type: 'date',
154
+ optional: true
155
+ }])).to.be.null;
156
+ });
157
+
158
+ it('single type', () => {
159
+ expect(ejv({
160
+ a: new Date
161
+ }, [{
162
+ key: 'a',
163
+ type: 'date'
164
+ }])).to.be.null;
165
+ });
166
+
167
+ it('multiple types', () => {
168
+ expect(ejv({
169
+ a: new Date
170
+ }, [{
171
+ key: 'a',
172
+ type: ['date', 'number']
173
+ }])).to.be.null;
174
+ });
175
+
176
+ it('multiple types', () => {
177
+ expect(ejv({
178
+ a: new Date
179
+ }, [{
180
+ key: 'a',
181
+ type: ['number', 'date']
182
+ }])).to.be.null;
183
+ });
184
+ });
185
+ });
186
+
187
+ describe('min & exclusiveMin', () => {
188
+ describe('min only', () => {
189
+ describe('check parameter', () => {
190
+ const data = {
191
+ date: new Date()
192
+ };
193
+
194
+ it('undefined is ok', () => {
195
+ expect(ejv(data, [{
196
+ key: 'date',
197
+ type: 'date',
198
+ min: undefined
199
+ }])).to.be.null;
200
+ });
201
+
202
+ it('null', () => {
203
+ const errorScheme: Scheme = {
204
+ key: 'date',
205
+ type: 'date',
206
+ min: null as unknown as string
207
+ };
208
+
209
+ checkSchemeError({
210
+ data,
211
+ errorScheme,
212
+ message: createErrorMsg(ErrorMsg.MIN_DATE_SHOULD_BE_DATE_OR_STRING)
213
+ });
214
+ });
215
+
216
+ it('min type', () => {
217
+ const errorScheme: Scheme = {
218
+ key: 'date',
219
+ type: 'date',
220
+ min: 123 as unknown as string
221
+ };
222
+
223
+ checkSchemeError({
224
+ data,
225
+ errorScheme,
226
+ message: createErrorMsg(ErrorMsg.MIN_DATE_SHOULD_BE_DATE_OR_STRING)
227
+ });
228
+ });
229
+ });
230
+
231
+ it('by date', () => {
232
+ checkError(TestCases.map((one: Date, i: number): ResultDefine => {
233
+ const result: ResultDefine = {
234
+ scheme: {
235
+ min: one
236
+ },
237
+ error: null
238
+ };
239
+
240
+ if ([2, 5].includes(i)) {
241
+ result.error = ErrorType.AFTER_OR_SAME_DATE;
242
+ result.placeholder = one.toISOString();
243
+ }
244
+
245
+ return result;
246
+ }));
247
+ });
248
+
249
+ it('by date string', () => {
250
+ checkError(TestCases.map((one: Date, i: number): ResultDefine => {
251
+ const result: ResultDefine = {
252
+ scheme: {
253
+ min: one.toISOString()
254
+ },
255
+ error: null
256
+ };
257
+
258
+ if ([2, 5].includes(i)) {
259
+ result.error = ErrorType.AFTER_OR_SAME_DATE;
260
+ result.placeholder = one.toISOString();
261
+ }
262
+
263
+ return result;
264
+ }));
265
+ });
266
+ });
267
+
268
+ describe('exclusiveMin', () => {
269
+ describe('check parameter', () => {
270
+ it('exclusiveMin type', () => {
271
+ const data = {
272
+ date: new Date()
273
+ };
274
+
275
+ const errorScheme: Scheme = {
276
+ key: 'date',
277
+ type: 'date',
278
+ min: now,
279
+ exclusiveMin: now.toISOString() as unknown as boolean
280
+ };
281
+
282
+ checkSchemeError({
283
+ data,
284
+ errorScheme,
285
+ message: createErrorMsg(ErrorMsg.EXCLUSIVE_MIN_SHOULD_BE_BOOLEAN)
286
+ });
287
+ });
288
+ });
289
+
290
+ it('exclusiveMin === true', () => {
291
+ checkError(TestCases.map((one: Date, i: number): ResultDefine => {
292
+ const result: ResultDefine = {
293
+ scheme: {
294
+ min: one,
295
+ exclusiveMin: true
296
+ },
297
+ error: null
298
+ };
299
+
300
+ if ([1, 2, 4, 5].includes(i)) {
301
+ result.error = ErrorType.AFTER_DATE;
302
+ result.placeholder = one.toISOString();
303
+ }
304
+
305
+ return result;
306
+ }));
307
+ });
308
+
309
+ it('exclusiveMin === false', () => {
310
+ checkError(TestCases.map((one: Date, i: number): ResultDefine => {
311
+ const result: ResultDefine = {
312
+ scheme: {
313
+ min: one,
314
+ exclusiveMin: false
315
+ },
316
+ error: null
317
+ };
318
+
319
+ if ([2, 5].includes(i)) {
320
+ result.error = ErrorType.AFTER_OR_SAME_DATE;
321
+ result.placeholder = one.toISOString();
322
+ }
323
+
324
+ return result;
325
+ }));
326
+ });
327
+ });
328
+
329
+ describe('max & exclusiveMax', () => {
330
+ describe('max only', () => {
331
+ describe('check parameter', () => {
332
+ const data = {
333
+ date: new Date()
334
+ };
335
+
336
+ it('undefined is ok', () => {
337
+ expect(ejv(data, [{
338
+ key: 'date',
339
+ type: 'date',
340
+ max: undefined
341
+ }])).to.be.null;
342
+ });
343
+
344
+ it('null', () => {
345
+ const errorScheme: Scheme = {
346
+ key: 'date',
347
+ type: 'date',
348
+ max: null as unknown as string
349
+ };
350
+
351
+ checkSchemeError({
352
+ data,
353
+ errorScheme,
354
+ message: createErrorMsg(ErrorMsg.MAX_DATE_SHOULD_BE_DATE_OR_STRING)
355
+ });
356
+ });
357
+
358
+ it('max type', () => {
359
+ const errorScheme: Scheme = {
360
+ key: 'date',
361
+ type: 'date',
362
+ max: 123 as unknown as string
363
+ };
364
+
365
+ checkSchemeError({
366
+ data,
367
+ errorScheme,
368
+ message: createErrorMsg(ErrorMsg.MAX_DATE_SHOULD_BE_DATE_OR_STRING)
369
+ });
370
+ });
371
+ });
372
+
373
+ it('by date', () => {
374
+ checkError(TestCases.map((one: Date, i: number): ResultDefine => {
375
+ const result: ResultDefine = {
376
+ scheme: {
377
+ max: one
378
+ },
379
+ error: null
380
+ };
381
+
382
+ if ([0, 3].includes(i)) {
383
+ result.error = ErrorType.BEFORE_OR_SAME_DATE;
384
+ result.placeholder = one.toISOString();
385
+ }
386
+
387
+ return result;
388
+ }));
389
+ });
390
+
391
+ it('by date string', () => {
392
+ checkError(TestCases.map((one: Date, i: number): ResultDefine => {
393
+ const result: ResultDefine = {
394
+ scheme: {
395
+ max: one.toISOString()
396
+ },
397
+ error: null
398
+ };
399
+
400
+ if ([0, 3].includes(i)) {
401
+ result.error = ErrorType.BEFORE_OR_SAME_DATE;
402
+ result.placeholder = one.toISOString();
403
+ }
404
+
405
+ return result;
406
+ }));
407
+ });
408
+ });
409
+
410
+ describe('exclusiveMax', () => {
411
+ describe('check parameter', () => {
412
+ it('exclusiveMax type', () => {
413
+ const data = {
414
+ date: new Date()
415
+ };
416
+
417
+ const errorScheme: Scheme = {
418
+ key: 'date',
419
+ type: 'date',
420
+ max: now,
421
+ exclusiveMax: now.toISOString() as unknown as boolean
422
+ };
423
+
424
+ checkSchemeError({
425
+ data,
426
+ errorScheme,
427
+ message: createErrorMsg(ErrorMsg.EXCLUSIVE_MAX_SHOULD_BE_BOOLEAN)
428
+ });
429
+ });
430
+ });
431
+
432
+ it('exclusiveMax === true', () => {
433
+ checkError(TestCases.map((one: Date, i: number): ResultDefine => {
434
+ const result: ResultDefine = {
435
+ scheme: {
436
+ max: one,
437
+ exclusiveMax: true
438
+ },
439
+ error: null
440
+ };
441
+
442
+ if ([0, 1, 3, 4].includes(i)) {
443
+ result.error = ErrorType.BEFORE_DATE;
444
+ result.placeholder = one.toISOString();
445
+ }
446
+
447
+ return result;
448
+ }));
449
+ });
450
+
451
+ it('exclusiveMax === false', () => {
452
+ checkError(TestCases.map((one: Date, i: number): ResultDefine => {
453
+ const result: ResultDefine = {
454
+ scheme: {
455
+ max: one,
456
+ exclusiveMax: false
457
+ },
458
+ error: null
459
+ };
460
+
461
+ if ([0, 3].includes(i)) {
462
+ result.error = ErrorType.BEFORE_OR_SAME_DATE;
463
+ result.placeholder = one.toISOString();
464
+ }
465
+
466
+ return result;
467
+ }));
468
+ });
469
+ });
470
+ });
471
+ });
472
+ });