@fincity/kirun-js 1.4.13 → 1.4.14

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.
@@ -0,0 +1,299 @@
1
+ import {
2
+ KIRunSchemaRepository,
3
+ Schema,
4
+ SchemaType,
5
+ SchemaValidator,
6
+ StringFormat,
7
+ Type,
8
+ TypeUtil,
9
+ } from '../../../../../src';
10
+
11
+ const repo = new KIRunSchemaRepository();
12
+
13
+ test('Schema Validator fail with date test', () => {
14
+ let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.INTEGER));
15
+
16
+ expect(SchemaValidator.validate([], schema, repo, 2)).toBe(2);
17
+
18
+ let obj = { name: 'shagil' };
19
+ let objSchema: Schema = Schema.ofObject('testObj')
20
+ .setProperties(
21
+ new Map<string, Schema>([
22
+ ['name', Schema.ofString('name')],
23
+ ['date', new Schema().setFormat(StringFormat.DATE)],
24
+ ]),
25
+ )
26
+ .setRequired(['name', 'date']);
27
+
28
+ expect(() => SchemaValidator.validate([], objSchema, repo, obj)).toThrow('date is mandatory');
29
+ const dateObj = { name: 'surendhar.s', date: '1999-13-12' };
30
+ const errorMsg =
31
+ 'Value {"name":"surendhar.s","date":"1999-13-12"} is not of valid type(s)' +
32
+ '\n' +
33
+ 'Type is missing in schema for declared DATE format.';
34
+
35
+ expect(() => SchemaValidator.validate([], objSchema, repo, dateObj)).toThrow(errorMsg);
36
+ });
37
+
38
+ test('Schema Validator pass with date test ', () => {
39
+ let intSchema: Schema = new Schema().setType(TypeUtil.of(SchemaType.INTEGER)).setMinimum(100);
40
+
41
+ let objSchema: Schema = Schema.ofObject('testObj')
42
+ .setProperties(
43
+ new Map<string, Schema>([
44
+ ['intSchema', intSchema],
45
+ ['name', Schema.ofString('name')],
46
+ [
47
+ 'date',
48
+ new Schema()
49
+ .setFormat(StringFormat.DATE)
50
+ .setType(TypeUtil.of(SchemaType.STRING)),
51
+ ],
52
+ ]),
53
+ )
54
+ .setRequired(['intSchema', 'date']);
55
+
56
+ const dateObj = { intSchema: 1231, date: '1999-09-12' };
57
+
58
+ expect(SchemaValidator.validate([], objSchema, repo, dateObj)).toBe(dateObj);
59
+ });
60
+
61
+ test('Schema Validator fail with time string type missing test ', () => {
62
+ let intSchema: Schema = new Schema()
63
+ .setType(TypeUtil.of(SchemaType.INTEGER))
64
+ .setMaximum(100)
65
+ .setMultipleOf(5);
66
+
67
+ let objSchema: Schema = Schema.ofObject('testObj')
68
+ .setProperties(
69
+ new Map<string, Schema>([
70
+ ['intSchema', intSchema],
71
+ ['name', Schema.ofString('name').setMinLength(10)],
72
+ ['time', new Schema().setFormat(StringFormat.TIME)],
73
+ ]),
74
+ )
75
+ .setRequired(['intSchema', 'time', 'name']);
76
+
77
+ const timeObj = { intSchema: 95, time: '22:23:61', name: 's.surendhar' };
78
+
79
+ const errMsg =
80
+ 'Value {"intSchema":95,"time":"22:23:61","name":"s.surendhar"} is not of valid type(s)\n' +
81
+ 'Type is missing in schema for declared TIME format.';
82
+
83
+ expect(() => SchemaValidator.validate([], objSchema, repo, timeObj)).toThrow(errMsg);
84
+ });
85
+
86
+ test('Schema Validator fail with time test ', () => {
87
+ let intSchema: Schema = new Schema()
88
+ .setType(TypeUtil.of(SchemaType.INTEGER))
89
+ .setMaximum(100)
90
+ .setMultipleOf(5);
91
+
92
+ let objSchema: Schema = Schema.ofObject('testObj')
93
+ .setProperties(
94
+ new Map<string, Schema>([
95
+ ['intSchema', intSchema],
96
+ ['name', Schema.ofString('name').setMinLength(10)],
97
+ [
98
+ 'time',
99
+ new Schema()
100
+ .setFormat(StringFormat.TIME)
101
+ .setType(TypeUtil.of(SchemaType.STRING)),
102
+ ],
103
+ ]),
104
+ )
105
+ .setRequired(['intSchema', 'time', 'name']);
106
+
107
+ const timeObj = { intSchema: 95, time: '22:23:61', name: 's.surendhar' };
108
+
109
+ const errMsg =
110
+ 'Value {"intSchema":95,"time":"22:23:61","name":"s.surendhar"} is not of valid type(s)\n' +
111
+ 'Value "22:23:61" is not of valid type(s)\n' +
112
+ '22:23:61 is not matched with the time pattern';
113
+
114
+ expect(() => SchemaValidator.validate([], objSchema, repo, timeObj)).toThrow(errMsg);
115
+ });
116
+
117
+ test('Schema Validator pass with time test ', () => {
118
+ let intSchema: Schema = new Schema()
119
+ .setType(TypeUtil.of(SchemaType.INTEGER))
120
+ .setMaximum(100)
121
+ .setMultipleOf(5);
122
+
123
+ let objSchema: Schema = Schema.ofObject('testObj')
124
+ .setProperties(
125
+ new Map<string, Schema>([
126
+ ['intSchema', intSchema],
127
+ ['name', Schema.ofString('name').setMinLength(10)],
128
+ [
129
+ 'time',
130
+ new Schema()
131
+ .setFormat(StringFormat.TIME)
132
+ .setType(TypeUtil.of(SchemaType.STRING)),
133
+ ],
134
+ ]),
135
+ )
136
+ .setRequired(['intSchema', 'time', 'name']);
137
+
138
+ const timeObj = { intSchema: 95, time: '22:23:24', name: 's.surendhar' };
139
+
140
+ expect(SchemaValidator.validate([], objSchema, repo, timeObj)).toBe(timeObj);
141
+ });
142
+
143
+ test('Schema Validator fail with email string type missing test ', () => {
144
+ let intSchema: Schema = new Schema().setType(TypeUtil.of(SchemaType.INTEGER)).setMaximum(100);
145
+
146
+ let objSchema: Schema = Schema.ofObject('testObj')
147
+ .setProperties(
148
+ new Map<string, Schema>([
149
+ ['intSchema', intSchema],
150
+ ['name', Schema.ofString('name').setMinLength(10)],
151
+ ['email', new Schema().setFormat(StringFormat.EMAIL)],
152
+ ]),
153
+ )
154
+ .setRequired(['intSchema', 'email', 'name']);
155
+
156
+ const emailObj = { intSchema: 95, email: 'iosdjfdf123--@gmail.com', name: 's.surendhar' };
157
+
158
+ const errMsg =
159
+ 'Value {"intSchema":95,"email":"iosdjfdf123--@gmail.com","name":"s.surendhar"} is not of valid type(s)\n' +
160
+ 'Type is missing in schema for declared EMAIL format.';
161
+
162
+ expect(() => SchemaValidator.validate([], objSchema, repo, emailObj)).toThrow(errMsg);
163
+ });
164
+
165
+ test('Schema Validator fail with email test ', () => {
166
+ let intSchema: Schema = new Schema()
167
+ .setType(TypeUtil.of(SchemaType.INTEGER))
168
+ .setMaximum(3)
169
+ .setMultipleOf(5);
170
+
171
+ let objSchema: Schema = Schema.ofObject('testObj')
172
+ .setProperties(
173
+ new Map<string, Schema>([
174
+ ['intSchema', intSchema],
175
+ ['name', Schema.ofString('name').setMinLength(10)],
176
+ [
177
+ 'email',
178
+ new Schema()
179
+ .setFormat(StringFormat.EMAIL)
180
+ .setType(TypeUtil.of(SchemaType.STRING)),
181
+ ],
182
+ ]),
183
+ )
184
+ .setRequired(['intSchema', 'email']);
185
+
186
+ const emailObj = { intSchema: 0, email: 'asdasdf@@*.com' };
187
+
188
+ const errMsg =
189
+ 'Value {"intSchema":0,"email":"asdasdf@@*.com"} is not of valid type(s)\n' +
190
+ 'Value "asdasdf@@*.com" is not of valid type(s)\n' +
191
+ 'asdasdf@@*.com is not matched with the email pattern';
192
+
193
+ expect(() => SchemaValidator.validate([], objSchema, repo, emailObj)).toThrow(errMsg);
194
+ });
195
+
196
+ test('Schema Validator pass with time test ', () => {
197
+ let intSchema: Schema = new Schema().setType(TypeUtil.of(SchemaType.INTEGER));
198
+
199
+ let objSchema: Schema = Schema.ofObject('testObj')
200
+ .setProperties(
201
+ new Map<string, Schema>([
202
+ ['intSchema', intSchema],
203
+ ['name', Schema.ofString('name').setMinLength(10)],
204
+ [
205
+ 'email',
206
+ new Schema()
207
+ .setFormat(StringFormat.EMAIL)
208
+ .setType(TypeUtil.of(SchemaType.STRING)),
209
+ ],
210
+ ]),
211
+ )
212
+ .setRequired(['intSchema', 'name']);
213
+
214
+ const emailObj = { intSchema: 95, email: 'surendhar.s@finc.c', name: 's.surendhar' };
215
+
216
+ expect(SchemaValidator.validate([], objSchema, repo, emailObj)).toBe(emailObj);
217
+ });
218
+
219
+ test('Schema Validator fail with dateTime string type missing test ', () => {
220
+ let intSchema: Schema = new Schema().setType(TypeUtil.of(SchemaType.INTEGER)).setMaximum(100);
221
+
222
+ let objSchema: Schema = Schema.ofObject('testObj')
223
+ .setProperties(
224
+ new Map<string, Schema>([
225
+ ['intSchema', intSchema],
226
+ ['name', Schema.ofString('name').setMinLength(10)],
227
+ ['dateTime', new Schema().setFormat(StringFormat.DATETIME)],
228
+ ]),
229
+ )
230
+ .setRequired(['intSchema', 'dateTime', 'name']);
231
+
232
+ const emailObj = { intSchema: 95, dateTime: '2023-08-21T07:56:45+12:12', name: 's.surendhar' };
233
+
234
+ const errMsg =
235
+ 'Value {"intSchema":95,"dateTime":"2023-08-21T07:56:45+12:12","name":"s.surendhar"} is not of valid type(s)\n' +
236
+ 'Type is missing in schema for declared DATETIME format.';
237
+
238
+ expect(() => SchemaValidator.validate([], objSchema, repo, emailObj)).toThrow(errMsg);
239
+ });
240
+
241
+ test('Schema Validator fail with dateTime test ', () => {
242
+ let intSchema: Schema = new Schema()
243
+ .setType(TypeUtil.of(SchemaType.INTEGER))
244
+ .setMaximum(3)
245
+ .setMultipleOf(5);
246
+
247
+ let objSchema: Schema = Schema.ofObject('testObj')
248
+ .setProperties(
249
+ new Map<string, Schema>([
250
+ ['intSchema', intSchema],
251
+ ['name', Schema.ofString('name').setMinLength(10)],
252
+ [
253
+ 'dateTime',
254
+ new Schema()
255
+ .setFormat(StringFormat.DATETIME)
256
+ .setType(TypeUtil.of(SchemaType.STRING)),
257
+ ],
258
+ ]),
259
+ )
260
+ .setRequired(['dateTime']);
261
+
262
+ const dateTimeObj = { dateTime: '2023-08-221T07:56:45+12:12' };
263
+
264
+ const errMsg =
265
+ 'Value {"dateTime":"2023-08-221T07:56:45+12:12"} is not of valid type(s)\n' +
266
+ 'Value "2023-08-221T07:56:45+12:12" is not of valid type(s)\n' +
267
+ '2023-08-221T07:56:45+12:12 is not matched with the date time pattern';
268
+
269
+ expect(() => SchemaValidator.validate([], objSchema, repo, dateTimeObj)).toThrow(errMsg);
270
+ });
271
+
272
+ test('Schema Validator pass with time test ', () => {
273
+ let intSchema: Schema = new Schema().setType(TypeUtil.of(SchemaType.INTEGER));
274
+
275
+ let objSchema: Schema = Schema.ofObject('testObj')
276
+ .setProperties(
277
+ new Map<string, Schema>([
278
+ ['intSchema', intSchema],
279
+ ['name', Schema.ofString('name').setMinLength(10)],
280
+ [
281
+ 'dateTime',
282
+ new Schema()
283
+ .setFormat(StringFormat.DATETIME)
284
+ .setType(TypeUtil.of(SchemaType.STRING)),
285
+ ],
286
+ ]),
287
+ )
288
+ .setRequired(['intSchema', 'dateTime']);
289
+
290
+ const dateTimeObj = {
291
+ intSchema: 95,
292
+ dateTime: '2023-08-21T07:56:45+12:12',
293
+ name: 's.surendhar',
294
+ };
295
+
296
+ expect(SchemaValidator.validate([], objSchema, repo, dateTimeObj)).toBe(dateTimeObj);
297
+ });
298
+
299
+ const dateTimeObj = { dateTime: '2023-08-21T07:56:45+12:12' };