@wix/metro-common-builders 1.0.1757 → 1.0.1758
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/dist/__tests__/merge-deep.spec.js +3 -3
- package/dist/__tests__/merge-deep.spec.js.map +1 -1
- package/dist/__tests__/value-generator.spec.js +116 -116
- package/dist/__tests__/value-generator.spec.js.map +1 -1
- package/dist/es/__tests__/merge-deep.spec.js +1 -1
- package/dist/es/__tests__/merge-deep.spec.js.map +1 -1
- package/dist/es/__tests__/value-generator.spec.js +4 -4
- package/dist/es/__tests__/value-generator.spec.js.map +1 -1
- package/dist/es/src/domain.d.ts +1 -1
- package/dist/es/src/domain.d.ts.map +1 -1
- package/dist/es/src/domain.js +1 -1
- package/dist/es/src/domain.js.map +1 -1
- package/dist/es/src/index.d.ts +6 -6
- package/dist/es/src/index.d.ts.map +1 -1
- package/dist/es/src/index.js +6 -6
- package/dist/es/src/index.js.map +1 -1
- package/dist/es/src/merge-deep.js +1 -1
- package/dist/es/src/merge-deep.js.map +1 -1
- package/dist/es/src/value-generator/validation-extractor.d.ts +1 -1
- package/dist/es/src/value-generator/validation-extractor.d.ts.map +1 -1
- package/dist/es/src/value-generator/validation-extractor.js +2 -2
- package/dist/es/src/value-generator/validation-extractor.js.map +1 -1
- package/dist/es/src/value-generator/value-generator-utils.d.ts +2 -2
- package/dist/es/src/value-generator/value-generator-utils.d.ts.map +1 -1
- package/dist/es/src/value-generator/value-generator-utils.js +2 -2
- package/dist/es/src/value-generator/value-generator-utils.js.map +1 -1
- package/dist/es/src/value-generator/value-generator.d.ts +2 -2
- package/dist/es/src/value-generator/value-generator.d.ts.map +1 -1
- package/dist/es/src/value-generator/value-generator.js +4 -4
- package/dist/es/src/value-generator/value-generator.js.map +1 -1
- package/dist/src/domain.d.ts +1 -1
- package/dist/src/domain.d.ts.map +1 -1
- package/dist/src/domain.js +2 -2
- package/dist/src/domain.js.map +1 -1
- package/dist/src/index.d.ts +6 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +8 -8
- package/dist/src/index.js.map +1 -1
- package/dist/src/merge-deep.js +2 -2
- package/dist/src/merge-deep.js.map +1 -1
- package/dist/src/value-generator/validation-extractor.d.ts +1 -1
- package/dist/src/value-generator/validation-extractor.d.ts.map +1 -1
- package/dist/src/value-generator/validation-extractor.js +17 -17
- package/dist/src/value-generator/validation-extractor.js.map +1 -1
- package/dist/src/value-generator/value-generator-utils.d.ts +2 -2
- package/dist/src/value-generator/value-generator-utils.d.ts.map +1 -1
- package/dist/src/value-generator/value-generator-utils.js +41 -41
- package/dist/src/value-generator/value-generator-utils.js.map +1 -1
- package/dist/src/value-generator/value-generator.d.ts +2 -2
- package/dist/src/value-generator/value-generator.d.ts.map +1 -1
- package/dist/src/value-generator/value-generator.js +32 -32
- package/dist/src/value-generator/value-generator.js.map +1 -1
- package/package.json +7 -4
|
@@ -2,55 +2,55 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
4
|
var long_1 = tslib_1.__importDefault(require("long"));
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
5
|
+
var domain_js_1 = require("../src/domain.js");
|
|
6
|
+
var index_js_1 = require("../src/index.js");
|
|
7
|
+
var constant_values_js_1 = require("../src/value-generator/constant-values.js");
|
|
8
|
+
var constants_js_1 = require("../src/value-generator/constants.js");
|
|
9
9
|
describe('Value generator', function () {
|
|
10
10
|
describe('Get generator type', function () {
|
|
11
11
|
it('should return string', function () {
|
|
12
|
-
expect((0,
|
|
12
|
+
expect((0, index_js_1.getGeneratorTypeForField)(getSimpleField(domain_js_1.Type.STRING))).toEqual(constants_js_1.GeneratorType.STRING);
|
|
13
13
|
});
|
|
14
14
|
it('should return number', function () {
|
|
15
|
-
var types = [
|
|
15
|
+
var types = [domain_js_1.Type.INT32, domain_js_1.Type.SINT32, domain_js_1.Type.DOUBLE];
|
|
16
16
|
types.forEach(function (type) {
|
|
17
|
-
return expect((0,
|
|
17
|
+
return expect((0, index_js_1.getGeneratorTypeForField)(getSimpleField(type))).toEqual(constants_js_1.GeneratorType.NUMBER);
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
20
|
it('should return string (int 64 numbers represented as string number)', function () {
|
|
21
|
-
var types = [
|
|
21
|
+
var types = [domain_js_1.Type.INT64, domain_js_1.Type.SINT64, domain_js_1.Type.FIXED64, domain_js_1.Type.SFIXED64];
|
|
22
22
|
types.forEach(function (type) {
|
|
23
|
-
return expect((0,
|
|
23
|
+
return expect((0, index_js_1.getGeneratorTypeForField)(getSimpleField(type))).toEqual(constants_js_1.GeneratorType.STRING);
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
26
|
it('should return float', function () {
|
|
27
|
-
var types = [
|
|
27
|
+
var types = [domain_js_1.Type.FLOAT, domain_js_1.Type.FIXED32, domain_js_1.Type.SFIXED32];
|
|
28
28
|
types.forEach(function (type) {
|
|
29
|
-
return expect((0,
|
|
29
|
+
return expect((0, index_js_1.getGeneratorTypeForField)(getSimpleField(type))).toEqual(constants_js_1.GeneratorType.FLOAT);
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
32
|
it('should return repeated', function () {
|
|
33
33
|
var types = ['google.protobuf.ListValue', 'google.protobuf.FieldMask'];
|
|
34
34
|
types.forEach(function (type) {
|
|
35
|
-
return expect((0,
|
|
35
|
+
return expect((0, index_js_1.getGeneratorTypeForField)(getComplexField(type))).toEqual(constants_js_1.GeneratorType.REPEATED);
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
it('should return duration', function () {
|
|
39
|
-
expect((0,
|
|
39
|
+
expect((0, index_js_1.getGeneratorTypeForField)(getComplexField('google.protobuf.Duration'))).toEqual(constants_js_1.GeneratorType.DURATION);
|
|
40
40
|
});
|
|
41
41
|
it('should return date', function () {
|
|
42
|
-
expect((0,
|
|
42
|
+
expect((0, index_js_1.getGeneratorTypeForField)(getComplexField('google.protobuf.Timestamp'))).toEqual(constants_js_1.GeneratorType.DATE);
|
|
43
43
|
});
|
|
44
44
|
it('should return bytes', function () {
|
|
45
45
|
var bytesProtoType = 'google.protobuf.BytesValue';
|
|
46
|
-
var bytesBusinessSchemaType =
|
|
47
|
-
expect((0,
|
|
48
|
-
expect((0,
|
|
46
|
+
var bytesBusinessSchemaType = domain_js_1.Type.BYTES;
|
|
47
|
+
expect((0, index_js_1.getGeneratorTypeForField)(getSimpleField(bytesBusinessSchemaType))).toEqual(constants_js_1.GeneratorType.BYTES);
|
|
48
|
+
expect((0, index_js_1.getGeneratorTypeForField)(getComplexField(bytesProtoType))).toEqual(constants_js_1.GeneratorType.BYTES);
|
|
49
49
|
});
|
|
50
50
|
it('should return other', function () {
|
|
51
51
|
var types = ['google.protobuf.BoolValue', 'google.protobuf.NullValue'];
|
|
52
52
|
types.forEach(function (type) {
|
|
53
|
-
return expect((0,
|
|
53
|
+
return expect((0, index_js_1.getGeneratorTypeForField)(getComplexField(type))).toEqual(constants_js_1.GeneratorType.OTHER);
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
56
|
it('should return any', function () {
|
|
@@ -61,7 +61,7 @@ describe('Value generator', function () {
|
|
|
61
61
|
'wix.rich_content.v1.Value', // TODO - remove when rich content create V2 without copy/paste google types
|
|
62
62
|
];
|
|
63
63
|
types.forEach(function (type) {
|
|
64
|
-
return expect((0,
|
|
64
|
+
return expect((0, index_js_1.getGeneratorTypeForField)(getComplexField(type))).toEqual(constants_js_1.GeneratorType.ANY);
|
|
65
65
|
});
|
|
66
66
|
});
|
|
67
67
|
function getSimpleField(type, validations) {
|
|
@@ -76,7 +76,7 @@ describe('Value generator', function () {
|
|
|
76
76
|
if (validations === void 0) { validations = []; }
|
|
77
77
|
return {
|
|
78
78
|
name: 'field_name',
|
|
79
|
-
type:
|
|
79
|
+
type: domain_js_1.Type.OBJECT,
|
|
80
80
|
schemaName: type,
|
|
81
81
|
validations: validations,
|
|
82
82
|
};
|
|
@@ -84,78 +84,78 @@ describe('Value generator', function () {
|
|
|
84
84
|
});
|
|
85
85
|
describe('Get function name by generator type', function () {
|
|
86
86
|
it('should return someString', function () {
|
|
87
|
-
expect((0,
|
|
87
|
+
expect((0, index_js_1.getGeneratorFunctionNameForGeneratorType)(constants_js_1.GeneratorType.STRING)).toEqual(constants_js_1.FunctionNames.SOME_STRING);
|
|
88
88
|
});
|
|
89
89
|
it('should return someBytes', function () {
|
|
90
|
-
expect((0,
|
|
90
|
+
expect((0, index_js_1.getGeneratorFunctionNameForGeneratorType)(constants_js_1.GeneratorType.BYTES)).toEqual(constants_js_1.FunctionNames.SOME_BYTES);
|
|
91
91
|
});
|
|
92
92
|
it('should return someAny', function () {
|
|
93
|
-
expect((0,
|
|
93
|
+
expect((0, index_js_1.getGeneratorFunctionNameForGeneratorType)(constants_js_1.GeneratorType.ANY)).toEqual(constants_js_1.FunctionNames.SOME_ANY);
|
|
94
94
|
});
|
|
95
95
|
});
|
|
96
96
|
describe('Generation functions', function () {
|
|
97
97
|
var min = 2;
|
|
98
98
|
var max = 20;
|
|
99
99
|
var minNumberValidation = {
|
|
100
|
-
type:
|
|
100
|
+
type: domain_js_1.ValidationType.MIN,
|
|
101
101
|
value: min,
|
|
102
102
|
};
|
|
103
103
|
var maxNumberValidation = {
|
|
104
|
-
type:
|
|
104
|
+
type: domain_js_1.ValidationType.MAX,
|
|
105
105
|
value: max,
|
|
106
106
|
};
|
|
107
107
|
describe('Strings', function () {
|
|
108
108
|
it('should generate strings', function () {
|
|
109
|
-
expect((0,
|
|
109
|
+
expect((0, index_js_1.someString)()).toEqual(constant_values_js_1.CONSTANT_VALUES.STRING);
|
|
110
110
|
});
|
|
111
111
|
it('should return a constant string if it satisfies the validations', function () {
|
|
112
112
|
var minLengthValidation = [
|
|
113
|
-
{ value: 10, type:
|
|
114
|
-
{ value: 30, type:
|
|
113
|
+
{ value: 10, type: domain_js_1.ValidationType.MIN_LENGTH },
|
|
114
|
+
{ value: 30, type: domain_js_1.ValidationType.MAX_LENGTH },
|
|
115
115
|
];
|
|
116
|
-
var value = (0,
|
|
117
|
-
expect(value).toEqual(
|
|
118
|
-
expect(value.length).toEqual(
|
|
116
|
+
var value = (0, index_js_1.someString)({ validations: minLengthValidation });
|
|
117
|
+
expect(value).toEqual(constant_values_js_1.CONSTANT_VALUES.STRING);
|
|
118
|
+
expect(value.length).toEqual(constant_values_js_1.CONSTANT_VALUES.STRING.length);
|
|
119
119
|
});
|
|
120
120
|
it('should repeat the string until desired min length', function () {
|
|
121
121
|
var minLength = 30;
|
|
122
122
|
var minLengthValidation = [
|
|
123
|
-
{ value: minLength, type:
|
|
123
|
+
{ value: minLength, type: domain_js_1.ValidationType.MIN_LENGTH },
|
|
124
124
|
];
|
|
125
|
-
var expectedValue =
|
|
126
|
-
var value = (0,
|
|
125
|
+
var expectedValue = constant_values_js_1.CONSTANT_VALUES.STRING.padEnd(minLength, constant_values_js_1.CONSTANT_VALUES.STRING);
|
|
126
|
+
var value = (0, index_js_1.someString)({ validations: minLengthValidation });
|
|
127
127
|
expect(value).toEqual(expectedValue);
|
|
128
128
|
expect(value.length).toEqual(minLength);
|
|
129
129
|
});
|
|
130
130
|
it('should trim the string if default is larger than max length', function () {
|
|
131
131
|
var maxLength = 10;
|
|
132
132
|
var maxLengthValidation = [
|
|
133
|
-
{ value: maxLength, type:
|
|
133
|
+
{ value: maxLength, type: domain_js_1.ValidationType.MAX_LENGTH },
|
|
134
134
|
];
|
|
135
|
-
var expectedValue =
|
|
136
|
-
var value = (0,
|
|
135
|
+
var expectedValue = constant_values_js_1.CONSTANT_VALUES.STRING.substring(0, maxLength);
|
|
136
|
+
var value = (0, index_js_1.someString)({ validations: maxLengthValidation });
|
|
137
137
|
expect(value).toEqual(expectedValue);
|
|
138
138
|
expect(value.length).toEqual(maxLength);
|
|
139
139
|
});
|
|
140
140
|
describe('Format', function () {
|
|
141
141
|
it('generates all formats', function () {
|
|
142
|
-
var allFormats = Object.keys(
|
|
142
|
+
var allFormats = Object.keys(constant_values_js_1.FORMAT_VALUES);
|
|
143
143
|
allFormats.forEach(function (format) {
|
|
144
|
-
var value = (0,
|
|
145
|
-
validations: [{ type:
|
|
144
|
+
var value = (0, index_js_1.someString)({
|
|
145
|
+
validations: [{ type: domain_js_1.ValidationType.FORMAT, value: format }],
|
|
146
146
|
});
|
|
147
|
-
expect(value).toEqual(
|
|
147
|
+
expect(value).toEqual(constant_values_js_1.FORMAT_VALUES[format]);
|
|
148
148
|
});
|
|
149
149
|
});
|
|
150
150
|
});
|
|
151
151
|
describe('with Decimal Value', function () {
|
|
152
152
|
var getDecimalValueValidation = function (value) { return ({
|
|
153
|
-
type:
|
|
153
|
+
type: domain_js_1.ValidationType.DECIMAL_VALUE,
|
|
154
154
|
value: value,
|
|
155
155
|
}); };
|
|
156
156
|
it('should use gte (greater then equal) as value for number', function () {
|
|
157
157
|
var decimalValueGreaterThanEqual = { gte: 1 };
|
|
158
|
-
var value = (0,
|
|
158
|
+
var value = (0, index_js_1.someString)({
|
|
159
159
|
validations: [
|
|
160
160
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
161
161
|
],
|
|
@@ -165,7 +165,7 @@ describe('Value generator', function () {
|
|
|
165
165
|
it('should use incremented gt (greater than) as value for number', function () {
|
|
166
166
|
var decimalValueGreaterThan = { gt: 1 };
|
|
167
167
|
var expected = (decimalValueGreaterThan.gt + 1).toString();
|
|
168
|
-
var value = (0,
|
|
168
|
+
var value = (0, index_js_1.someString)({
|
|
169
169
|
validations: [getDecimalValueValidation(decimalValueGreaterThan)],
|
|
170
170
|
});
|
|
171
171
|
expect(value).toEqual(expected);
|
|
@@ -173,7 +173,7 @@ describe('Value generator', function () {
|
|
|
173
173
|
it('should use incremented gt (greater than) as value even when lt and lte exist', function () {
|
|
174
174
|
var decimalValueGreaterThanLowerThan = { gt: 1, lte: 3, lt: 3 };
|
|
175
175
|
var expected = (decimalValueGreaterThanLowerThan.gt + 1).toString();
|
|
176
|
-
var value = (0,
|
|
176
|
+
var value = (0, index_js_1.someString)({
|
|
177
177
|
validations: [
|
|
178
178
|
getDecimalValueValidation(decimalValueGreaterThanLowerThan),
|
|
179
179
|
],
|
|
@@ -182,7 +182,7 @@ describe('Value generator', function () {
|
|
|
182
182
|
});
|
|
183
183
|
it('should use lte (lower than equal) as value', function () {
|
|
184
184
|
var decimalValueGreaterThanEqual = { lte: 2 };
|
|
185
|
-
var value = (0,
|
|
185
|
+
var value = (0, index_js_1.someString)({
|
|
186
186
|
validations: [
|
|
187
187
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
188
188
|
],
|
|
@@ -192,7 +192,7 @@ describe('Value generator', function () {
|
|
|
192
192
|
it('should use lt (lower than) decremented as value', function () {
|
|
193
193
|
var decimalValueGreaterThanEqual = { lt: 2 };
|
|
194
194
|
var expected = (decimalValueGreaterThanEqual.lt - 1).toString();
|
|
195
|
-
var value = (0,
|
|
195
|
+
var value = (0, index_js_1.someString)({
|
|
196
196
|
validations: [
|
|
197
197
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
198
198
|
],
|
|
@@ -201,7 +201,7 @@ describe('Value generator', function () {
|
|
|
201
201
|
});
|
|
202
202
|
it('should return float when maxScale is present with gte', function () {
|
|
203
203
|
var decimalValueGreaterThanEqual = { gte: 2, maxScale: 2 };
|
|
204
|
-
var value = (0,
|
|
204
|
+
var value = (0, index_js_1.someString)({
|
|
205
205
|
validations: [
|
|
206
206
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
207
207
|
],
|
|
@@ -210,7 +210,7 @@ describe('Value generator', function () {
|
|
|
210
210
|
});
|
|
211
211
|
it('should return float when maxScale is present with lte', function () {
|
|
212
212
|
var decimalValueGreaterThanEqual = { lte: 2, maxScale: 2 };
|
|
213
|
-
var value = (0,
|
|
213
|
+
var value = (0, index_js_1.someString)({
|
|
214
214
|
validations: [
|
|
215
215
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
216
216
|
],
|
|
@@ -224,7 +224,7 @@ describe('Value generator', function () {
|
|
|
224
224
|
maxScale: 2,
|
|
225
225
|
};
|
|
226
226
|
var expectedValue = (decimalValueGreaterThanEqual.gt + 0.01).toString();
|
|
227
|
-
var value = (0,
|
|
227
|
+
var value = (0, index_js_1.someString)({
|
|
228
228
|
validations: [
|
|
229
229
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
230
230
|
],
|
|
@@ -234,14 +234,14 @@ describe('Value generator', function () {
|
|
|
234
234
|
it('should decrement according to maxScale', function () {
|
|
235
235
|
var decimalValueLowerThan = { lt: 2, maxScale: 2 };
|
|
236
236
|
var expected = (decimalValueLowerThan.lt - 0.01).toString();
|
|
237
|
-
var value = (0,
|
|
237
|
+
var value = (0, index_js_1.someString)({
|
|
238
238
|
validations: [getDecimalValueValidation(decimalValueLowerThan)],
|
|
239
239
|
});
|
|
240
240
|
expect(value).toEqual(expected);
|
|
241
241
|
});
|
|
242
242
|
it('should support having only max scale', function () {
|
|
243
243
|
var decimalValueMaxScale = { maxScale: 2 };
|
|
244
|
-
var value = (0,
|
|
244
|
+
var value = (0, index_js_1.someString)({
|
|
245
245
|
validations: [getDecimalValueValidation(decimalValueMaxScale)],
|
|
246
246
|
});
|
|
247
247
|
expect(value).toEqual('-1337.00');
|
|
@@ -253,7 +253,7 @@ describe('Value generator', function () {
|
|
|
253
253
|
maxScale: 2,
|
|
254
254
|
};
|
|
255
255
|
var expectedValue = (parseFloat(decimalValueGreaterThanEqual.gt) + 0.01).toString();
|
|
256
|
-
var value = (0,
|
|
256
|
+
var value = (0, index_js_1.someString)({
|
|
257
257
|
validations: [
|
|
258
258
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
259
259
|
],
|
|
@@ -261,14 +261,14 @@ describe('Value generator', function () {
|
|
|
261
261
|
expect(value).toEqual(expectedValue);
|
|
262
262
|
});
|
|
263
263
|
it('should return a string number when decimal value validation is present', function () {
|
|
264
|
-
var stringNumber = (0,
|
|
265
|
-
validations: [{ type:
|
|
264
|
+
var stringNumber = (0, index_js_1.someString)({
|
|
265
|
+
validations: [{ type: domain_js_1.ValidationType.DECIMAL_VALUE }],
|
|
266
266
|
});
|
|
267
267
|
expect(stringNumber).toEqual('-1337');
|
|
268
268
|
});
|
|
269
269
|
it('should return an unsigned string number when decimal value validation is present', function () {
|
|
270
|
-
var stringNumber = (0,
|
|
271
|
-
validations: [{ type:
|
|
270
|
+
var stringNumber = (0, index_js_1.someString)({
|
|
271
|
+
validations: [{ type: domain_js_1.ValidationType.DECIMAL_VALUE }],
|
|
272
272
|
isUnsigned: true,
|
|
273
273
|
});
|
|
274
274
|
expect(stringNumber).toEqual('1337');
|
|
@@ -278,13 +278,13 @@ describe('Value generator', function () {
|
|
|
278
278
|
});
|
|
279
279
|
describe('Numbers', function () {
|
|
280
280
|
it('should return constant number as a string', function () {
|
|
281
|
-
var value = (0,
|
|
282
|
-
expect(value).toEqual(
|
|
281
|
+
var value = (0, index_js_1.someNumber)();
|
|
282
|
+
expect(value).toEqual(constant_values_js_1.CONSTANT_VALUES.INT);
|
|
283
283
|
});
|
|
284
284
|
it('should use the maximum validation as number value', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
285
285
|
var value;
|
|
286
286
|
return tslib_1.__generator(this, function (_a) {
|
|
287
|
-
value = (0,
|
|
287
|
+
value = (0, index_js_1.someNumber)({ validations: [maxNumberValidation] });
|
|
288
288
|
expect(value).toEqual(max);
|
|
289
289
|
return [2 /*return*/];
|
|
290
290
|
});
|
|
@@ -292,7 +292,7 @@ describe('Value generator', function () {
|
|
|
292
292
|
it('should use the minimum validation as number value', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
293
293
|
var value;
|
|
294
294
|
return tslib_1.__generator(this, function (_a) {
|
|
295
|
-
value = (0,
|
|
295
|
+
value = (0, index_js_1.someNumber)({ validations: [minNumberValidation] });
|
|
296
296
|
expect(value).toEqual(min);
|
|
297
297
|
return [2 /*return*/];
|
|
298
298
|
});
|
|
@@ -300,7 +300,7 @@ describe('Value generator', function () {
|
|
|
300
300
|
it('should use the minimum validation as number value when having both min and max', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
301
301
|
var value;
|
|
302
302
|
return tslib_1.__generator(this, function (_a) {
|
|
303
|
-
value = (0,
|
|
303
|
+
value = (0, index_js_1.someNumber)({
|
|
304
304
|
validations: [minNumberValidation, maxNumberValidation],
|
|
305
305
|
});
|
|
306
306
|
expect(value).toEqual(min);
|
|
@@ -309,17 +309,17 @@ describe('Value generator', function () {
|
|
|
309
309
|
}); });
|
|
310
310
|
// todo: move to params object with validations, defaultValue and isUnsigned
|
|
311
311
|
it('should use unsigned int when needed', function () {
|
|
312
|
-
var value = (0,
|
|
313
|
-
expect(value).toEqual(
|
|
312
|
+
var value = (0, index_js_1.someNumber)({ isUnsigned: true });
|
|
313
|
+
expect(value).toEqual(constant_values_js_1.CONSTANT_VALUES.UINT);
|
|
314
314
|
});
|
|
315
315
|
describe('with Decimal Value', function () {
|
|
316
316
|
var getDecimalValueValidation = function (value) { return ({
|
|
317
|
-
type:
|
|
317
|
+
type: domain_js_1.ValidationType.DECIMAL_VALUE,
|
|
318
318
|
value: value,
|
|
319
319
|
}); };
|
|
320
320
|
it('should use gte (greater then equal) as value for number', function () {
|
|
321
321
|
var decimalValueGreaterThanEqual = { gte: 1 };
|
|
322
|
-
var value = (0,
|
|
322
|
+
var value = (0, index_js_1.someNumber)({
|
|
323
323
|
validations: [
|
|
324
324
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
325
325
|
],
|
|
@@ -328,14 +328,14 @@ describe('Value generator', function () {
|
|
|
328
328
|
});
|
|
329
329
|
it('should use incremented gt (greater than) as value for number', function () {
|
|
330
330
|
var decimalValueGreaterThan = { gt: 1 };
|
|
331
|
-
var value = (0,
|
|
331
|
+
var value = (0, index_js_1.someNumber)({
|
|
332
332
|
validations: [getDecimalValueValidation(decimalValueGreaterThan)],
|
|
333
333
|
});
|
|
334
334
|
expect(value).toEqual(decimalValueGreaterThan.gt + 1);
|
|
335
335
|
});
|
|
336
336
|
it('should use incremented gt (greater than) as value even when lt and lte exist', function () {
|
|
337
337
|
var decimalValueGreaterThanLowerThan = { gt: 1, lte: 3, lt: 3 };
|
|
338
|
-
var value = (0,
|
|
338
|
+
var value = (0, index_js_1.someNumber)({
|
|
339
339
|
validations: [
|
|
340
340
|
getDecimalValueValidation(decimalValueGreaterThanLowerThan),
|
|
341
341
|
],
|
|
@@ -344,7 +344,7 @@ describe('Value generator', function () {
|
|
|
344
344
|
});
|
|
345
345
|
it('should use lte (lower than equal) as value', function () {
|
|
346
346
|
var decimalValueGreaterThanEqual = { lte: 2 };
|
|
347
|
-
var value = (0,
|
|
347
|
+
var value = (0, index_js_1.someNumber)({
|
|
348
348
|
validations: [
|
|
349
349
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
350
350
|
],
|
|
@@ -353,7 +353,7 @@ describe('Value generator', function () {
|
|
|
353
353
|
});
|
|
354
354
|
it('should use lt (lower than) decremented as value', function () {
|
|
355
355
|
var decimalValueGreaterThanEqual = { lt: 2 };
|
|
356
|
-
var value = (0,
|
|
356
|
+
var value = (0, index_js_1.someNumber)({
|
|
357
357
|
validations: [
|
|
358
358
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
359
359
|
],
|
|
@@ -362,7 +362,7 @@ describe('Value generator', function () {
|
|
|
362
362
|
});
|
|
363
363
|
it('should return float when maxScale is present with gte', function () {
|
|
364
364
|
var decimalValueGreaterThanEqual = { gte: 2, maxScale: 2 };
|
|
365
|
-
var value = (0,
|
|
365
|
+
var value = (0, index_js_1.someNumber)({
|
|
366
366
|
validations: [
|
|
367
367
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
368
368
|
],
|
|
@@ -371,7 +371,7 @@ describe('Value generator', function () {
|
|
|
371
371
|
});
|
|
372
372
|
it('should return float when maxScale is present with lte', function () {
|
|
373
373
|
var decimalValueGreaterThanEqual = { lte: 2, maxScale: 2 };
|
|
374
|
-
var value = (0,
|
|
374
|
+
var value = (0, index_js_1.someNumber)({
|
|
375
375
|
validations: [
|
|
376
376
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
377
377
|
],
|
|
@@ -385,7 +385,7 @@ describe('Value generator', function () {
|
|
|
385
385
|
maxScale: 2,
|
|
386
386
|
};
|
|
387
387
|
var expectedValue = decimalValueGreaterThanEqual.gt + 0.01;
|
|
388
|
-
var value = (0,
|
|
388
|
+
var value = (0, index_js_1.someNumber)({
|
|
389
389
|
validations: [
|
|
390
390
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
391
391
|
],
|
|
@@ -394,14 +394,14 @@ describe('Value generator', function () {
|
|
|
394
394
|
});
|
|
395
395
|
it('should decrement according to maxScale', function () {
|
|
396
396
|
var decimalValueLowerThan = { lt: 2, maxScale: 2 };
|
|
397
|
-
var value = (0,
|
|
397
|
+
var value = (0, index_js_1.someNumber)({
|
|
398
398
|
validations: [getDecimalValueValidation(decimalValueLowerThan)],
|
|
399
399
|
});
|
|
400
400
|
expect(value).toEqual(decimalValueLowerThan.lt - 0.01);
|
|
401
401
|
});
|
|
402
402
|
it('should support having only max scale', function () {
|
|
403
403
|
var decimalValueMaxScale = { maxScale: 2 };
|
|
404
|
-
var value = (0,
|
|
404
|
+
var value = (0, index_js_1.someNumber)({
|
|
405
405
|
validations: [getDecimalValueValidation(decimalValueMaxScale)],
|
|
406
406
|
});
|
|
407
407
|
expect(value).toEqual(-1337.0);
|
|
@@ -413,7 +413,7 @@ describe('Value generator', function () {
|
|
|
413
413
|
maxScale: 2,
|
|
414
414
|
};
|
|
415
415
|
var expectedValue = parseFloat(decimalValueGreaterThanEqual.gt) + 0.01;
|
|
416
|
-
var value = (0,
|
|
416
|
+
var value = (0, index_js_1.someNumber)({
|
|
417
417
|
validations: [
|
|
418
418
|
getDecimalValueValidation(decimalValueGreaterThanEqual),
|
|
419
419
|
],
|
|
@@ -428,7 +428,7 @@ describe('Value generator', function () {
|
|
|
428
428
|
it('should use minimum validation number as long value', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
429
429
|
var value;
|
|
430
430
|
return tslib_1.__generator(this, function (_a) {
|
|
431
|
-
value = (0,
|
|
431
|
+
value = (0, index_js_1.someLong)({ validations: [minNumberValidation] });
|
|
432
432
|
expect(value).toEqual(new long_1.default(min, 0));
|
|
433
433
|
return [2 /*return*/];
|
|
434
434
|
});
|
|
@@ -436,7 +436,7 @@ describe('Value generator', function () {
|
|
|
436
436
|
it('should use maximum validation number as long value', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
437
437
|
var value;
|
|
438
438
|
return tslib_1.__generator(this, function (_a) {
|
|
439
|
-
value = (0,
|
|
439
|
+
value = (0, index_js_1.someLong)({ validations: [maxNumberValidation] });
|
|
440
440
|
expect(value).toEqual(new long_1.default(max, 0));
|
|
441
441
|
return [2 /*return*/];
|
|
442
442
|
});
|
|
@@ -444,15 +444,15 @@ describe('Value generator', function () {
|
|
|
444
444
|
it('should use default long as an unsigned long value', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
445
445
|
var value;
|
|
446
446
|
return tslib_1.__generator(this, function (_a) {
|
|
447
|
-
value = (0,
|
|
448
|
-
expect(value).toEqual(new long_1.default(
|
|
447
|
+
value = (0, index_js_1.someLong)({ isUnsigned: isUnsigned });
|
|
448
|
+
expect(value).toEqual(new long_1.default(constant_values_js_1.CONSTANT_VALUES.UINT, 0, true));
|
|
449
449
|
return [2 /*return*/];
|
|
450
450
|
});
|
|
451
451
|
}); });
|
|
452
452
|
it('should use minimum validation number as an unsigned long value', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
453
453
|
var value;
|
|
454
454
|
return tslib_1.__generator(this, function (_a) {
|
|
455
|
-
value = (0,
|
|
455
|
+
value = (0, index_js_1.someLong)({
|
|
456
456
|
validations: [minNumberValidation],
|
|
457
457
|
isUnsigned: isUnsigned,
|
|
458
458
|
});
|
|
@@ -463,7 +463,7 @@ describe('Value generator', function () {
|
|
|
463
463
|
it('should use maximum validation number as an unsigned long value', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
464
464
|
var value;
|
|
465
465
|
return tslib_1.__generator(this, function (_a) {
|
|
466
|
-
value = (0,
|
|
466
|
+
value = (0, index_js_1.someLong)({
|
|
467
467
|
validations: [maxNumberValidation],
|
|
468
468
|
isUnsigned: isUnsigned,
|
|
469
469
|
});
|
|
@@ -476,94 +476,94 @@ describe('Value generator', function () {
|
|
|
476
476
|
var floatMin = 2.1;
|
|
477
477
|
var floatMax = 4.6;
|
|
478
478
|
var minFloatValidation = {
|
|
479
|
-
type:
|
|
479
|
+
type: domain_js_1.ValidationType.MIN,
|
|
480
480
|
value: floatMin,
|
|
481
481
|
};
|
|
482
482
|
var maxFloatValidation = {
|
|
483
|
-
type:
|
|
483
|
+
type: domain_js_1.ValidationType.MAX,
|
|
484
484
|
value: floatMax,
|
|
485
485
|
};
|
|
486
486
|
it('should return the default float', function () {
|
|
487
|
-
expect((0,
|
|
487
|
+
expect((0, index_js_1.someFloat)()).toEqual(constant_values_js_1.CONSTANT_VALUES.FLOAT);
|
|
488
488
|
});
|
|
489
489
|
it('should return a float according to min value', function () {
|
|
490
|
-
expect((0,
|
|
490
|
+
expect((0, index_js_1.someFloat)({ validations: [minFloatValidation] })).toEqual(floatMin);
|
|
491
491
|
});
|
|
492
492
|
it('should return a float according to max value', function () {
|
|
493
|
-
expect((0,
|
|
493
|
+
expect((0, index_js_1.someFloat)({ validations: [maxFloatValidation] })).toEqual(floatMax);
|
|
494
494
|
});
|
|
495
495
|
});
|
|
496
496
|
describe('Repeated', function () {
|
|
497
497
|
it('should handle list value', function () {
|
|
498
498
|
var expectedArrayValue = [
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
499
|
+
constant_values_js_1.CONSTANT_VALUES.EMPTY_OBJECT,
|
|
500
|
+
constant_values_js_1.CONSTANT_VALUES.STRING,
|
|
501
|
+
constant_values_js_1.CONSTANT_VALUES.INT,
|
|
502
502
|
];
|
|
503
|
-
expect((0,
|
|
503
|
+
expect((0, index_js_1.someRepeated)()).toEqual(expectedArrayValue);
|
|
504
504
|
});
|
|
505
505
|
it('should generate list value with min length filled with empty objects', function () {
|
|
506
|
-
var value = (0,
|
|
507
|
-
validations: [{ type:
|
|
506
|
+
var value = (0, index_js_1.someRepeated)({
|
|
507
|
+
validations: [{ type: domain_js_1.ValidationType.MIN_SIZE, value: 6 }],
|
|
508
508
|
});
|
|
509
509
|
var expectedArrayValue = [
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
510
|
+
constant_values_js_1.CONSTANT_VALUES.EMPTY_OBJECT,
|
|
511
|
+
constant_values_js_1.CONSTANT_VALUES.STRING,
|
|
512
|
+
constant_values_js_1.CONSTANT_VALUES.INT,
|
|
513
|
+
constant_values_js_1.CONSTANT_VALUES.STRING,
|
|
514
|
+
constant_values_js_1.CONSTANT_VALUES.STRING,
|
|
515
|
+
constant_values_js_1.CONSTANT_VALUES.STRING,
|
|
516
516
|
];
|
|
517
517
|
expect(value).toEqual(expectedArrayValue);
|
|
518
518
|
});
|
|
519
519
|
it('should generate list value with max size', function () {
|
|
520
|
-
var value = (0,
|
|
521
|
-
validations: [{ type:
|
|
520
|
+
var value = (0, index_js_1.someRepeated)({
|
|
521
|
+
validations: [{ type: domain_js_1.ValidationType.MAX_SIZE, value: 2 }],
|
|
522
522
|
});
|
|
523
523
|
var expectedArrayValue = [
|
|
524
|
-
|
|
525
|
-
|
|
524
|
+
constant_values_js_1.CONSTANT_VALUES.EMPTY_OBJECT,
|
|
525
|
+
constant_values_js_1.CONSTANT_VALUES.STRING,
|
|
526
526
|
];
|
|
527
527
|
expect(value).toEqual(expectedArrayValue);
|
|
528
528
|
});
|
|
529
529
|
it('should generate list value when constant value satisfies array size validations', function () {
|
|
530
|
-
var value = (0,
|
|
530
|
+
var value = (0, index_js_1.someRepeated)({
|
|
531
531
|
validations: [
|
|
532
|
-
{ type:
|
|
533
|
-
{ type:
|
|
532
|
+
{ type: domain_js_1.ValidationType.MIN_SIZE, value: 1 },
|
|
533
|
+
{ type: domain_js_1.ValidationType.MAX_SIZE, value: 4 },
|
|
534
534
|
],
|
|
535
535
|
});
|
|
536
536
|
var expectedArrayValue = [
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
537
|
+
constant_values_js_1.CONSTANT_VALUES.EMPTY_OBJECT,
|
|
538
|
+
constant_values_js_1.CONSTANT_VALUES.STRING,
|
|
539
|
+
constant_values_js_1.CONSTANT_VALUES.INT,
|
|
540
540
|
];
|
|
541
541
|
expect(value).toEqual(expectedArrayValue);
|
|
542
542
|
});
|
|
543
543
|
it('should work for field mask', function () {
|
|
544
544
|
var fillWithOnlyStrings = true;
|
|
545
|
-
var value = (0,
|
|
545
|
+
var value = (0, index_js_1.someRepeated)({ validations: [{ type: domain_js_1.ValidationType.MIN_SIZE, value: 2 }] }, fillWithOnlyStrings);
|
|
546
546
|
var expectedArrayValue = [
|
|
547
|
-
|
|
548
|
-
|
|
547
|
+
constant_values_js_1.CONSTANT_VALUES.STRING,
|
|
548
|
+
constant_values_js_1.CONSTANT_VALUES.STRING,
|
|
549
549
|
];
|
|
550
550
|
expect(value).toEqual(expectedArrayValue);
|
|
551
551
|
});
|
|
552
552
|
});
|
|
553
553
|
describe('Date and Duration', function () {
|
|
554
554
|
it('should return constant date', function () {
|
|
555
|
-
expect((0,
|
|
555
|
+
expect((0, index_js_1.someDate)()).toEqual(constant_values_js_1.CONSTANT_VALUES.DATE);
|
|
556
556
|
});
|
|
557
557
|
it('should return constant duration', function () {
|
|
558
|
-
var duration = (0,
|
|
559
|
-
expect(duration).toEqual(
|
|
558
|
+
var duration = (0, index_js_1.someDuration)();
|
|
559
|
+
expect(duration).toEqual(constant_values_js_1.CONSTANT_VALUES.DURATION);
|
|
560
560
|
expect(typeof duration.seconds).toEqual('string');
|
|
561
561
|
expect(typeof duration.nanos).toEqual('number');
|
|
562
562
|
});
|
|
563
563
|
});
|
|
564
564
|
describe('Any', function () {
|
|
565
565
|
it('should return empty object', function () {
|
|
566
|
-
expect((0,
|
|
566
|
+
expect((0, index_js_1.someAny)()).toEqual(constant_values_js_1.CONSTANT_VALUES.EMPTY_OBJECT);
|
|
567
567
|
});
|
|
568
568
|
});
|
|
569
569
|
});
|