@strictly/define 0.0.8 → 0.0.9
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/.out/index.d.ts +2 -0
- package/.out/index.js +2 -0
- package/.out/transformers/flatteners/flatten_type_to.d.ts +1 -1
- package/.out/transformers/flatteners/flatten_type_to.js +1 -1
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/types/builders.d.ts +1 -2
- package/.out/types/builders.js +3 -7
- package/.out/validation/validator.d.ts +9 -7
- package/.out/validation/validator.js +6 -0
- package/.out/validation/validators/minimum_string_length_validator.js +1 -1
- package/.out/validation/validators/optional_validator_proxy.d.ts +13 -0
- package/.out/validation/validators/optional_validator_proxy.js +26 -0
- package/.out/validation/validators/regexp_validator.d.ts +29 -0
- package/.out/validation/validators/regexp_validator.js +37 -0
- package/.out/validation/validators/specs/minimum_string_length_validator.tests.d.ts +1 -0
- package/.out/validation/validators/specs/minimum_string_length_validator.tests.js +69 -0
- package/.out/validation/validators/specs/regexp_validator.tests.d.ts +1 -0
- package/.out/validation/validators/specs/regexp_validator.tests.js +98 -0
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-release$colon$exports.log +1 -1
- package/dist/index.cjs +87 -8
- package/dist/index.d.cts +53 -10
- package/dist/index.d.ts +53 -10
- package/dist/index.js +83 -8
- package/index.ts +2 -0
- package/package.json +1 -1
- package/transformers/flatteners/flatten_type_to.ts +2 -2
- package/types/builders.ts +4 -13
- package/validation/validator.ts +13 -4
- package/validation/validators/minimum_string_length_validator.ts +1 -1
- package/validation/validators/optional_validator_proxy.ts +52 -0
- package/validation/validators/regexp_validator.ts +61 -0
- package/validation/validators/specs/minimum_string_length_validator.tests.ts +76 -0
- package/validation/validators/specs/regexp_validator.tests.ts +108 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RegexpValidationErrorType,
|
|
3
|
+
RegexpValidator,
|
|
4
|
+
} from 'validation/validators/regexp_validator'
|
|
5
|
+
|
|
6
|
+
describe('RegexpValidator', () => {
|
|
7
|
+
describe('phone', () => {
|
|
8
|
+
it.each([
|
|
9
|
+
'0403545000',
|
|
10
|
+
'+12 (1800) 000 000',
|
|
11
|
+
'1-2-3-4-5-6',
|
|
12
|
+
'+1 394 3234 000 (2)',
|
|
13
|
+
'1234',
|
|
14
|
+
])('accepts "%s"', (phoneNumber) => {
|
|
15
|
+
expect(RegexpValidator.phone.validate(phoneNumber)).toBeNull()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it.each([
|
|
19
|
+
'',
|
|
20
|
+
'ABC',
|
|
21
|
+
'1',
|
|
22
|
+
' 0412345678',
|
|
23
|
+
'----1245456',
|
|
24
|
+
'1 2',
|
|
25
|
+
'234234+234',
|
|
26
|
+
])('rejects "%s"', (phoneNumber) => {
|
|
27
|
+
expect(RegexpValidator.phone.validate(phoneNumber)).toEqual({
|
|
28
|
+
type: RegexpValidationErrorType,
|
|
29
|
+
intent: 'phone',
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('email', () => {
|
|
35
|
+
it.each([
|
|
36
|
+
'x@y.z',
|
|
37
|
+
'support@company.com',
|
|
38
|
+
'...@......',
|
|
39
|
+
'1234@3454.23',
|
|
40
|
+
])('accepts "%s"', (email) => {
|
|
41
|
+
expect(RegexpValidator.email.validate(email)).toBeNull()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it.each([
|
|
45
|
+
'',
|
|
46
|
+
'@@@@',
|
|
47
|
+
'email',
|
|
48
|
+
'@bee.com',
|
|
49
|
+
'aaa@bbb',
|
|
50
|
+
'a a@b b.c c',
|
|
51
|
+
])('rejects "%s"', (email) => {
|
|
52
|
+
expect(RegexpValidator.email.validate(email)).toEqual({
|
|
53
|
+
type: RegexpValidationErrorType,
|
|
54
|
+
intent: 'email',
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
describe('required', () => {
|
|
60
|
+
it.each([
|
|
61
|
+
true,
|
|
62
|
+
false,
|
|
63
|
+
])('exposes required %s', (required) => {
|
|
64
|
+
const validator = new RegexpValidator(/a/, 'test', {
|
|
65
|
+
required,
|
|
66
|
+
})
|
|
67
|
+
expect(validator.annotations().required).toBe(required)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('general', () => {
|
|
72
|
+
// not here to test if regexp works
|
|
73
|
+
it.each([
|
|
74
|
+
[
|
|
75
|
+
'^a$',
|
|
76
|
+
'a',
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
'^\\w+$',
|
|
80
|
+
'asdf',
|
|
81
|
+
],
|
|
82
|
+
])('passes validation with regexp "%s" and value "%s"', (regexpString, value) => {
|
|
83
|
+
const regexp = new RegExp(regexpString)
|
|
84
|
+
const validator = new RegexpValidator(regexp, 'test')
|
|
85
|
+
expect(validator.validate(value)).toBeNull()
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it.each([
|
|
89
|
+
[
|
|
90
|
+
'^$',
|
|
91
|
+
'something',
|
|
92
|
+
'empty',
|
|
93
|
+
],
|
|
94
|
+
[
|
|
95
|
+
'^\\w+$',
|
|
96
|
+
'',
|
|
97
|
+
'non-empty',
|
|
98
|
+
],
|
|
99
|
+
])('fails validation with regexp "%s" and value "%s', (regexpString, value, intent) => {
|
|
100
|
+
const regexp = new RegExp(regexpString)
|
|
101
|
+
const validator = new RegexpValidator(regexp, intent)
|
|
102
|
+
expect(validator.validate(value)).toEqual({
|
|
103
|
+
type: RegexpValidationErrorType,
|
|
104
|
+
intent,
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
})
|