@availity/yup 3.1.1 → 3.2.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/CHANGELOG.md +11 -0
- package/README.md +2 -2
- package/lib/dateRange.js +4 -4
- package/package.json +12 -18
- package/src/date.js +4 -16
- package/src/dateRange.js +26 -50
- package/src/index.js +2 -2
- package/src/phone.js +1 -2
- package/{typings → types}/date.d.ts +2 -7
- package/{typings → types}/dateRange.d.ts +3 -9
- package/{typings → types}/index.d.ts +2 -4
- package/tests/date.test.js +0 -172
- package/tests/dateRange.test.js +0 -97
- package/tests/isRequired.test.js +0 -52
- package/tests/npi.test.js +0 -77
- package/tests/phone.test.js +0 -62
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 3.2.0 (2021-10-22)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **yup:** switch to lodash from merge-options-es5 ([06456c9](https://github.com/Availity/sdk-js/commit/06456c90ac6ef7523c4ed0d2e4dc9af8c4a6dee5))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [3.1.1](https://github.com/Availity/sdk-js/compare/@availity/yup@3.1.0...@availity/yup@3.1.1) (2021-06-16)
|
|
7
18
|
|
|
8
19
|
|
package/README.md
CHANGED
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
### NPM
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
|
|
12
|
+
npm install @availity/yup yup
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
### Yarn
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
|
-
|
|
18
|
+
yarn add @availity/yup yup
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## [Documentation](https://availity.github.io/sdk-js/resources/yup)
|
package/lib/dateRange.js
CHANGED
|
@@ -23,11 +23,11 @@ var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
|
|
|
23
23
|
|
|
24
24
|
var _moment = _interopRequireDefault(require("moment"));
|
|
25
25
|
|
|
26
|
-
var _get = _interopRequireDefault(require("lodash/get"));
|
|
27
|
-
|
|
28
26
|
var _yup = require("yup");
|
|
29
27
|
|
|
30
|
-
var
|
|
28
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
29
|
+
|
|
30
|
+
var _merge2 = _interopRequireDefault(require("lodash/merge"));
|
|
31
31
|
|
|
32
32
|
var defaultOptions = {
|
|
33
33
|
startKey: 'startDate',
|
|
@@ -50,7 +50,7 @@ var DateRangeSchema = /*#__PURE__*/function (_mixed) {
|
|
|
50
50
|
type: 'dateRange'
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
var _merge = (0,
|
|
53
|
+
var _merge = (0, _merge2["default"])({}, defaultOptions, options),
|
|
54
54
|
startKey = _merge.startKey,
|
|
55
55
|
endKey = _merge.endKey,
|
|
56
56
|
format = _merge.format;
|
package/package.json
CHANGED
|
@@ -1,37 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@availity/yup",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Additional Methods for Yup validation library",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
7
|
-
"
|
|
8
|
-
"scripts": {
|
|
9
|
-
"test": "test"
|
|
10
|
-
},
|
|
7
|
+
"types": "types/index.d.ts",
|
|
11
8
|
"keywords": [
|
|
12
|
-
"
|
|
13
|
-
"resumable",
|
|
14
|
-
"upload",
|
|
9
|
+
"yup",
|
|
15
10
|
"availity"
|
|
16
11
|
],
|
|
17
12
|
"author": "Kyle Gray <kyle.gray@availity.com>",
|
|
18
13
|
"license": "MIT",
|
|
19
|
-
"peerDependencies": {
|
|
20
|
-
"moment": "^2.24.0",
|
|
21
|
-
"yup": "^0.28.1"
|
|
22
|
-
},
|
|
23
14
|
"publishConfig": {
|
|
24
15
|
"access": "public"
|
|
25
16
|
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@babel/runtime": "^7.10.2",
|
|
19
|
+
"core-js": "^3.12.1",
|
|
20
|
+
"lodash": "^4.17.21"
|
|
21
|
+
},
|
|
26
22
|
"devDependencies": {
|
|
27
23
|
"moment": "^2.24.0",
|
|
28
24
|
"yup": "^0.28.1"
|
|
29
25
|
},
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"lodash": "^4.17.21",
|
|
34
|
-
"merge-options-es5": "^1.0.0"
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"moment": "^2.24.0",
|
|
28
|
+
"yup": "^0.28.1"
|
|
35
29
|
},
|
|
36
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "a247c20c27816eb3e3b68b983d12631a6cadd72b"
|
|
37
31
|
}
|
package/src/date.js
CHANGED
|
@@ -42,8 +42,7 @@ export default class AvDateSchema extends mixed {
|
|
|
42
42
|
const minDate = this.getValidDate(min);
|
|
43
43
|
|
|
44
44
|
return this.test({
|
|
45
|
-
message:
|
|
46
|
-
message || `Date must be ${minDate.format(this.format)} or later.`,
|
|
45
|
+
message: message || `Date must be ${minDate.format(this.format)} or later.`,
|
|
47
46
|
name: 'min',
|
|
48
47
|
exclusive: true,
|
|
49
48
|
params: { min },
|
|
@@ -60,8 +59,7 @@ export default class AvDateSchema extends mixed {
|
|
|
60
59
|
const maxDate = this.getValidDate(max);
|
|
61
60
|
|
|
62
61
|
return this.test({
|
|
63
|
-
message:
|
|
64
|
-
message || `Date must be ${maxDate.format(this.format)} or earlier.`,
|
|
62
|
+
message: message || `Date must be ${maxDate.format(this.format)} or earlier.`,
|
|
65
63
|
name: 'max',
|
|
66
64
|
exclusive: true,
|
|
67
65
|
params: { max },
|
|
@@ -99,19 +97,9 @@ export default class AvDateSchema extends mixed {
|
|
|
99
97
|
name: 'between',
|
|
100
98
|
exclusive: true, // Validation errors don't stack
|
|
101
99
|
// NOTE: Intentional use of single quotes - yup will handle the string interpolation
|
|
102
|
-
message:
|
|
103
|
-
msg ||
|
|
104
|
-
`Date must be between ${minDate.format(
|
|
105
|
-
this.format
|
|
106
|
-
)} and ${maxDate.format(this.format)}.`,
|
|
100
|
+
message: msg || `Date must be between ${minDate.format(this.format)} and ${maxDate.format(this.format)}.`,
|
|
107
101
|
test(value) {
|
|
108
|
-
if (
|
|
109
|
-
!value ||
|
|
110
|
-
!min ||
|
|
111
|
-
!max ||
|
|
112
|
-
!minDate.isValid() ||
|
|
113
|
-
!maxDate.isValid()
|
|
114
|
-
) {
|
|
102
|
+
if (!value || !min || !max || !minDate.isValid() || !maxDate.isValid()) {
|
|
115
103
|
return true;
|
|
116
104
|
}
|
|
117
105
|
|
package/src/dateRange.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import moment from 'moment';
|
|
2
|
-
import get from 'lodash/get';
|
|
3
2
|
import { mixed, ValidationError } from 'yup';
|
|
4
|
-
import
|
|
3
|
+
import get from 'lodash/get';
|
|
4
|
+
import merge from 'lodash/merge';
|
|
5
5
|
|
|
6
6
|
const defaultOptions = {
|
|
7
7
|
startKey: 'startDate',
|
|
@@ -64,16 +64,8 @@ export default class DateRangeSchema extends mixed {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
distance({
|
|
67
|
-
min: {
|
|
68
|
-
|
|
69
|
-
units: minUnits = 'day',
|
|
70
|
-
errorMessage: minErrorMessage,
|
|
71
|
-
} = {},
|
|
72
|
-
max: {
|
|
73
|
-
value: maxValue,
|
|
74
|
-
units: maxUnits = 'day',
|
|
75
|
-
errorMessage: maxErrorMessage,
|
|
76
|
-
} = {},
|
|
67
|
+
min: { value: minValue, units: minUnits = 'day', errorMessage: minErrorMessage } = {},
|
|
68
|
+
max: { value: maxValue, units: maxUnits = 'day', errorMessage: maxErrorMessage } = {},
|
|
77
69
|
} = defaultValue) {
|
|
78
70
|
return this.test({
|
|
79
71
|
name: 'distance',
|
|
@@ -82,28 +74,24 @@ export default class DateRangeSchema extends mixed {
|
|
|
82
74
|
if ((!minValue && !maxValue) || !startDate || !endDate) return true;
|
|
83
75
|
|
|
84
76
|
if (maxValue && endDate.isAfter(startDate.add(maxValue, maxUnits), 'day')) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
);
|
|
96
|
-
}
|
|
77
|
+
return new ValidationError(
|
|
78
|
+
maxErrorMessage ||
|
|
79
|
+
`The end date must be within ${maxValue} ${maxUnits}${maxValue > 1 ? 's' : ''} of the start date`,
|
|
80
|
+
{
|
|
81
|
+
startDate,
|
|
82
|
+
endDate,
|
|
83
|
+
},
|
|
84
|
+
this.path
|
|
85
|
+
);
|
|
86
|
+
}
|
|
97
87
|
if (minValue && endDate.isBefore(startDate.add(minValue, minUnits), 'day')) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
);
|
|
106
|
-
}
|
|
88
|
+
return new ValidationError(
|
|
89
|
+
minErrorMessage ||
|
|
90
|
+
`The end date must be greater than ${minValue} ${minUnits}${minValue > 1 ? 's' : ''} of the start date`,
|
|
91
|
+
{ startDate, endDate },
|
|
92
|
+
this.path
|
|
93
|
+
);
|
|
94
|
+
}
|
|
107
95
|
|
|
108
96
|
return true;
|
|
109
97
|
},
|
|
@@ -115,9 +103,7 @@ export default class DateRangeSchema extends mixed {
|
|
|
115
103
|
|
|
116
104
|
const minDate = this.getValidDate(min);
|
|
117
105
|
return this.test({
|
|
118
|
-
message:
|
|
119
|
-
message ||
|
|
120
|
-
`Date Range must start on or after ${minDate.format(format)}`,
|
|
106
|
+
message: message || `Date Range must start on or after ${minDate.format(format)}`,
|
|
121
107
|
name: 'min',
|
|
122
108
|
exclusive: true,
|
|
123
109
|
params: { min },
|
|
@@ -136,8 +122,7 @@ export default class DateRangeSchema extends mixed {
|
|
|
136
122
|
const maxDate = this.getValidDate(max);
|
|
137
123
|
|
|
138
124
|
return this.test({
|
|
139
|
-
message:
|
|
140
|
-
message || `Date Range must end on or before ${maxDate.format(format)}`,
|
|
125
|
+
message: message || `Date Range must end on or before ${maxDate.format(format)}`,
|
|
141
126
|
name: 'max',
|
|
142
127
|
exclusive: true,
|
|
143
128
|
params: { max },
|
|
@@ -155,21 +140,14 @@ export default class DateRangeSchema extends mixed {
|
|
|
155
140
|
const maxDate = this.getValidDate(max);
|
|
156
141
|
|
|
157
142
|
return this.test({
|
|
158
|
-
message:
|
|
159
|
-
message ||
|
|
160
|
-
`Date Range must be between ${minDate.format(
|
|
161
|
-
format
|
|
162
|
-
)} and ${maxDate.format(format)}`,
|
|
143
|
+
message: message || `Date Range must be between ${minDate.format(format)} and ${maxDate.format(format)}`,
|
|
163
144
|
name: 'between',
|
|
164
145
|
exclusive: true,
|
|
165
146
|
params: { min, max },
|
|
166
147
|
test({ startDate, endDate } = defaultValue) {
|
|
167
148
|
if (!startDate || !endDate || !min || !max) return true;
|
|
168
149
|
return (
|
|
169
|
-
maxDate.isValid() &&
|
|
170
|
-
minDate.isValid() &&
|
|
171
|
-
maxDate.isSameOrAfter(endDate) &&
|
|
172
|
-
minDate.isSameOrBefore(startDate)
|
|
150
|
+
maxDate.isValid() && minDate.isValid() && maxDate.isSameOrAfter(endDate) && minDate.isSameOrBefore(startDate)
|
|
173
151
|
);
|
|
174
152
|
},
|
|
175
153
|
});
|
|
@@ -205,9 +183,7 @@ export default class DateRangeSchema extends mixed {
|
|
|
205
183
|
errors.push('End Date is invalid.');
|
|
206
184
|
}
|
|
207
185
|
|
|
208
|
-
return errors.length > 0
|
|
209
|
-
? new ValidationError(errors, { startDate, endDate }, this.path)
|
|
210
|
-
: true;
|
|
186
|
+
return errors.length > 0 ? new ValidationError(errors, { startDate, endDate }, this.path) : true;
|
|
211
187
|
},
|
|
212
188
|
});
|
|
213
189
|
}
|
package/src/index.js
CHANGED
|
@@ -5,8 +5,8 @@ import phone from './phone';
|
|
|
5
5
|
import AvDate from './date';
|
|
6
6
|
import DateRange from './dateRange';
|
|
7
7
|
|
|
8
|
-
export const avDate = opts => new AvDate(opts);
|
|
9
|
-
export const dateRange = opts => new DateRange(opts);
|
|
8
|
+
export const avDate = (opts) => new AvDate(opts);
|
|
9
|
+
export const dateRange = (opts) => new DateRange(opts);
|
|
10
10
|
|
|
11
11
|
addMethod(string, 'isRequired', isRequired);
|
|
12
12
|
addMethod(number, 'isRequired', isRequired);
|
package/src/phone.js
CHANGED
|
@@ -5,15 +5,10 @@ declare module 'yup' {
|
|
|
5
5
|
format?: string | 'MM/DD/YYYY';
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
interface AvDateSchema<T extends string | null | undefined = string>
|
|
9
|
-
extends MixedSchema<T> {
|
|
8
|
+
interface AvDateSchema<T extends string | null | undefined = string> extends MixedSchema<T> {
|
|
10
9
|
min(date: string, errorMessage?: string): DateRangeSchema<T>;
|
|
11
10
|
max(date: string, errorMessage?: string): DateRangeSchema<T>;
|
|
12
|
-
between(
|
|
13
|
-
minDate: string,
|
|
14
|
-
maxDate: string,
|
|
15
|
-
errorMessage?: string
|
|
16
|
-
): AvDateSchema<T>;
|
|
11
|
+
between(minDate: string, maxDate: string, errorMessage?: string): AvDateSchema<T>;
|
|
17
12
|
isRequired(required?: boolean, errorMessage?: string): AvDateSchema<T>;
|
|
18
13
|
}
|
|
19
14
|
|
|
@@ -23,18 +23,12 @@ declare module 'yup' {
|
|
|
23
23
|
max?: DistanceValue;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
interface DateRangeSchema<
|
|
27
|
-
T extends DateRangeObject | null | undefined = DateRangeObject
|
|
28
|
-
> extends MixedSchema<T> {
|
|
26
|
+
interface DateRangeSchema<T extends DateRangeObject | null | undefined = DateRangeObject> extends MixedSchema<T> {
|
|
29
27
|
min(date: string, errorMessage?: string): DateRangeSchema<T>;
|
|
30
28
|
max(date: string, errorMessage?: string): DateRangeSchema<T>;
|
|
31
|
-
between(
|
|
32
|
-
minDate: string,
|
|
33
|
-
maxDate: string,
|
|
34
|
-
errorMessage?: string
|
|
35
|
-
): DateRangeSchema<T>;
|
|
29
|
+
between(minDate: string, maxDate: string, errorMessage?: string): DateRangeSchema<T>;
|
|
36
30
|
isRequired(required?: boolean, errorMessage?: string): DateRangeSchema<T>;
|
|
37
|
-
distance(distanceOpts: DistanceOpts)
|
|
31
|
+
distance(distanceOpts: DistanceOpts): DateRangeSchema<T>;
|
|
38
32
|
}
|
|
39
33
|
|
|
40
34
|
export interface DateRangeSchemaConstructor {
|
|
@@ -3,8 +3,7 @@ import './dateRange.d.ts';
|
|
|
3
3
|
import './date.d.ts';
|
|
4
4
|
|
|
5
5
|
declare module 'yup' {
|
|
6
|
-
interface StringSchema<T extends string | null | undefined = string>
|
|
7
|
-
extends Schema<T> {
|
|
6
|
+
interface StringSchema<T extends string | null | undefined = string> extends Schema<T> {
|
|
8
7
|
isRequired(required?: boolean, errorMessage?: string): StringSchema<T>;
|
|
9
8
|
npi(errorMessage?: string): StringSchema<T>;
|
|
10
9
|
phone(errorMessage?: string): StringSchema<T>;
|
|
@@ -14,8 +13,7 @@ declare module 'yup' {
|
|
|
14
13
|
isRequired(required?: boolean, errorMessage?: string): ArraySchema<T>;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
interface NumberSchema<T extends number | null | undefined = number>
|
|
18
|
-
extends Schema<T> {
|
|
16
|
+
interface NumberSchema<T extends number | null | undefined = number> extends Schema<T> {
|
|
19
17
|
isRequired(required?: boolean, errorMessage?: string): NumberSchema<T>;
|
|
20
18
|
npi(errorMessage?: string): NumberSchema<T>;
|
|
21
19
|
phone(errorMessage?: string): NumberSchema<T>;
|
package/tests/date.test.js
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { avDate } from '../src';
|
|
2
|
-
|
|
3
|
-
const INVALID = 'Date is invalid.';
|
|
4
|
-
|
|
5
|
-
const defaults = {};
|
|
6
|
-
|
|
7
|
-
const validate = async (
|
|
8
|
-
date,
|
|
9
|
-
{ format, min, max, message, inclusivity, customErrorMessage } = defaults
|
|
10
|
-
) => {
|
|
11
|
-
let schema = avDate({
|
|
12
|
-
format,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
if (min && !max) {
|
|
16
|
-
schema = schema.min(min, message);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (max && !min) {
|
|
20
|
-
schema = schema.max(max, message);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (min && max) {
|
|
24
|
-
schema = inclusivity
|
|
25
|
-
? schema.between(min, max, message, inclusivity)
|
|
26
|
-
: schema.between(min, max, message);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (customErrorMessage) {
|
|
30
|
-
schema = schema.typeError(customErrorMessage);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return schema.validate(date);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
describe('Date', () => {
|
|
37
|
-
test('valid', async () => {
|
|
38
|
-
await expect(validate('12/12/2012')).resolves.toBeTruthy();
|
|
39
|
-
await expect(validate('12-12-2012')).resolves.toBeTruthy();
|
|
40
|
-
await expect(
|
|
41
|
-
validate('2012/12/12', { format: 'YYYY/MM/DD' })
|
|
42
|
-
).resolves.toBeTruthy();
|
|
43
|
-
await expect(
|
|
44
|
-
validate('20121212', { format: 'YYYYMMDD' })
|
|
45
|
-
).resolves.toBeTruthy();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('invalid', async () => {
|
|
49
|
-
await expect(validate('2012')).rejects.toThrow(INVALID);
|
|
50
|
-
await expect(validate('12-2012')).rejects.toThrow(INVALID);
|
|
51
|
-
await expect(validate('12-2012-12')).rejects.toThrow(INVALID);
|
|
52
|
-
await expect(validate('invalid-date')).rejects.toThrow(INVALID);
|
|
53
|
-
await expect(validate('01/01/20011')).rejects.toThrow(INVALID);
|
|
54
|
-
|
|
55
|
-
// Allow user to clear date field without showing typeError
|
|
56
|
-
await expect(validate('')).resolves.toBeTruthy();
|
|
57
|
-
|
|
58
|
-
// With custom message
|
|
59
|
-
await expect(
|
|
60
|
-
validate('invalid-date', { customErrorMessage: 'custom error message' })
|
|
61
|
-
).rejects.toThrow('custom error message');
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('min date', async () => {
|
|
65
|
-
await expect(
|
|
66
|
-
validate('12/12/2012', {
|
|
67
|
-
min: '12/11/2012',
|
|
68
|
-
})
|
|
69
|
-
).resolves.toBeTruthy();
|
|
70
|
-
|
|
71
|
-
await expect(
|
|
72
|
-
validate('12/12/2012', {
|
|
73
|
-
min: '12/12/2012',
|
|
74
|
-
})
|
|
75
|
-
).resolves.toBeTruthy();
|
|
76
|
-
|
|
77
|
-
await expect(
|
|
78
|
-
validate('12/10/2012', {
|
|
79
|
-
min: '12/11/2012',
|
|
80
|
-
})
|
|
81
|
-
).rejects.toThrow(`Date must be 12/11/2012 or later.`);
|
|
82
|
-
|
|
83
|
-
await expect(
|
|
84
|
-
validate('2012/12/12', {
|
|
85
|
-
min: '2012/12/11',
|
|
86
|
-
format: 'YYYY/MM/DD',
|
|
87
|
-
})
|
|
88
|
-
).resolves.toBeTruthy();
|
|
89
|
-
|
|
90
|
-
await expect(
|
|
91
|
-
validate('2012/12/10', {
|
|
92
|
-
min: '2012/12/11',
|
|
93
|
-
format: 'YYYY/MM/DD',
|
|
94
|
-
})
|
|
95
|
-
).rejects.toThrow();
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test('max date', async () => {
|
|
99
|
-
await expect(
|
|
100
|
-
validate('12/11/2012', {
|
|
101
|
-
max: '12/12/2012',
|
|
102
|
-
})
|
|
103
|
-
).resolves.toBeTruthy();
|
|
104
|
-
|
|
105
|
-
await expect(
|
|
106
|
-
validate('12/12/2012', {
|
|
107
|
-
max: '12/12/2012',
|
|
108
|
-
})
|
|
109
|
-
).resolves.toBeTruthy();
|
|
110
|
-
|
|
111
|
-
await expect(
|
|
112
|
-
validate('12/12/2012', {
|
|
113
|
-
max: '12/11/2012',
|
|
114
|
-
})
|
|
115
|
-
).rejects.toThrow(`Date must be 12/11/2012 or earlier.`);
|
|
116
|
-
|
|
117
|
-
await expect(
|
|
118
|
-
validate('2012/12/11', {
|
|
119
|
-
max: '2012/12/11',
|
|
120
|
-
format: 'YYYY/MM/DD',
|
|
121
|
-
})
|
|
122
|
-
).resolves.toBeTruthy();
|
|
123
|
-
|
|
124
|
-
await expect(
|
|
125
|
-
validate('2012/12/12', {
|
|
126
|
-
max: '2012/12/11',
|
|
127
|
-
format: 'YYYY/MM/DD',
|
|
128
|
-
})
|
|
129
|
-
).rejects.toThrow();
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
test('between', async () => {
|
|
133
|
-
await expect(
|
|
134
|
-
validate('12/11/2012', {
|
|
135
|
-
max: '12/12/2012',
|
|
136
|
-
min: '12/10/2012',
|
|
137
|
-
})
|
|
138
|
-
).resolves.toBeTruthy();
|
|
139
|
-
|
|
140
|
-
await expect(
|
|
141
|
-
validate('12/12/2012', {
|
|
142
|
-
min: '12/12/2012',
|
|
143
|
-
max: '12/13/2012',
|
|
144
|
-
})
|
|
145
|
-
).rejects.toThrow(`Date must be between 12/12/2012 and 12/13/2012.`);
|
|
146
|
-
|
|
147
|
-
await expect(
|
|
148
|
-
validate('2012/12/11', {
|
|
149
|
-
max: '2012/12/13',
|
|
150
|
-
min: '2012/12/10',
|
|
151
|
-
format: 'YYYY/MM/DD',
|
|
152
|
-
})
|
|
153
|
-
).resolves.toBeTruthy();
|
|
154
|
-
|
|
155
|
-
await expect(
|
|
156
|
-
validate('2012/12/13', {
|
|
157
|
-
min: '2012/12/11',
|
|
158
|
-
max: '2012/12/12',
|
|
159
|
-
format: 'YYYY/MM/DD',
|
|
160
|
-
})
|
|
161
|
-
).rejects.toThrow();
|
|
162
|
-
|
|
163
|
-
await expect(
|
|
164
|
-
validate('2012/12/12', {
|
|
165
|
-
max: '2012/12/12',
|
|
166
|
-
min: '2012/12/10',
|
|
167
|
-
format: 'YYYY/MM/DD',
|
|
168
|
-
inclusivity: '(]',
|
|
169
|
-
})
|
|
170
|
-
).resolves.toBeTruthy();
|
|
171
|
-
});
|
|
172
|
-
});
|
package/tests/dateRange.test.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { dateRange } from '../src';
|
|
2
|
-
|
|
3
|
-
describe('DateRange', () => {
|
|
4
|
-
test('start comes before end', async () => {
|
|
5
|
-
const schema = dateRange();
|
|
6
|
-
|
|
7
|
-
await expect(
|
|
8
|
-
schema.validate({
|
|
9
|
-
startDate: '12/14/2012',
|
|
10
|
-
endDate: '12/13/2012',
|
|
11
|
-
})
|
|
12
|
-
).rejects.toThrow('Start date must come before end date.');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('Invalid Dates', async () => {
|
|
16
|
-
const schema = dateRange();
|
|
17
|
-
|
|
18
|
-
await expect(
|
|
19
|
-
schema.validate({
|
|
20
|
-
startDate: '',
|
|
21
|
-
endDate: '12/14/2012',
|
|
22
|
-
})
|
|
23
|
-
).rejects.toThrow('Start and End Date are required.');
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('defines min', async () => {
|
|
27
|
-
const schema = dateRange().min('12/12/2012');
|
|
28
|
-
|
|
29
|
-
const valid = await schema.isValid({
|
|
30
|
-
startDate: '12/13/2012',
|
|
31
|
-
endDate: '12/14/2012',
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
expect(valid).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('errors on invalid', async () => {
|
|
38
|
-
const schema = dateRange().min('12/12/2012');
|
|
39
|
-
|
|
40
|
-
const valid = await schema.isValid({
|
|
41
|
-
startDate: '12/11/2012',
|
|
42
|
-
endDate: '12/13/2012',
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
expect(valid).toBe(false);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('date', () => {
|
|
50
|
-
test('should validate', async () => {
|
|
51
|
-
const schema = dateRange().between('12/10/2012', '12/13/2012');
|
|
52
|
-
|
|
53
|
-
const valid = await schema.isValid({
|
|
54
|
-
startDate: '12/11/2012',
|
|
55
|
-
endDate: '12/12/2012',
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
expect(valid).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('should work with custom value keys', async () => {
|
|
62
|
-
const schema = dateRange({
|
|
63
|
-
startKey: 'helloDate',
|
|
64
|
-
endKey: 'worldDate',
|
|
65
|
-
}).between('12/10/2012', '12/13/2012');
|
|
66
|
-
|
|
67
|
-
const valid = await schema.isValid({
|
|
68
|
-
helloDate: '12/11/2012',
|
|
69
|
-
worldDate: '12/12/2012',
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
expect(valid).toBe(true);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('should validate distance', async () => {
|
|
76
|
-
const schema = dateRange().distance({
|
|
77
|
-
min: {
|
|
78
|
-
value: 5,
|
|
79
|
-
units: 'day',
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
let valid = await schema.isValid({
|
|
84
|
-
startDate: '12/11/2012',
|
|
85
|
-
endDate: '12/13/2012',
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
expect(valid).toBe(false);
|
|
89
|
-
|
|
90
|
-
valid = await schema.isValid({
|
|
91
|
-
startDate: '12/11/2012',
|
|
92
|
-
endDate: '12/18/2012',
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
expect(valid).toBe(true);
|
|
96
|
-
});
|
|
97
|
-
});
|
package/tests/isRequired.test.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { array, number, string } from 'yup';
|
|
2
|
-
import '../src';
|
|
3
|
-
|
|
4
|
-
describe('isRequired', () => {
|
|
5
|
-
test('should return error on empty input', async () => {
|
|
6
|
-
const schema = string().isRequired();
|
|
7
|
-
|
|
8
|
-
const valid = await schema.isValid('');
|
|
9
|
-
|
|
10
|
-
expect(valid).toBe(false);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test('should return error on no number', async () => {
|
|
14
|
-
const schema = number().isRequired();
|
|
15
|
-
|
|
16
|
-
const valid = await schema.isValid(null);
|
|
17
|
-
|
|
18
|
-
expect(valid).toBe(false);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('should return error on empty array', async () => {
|
|
22
|
-
const schema = array().isRequired();
|
|
23
|
-
|
|
24
|
-
const valid = await schema.isValid([]);
|
|
25
|
-
|
|
26
|
-
expect(valid).toBe(false);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('should accept null input', async () => {
|
|
30
|
-
const schema = string()
|
|
31
|
-
.isRequired(true)
|
|
32
|
-
.nullable();
|
|
33
|
-
|
|
34
|
-
const valid = await schema.isValid(null);
|
|
35
|
-
|
|
36
|
-
expect(valid).toBe(true);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('should accept input', async () => {
|
|
40
|
-
const schema = string().isRequired(true);
|
|
41
|
-
|
|
42
|
-
const valid = await schema.isValid('Test');
|
|
43
|
-
|
|
44
|
-
expect(valid).toBe(true);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
test('should render custom error message', async () => {
|
|
48
|
-
const schema = string().isRequired(true, 'Test Error Message');
|
|
49
|
-
|
|
50
|
-
await expect(schema.validate()).rejects.toThrow('Test Error Message');
|
|
51
|
-
});
|
|
52
|
-
});
|
package/tests/npi.test.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { number, string } from 'yup';
|
|
2
|
-
import '../src';
|
|
3
|
-
|
|
4
|
-
describe('npi', () => {
|
|
5
|
-
test('should be valid for empty input', async () => {
|
|
6
|
-
const schema = string().npi();
|
|
7
|
-
|
|
8
|
-
const valid = await schema.isValid('');
|
|
9
|
-
|
|
10
|
-
expect(valid).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
test('should be valid for no number', async () => {
|
|
14
|
-
const schema = number().npi();
|
|
15
|
-
|
|
16
|
-
const valid = await schema.isValid();
|
|
17
|
-
|
|
18
|
-
expect(valid).toBe(true);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('should accept null input', async () => {
|
|
22
|
-
const schema = string()
|
|
23
|
-
.npi()
|
|
24
|
-
.nullable();
|
|
25
|
-
|
|
26
|
-
const valid = await schema.isValid(null);
|
|
27
|
-
|
|
28
|
-
expect(valid).toBe(true);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('should be invalid for invalid input', async () => {
|
|
32
|
-
const schema = string().npi();
|
|
33
|
-
|
|
34
|
-
const valid = await schema.isValid('1234');
|
|
35
|
-
|
|
36
|
-
expect(valid).toBe(false);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('should be invalid if NPI contains non-digits', async () => {
|
|
40
|
-
const schema = number().npi();
|
|
41
|
-
const valid = await schema.isValid('i2eh56789o');
|
|
42
|
-
expect(valid).toBe(false);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('should be invalid if NPI is not 10 digits in length', async () => {
|
|
46
|
-
const schema = number().npi();
|
|
47
|
-
let valid = await schema.isValid('123456789');
|
|
48
|
-
expect(valid).toBe(false);
|
|
49
|
-
|
|
50
|
-
valid = await schema.isValid('12345678901');
|
|
51
|
-
expect(valid).toBe(false);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('should be invalid if NPI does not start with a 1, 2, 3, or 4', async () => {
|
|
55
|
-
const schema = number().npi();
|
|
56
|
-
const valid = await schema.isValid('5678901234');
|
|
57
|
-
expect(valid).toBe(false);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test('should be invalid if NPI checksum does not match check digit', async () => {
|
|
61
|
-
const schema = number().npi();
|
|
62
|
-
const valid = await schema.isValid('1234567890');
|
|
63
|
-
expect(valid).toBe(false);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('should be valid if NPI is valid', async () => {
|
|
67
|
-
const schema = number().npi();
|
|
68
|
-
const valid = await schema.isValid('1234567893');
|
|
69
|
-
expect(valid).toBe(true);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('should render custom error message', async () => {
|
|
73
|
-
const schema = number().npi('Test Error Message');
|
|
74
|
-
|
|
75
|
-
await expect(schema.validate('123')).rejects.toThrow('Test Error Message');
|
|
76
|
-
});
|
|
77
|
-
});
|
package/tests/phone.test.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { number, string } from 'yup';
|
|
2
|
-
import '../src';
|
|
3
|
-
|
|
4
|
-
describe('phone', () => {
|
|
5
|
-
test('should accept empty string', async () => {
|
|
6
|
-
const schema = string().phone();
|
|
7
|
-
const valid = await schema.isValid('');
|
|
8
|
-
expect(valid).toBe(true);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('should accept no number', async () => {
|
|
12
|
-
const schema = number().phone();
|
|
13
|
-
const valid = await schema.isValid();
|
|
14
|
-
expect(valid).toBe(true);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('should accept null input', async () => {
|
|
18
|
-
const schema = string()
|
|
19
|
-
.phone()
|
|
20
|
-
.nullable();
|
|
21
|
-
const valid = await schema.isValid();
|
|
22
|
-
expect(valid).toBe(true);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('should not accept less than 10 digits', async () => {
|
|
26
|
-
const schema = number().phone();
|
|
27
|
-
const valid = await schema.isValid('123456789');
|
|
28
|
-
expect(valid).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('should accept country code of "+1" and variations', async () => {
|
|
32
|
-
const schema = string().phone();
|
|
33
|
-
expect(await schema.isValid('+14444444444')).toBe(true);
|
|
34
|
-
expect(await schema.isValid('14444444444')).toBe(true);
|
|
35
|
-
expect(await schema.isValid('+1 4444444444')).toBe(true);
|
|
36
|
-
expect(await schema.isValid('1 4444444444')).toBe(true);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test('must be 10 digits without country code', async () => {
|
|
40
|
-
const schema = number().phone();
|
|
41
|
-
expect(await schema.isValid('4444444444')).toBe(true);
|
|
42
|
-
expect(await schema.isValid('444 444 4444')).toBe(true);
|
|
43
|
-
expect(await schema.isValid('44444444445')).toBe(false);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('can be formatted', async () => {
|
|
47
|
-
const schema = string().phone();
|
|
48
|
-
expect(await schema.isValid('(444) 444-4444')).toBe(true);
|
|
49
|
-
expect(await schema.isValid('+1 (444) 444-4444')).toBe(true);
|
|
50
|
-
expect(await schema.isValid('444-444-4444')).toBe(true);
|
|
51
|
-
expect(await schema.isValid('+1 444-444-4444')).toBe(true);
|
|
52
|
-
expect(await schema.isValid('444.444.4444')).toBe(true);
|
|
53
|
-
expect(await schema.isValid('(444) 444 4444')).toBe(true);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('should display custom error message', async () => {
|
|
57
|
-
const schema = number().phone('Custom Error Message');
|
|
58
|
-
await expect(schema.validate('123321')).rejects.toThrow(
|
|
59
|
-
'Custom Error Message'
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
});
|