@fincity/kirun-js 1.4.5 → 1.4.6

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,135 @@
1
+ import {
2
+ KIRunSchemaRepository,
3
+ Schema,
4
+ SchemaType,
5
+ StringFormat,
6
+ TypeUtil,
7
+ } from '../../../../../src';
8
+ import { StringValidator } from '../../../../../src';
9
+
10
+ const repo = new KIRunSchemaRepository();
11
+
12
+ test('String valid case', () => {
13
+ let value: String = 'surendhar';
14
+ let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.STRING));
15
+
16
+ expect(StringValidator.validate([], schema, value)).toBe(value);
17
+ });
18
+
19
+ test('String invalid case', () => {
20
+ let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.STRING));
21
+
22
+ expect(() => StringValidator.validate([], schema, 123).toThrow(123 + ' is not String'));
23
+ });
24
+
25
+ test('String min length invalid', () => {
26
+ let value: String = 'abcd';
27
+ let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.STRING)).setMinLength(5);
28
+
29
+ expect(() =>
30
+ StringValidator.validate([], schema, value).toThrow(
31
+ 'Expected a minimum of ' + value.length + ' characters',
32
+ ),
33
+ );
34
+ });
35
+
36
+ test('String max length invalid', () => {
37
+ let value: String = 'surendhar';
38
+ let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.STRING)).setMaxLength(8);
39
+
40
+ expect(() =>
41
+ StringValidator.validate([], schema, value).toThrow(
42
+ 'Expected a maximum of ' + value.length + ' characters',
43
+ ),
44
+ );
45
+ });
46
+
47
+ test('String min length', () => {
48
+ let value: String = 'abcdefg';
49
+ let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.STRING)).setMinLength(5);
50
+
51
+ expect(StringValidator.validate([], schema, value)).toBe(value);
52
+ });
53
+
54
+ test('String max length', () => {
55
+ let value: String = 'surendhar';
56
+ let schema: Schema = new Schema().setType(TypeUtil.of(SchemaType.STRING)).setMaxLength(12323);
57
+
58
+ expect(StringValidator.validate([], schema, value)).toBe(value);
59
+ });
60
+
61
+ test('String date invalid case', () => {
62
+ let value: String = '1234-12-1245';
63
+
64
+ let schema: Schema = new Schema().setFormat(StringFormat.DATE);
65
+
66
+ expect(() =>
67
+ StringValidator.validate([], schema, value).toThrow(
68
+ value + ' is not matched with the ' + 'date pattern',
69
+ ),
70
+ );
71
+ });
72
+
73
+ test('String date valid case', () => {
74
+ let value: String = '2023-01-26';
75
+
76
+ let schema: Schema = new Schema().setFormat(StringFormat.DATE);
77
+
78
+ expect(StringValidator.validate([], schema, value)).toBe(value);
79
+ });
80
+
81
+ test('String time invalid case', () => {
82
+ let value: String = '231:45:56';
83
+
84
+ let schema: Schema = new Schema().setFormat(StringFormat.TIME);
85
+
86
+ expect(() => StringValidator.validate([], schema, value)).toThrow(
87
+ value + ' is not matched with the ' + 'time pattern',
88
+ );
89
+ });
90
+
91
+ test('String time valid case', () => {
92
+ let value: String = '22:32:45';
93
+
94
+ let schema: Schema = new Schema().setFormat(StringFormat.TIME);
95
+
96
+ expect(StringValidator.validate([], schema, value)).toBe(value);
97
+ });
98
+
99
+ test('String date time invalid case', () => {
100
+ let value: String = '26-jan-2023 231:45:56';
101
+
102
+ let schema: Schema = new Schema().setFormat(StringFormat.DATETIME);
103
+
104
+ expect(() => StringValidator.validate([], schema, value)).toThrow(
105
+ value + ' is not matched with the ' + 'date time pattern',
106
+ );
107
+ });
108
+
109
+ test('String date time valid case', () => {
110
+ let value: String = '2032-02-12T02:54:23';
111
+
112
+ let schema: Schema = new Schema().setFormat(StringFormat.DATETIME);
113
+
114
+ expect(StringValidator.validate([], schema, value)).toBe(value);
115
+ });
116
+
117
+ test('String email invalid case', () => {
118
+ let value: String = 'testemail fai%6&8ls@gmail.com';
119
+
120
+ let schema: Schema = new Schema().setFormat(StringFormat.EMAIL);
121
+
122
+ expect(() => StringValidator.validate([], schema, value)).toThrow(
123
+ value + ' is not matched with the ' + 'email pattern',
124
+ );
125
+ });
126
+
127
+ test('String email valid case', () => {
128
+ let value: String = 'testemaifai%6&8lworkings@magil.com';
129
+
130
+ let schema: Schema = new Schema().setFormat(StringFormat.EMAIL);
131
+
132
+ console.log(StringValidator.validate([], schema, value));
133
+
134
+ expect(StringValidator.validate([], schema, value)).toBe(value);
135
+ });