@sprucelabs/schema 25.5.65 → 25.5.69

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.
Files changed (96) hide show
  1. package/build/esm/DynamicSchemaEntityImplementation.d.ts +1 -1
  2. package/build/esm/fields/AbstractField.d.ts +1 -1
  3. package/build/esm/fields/field.static.types.d.ts +1 -1
  4. package/build/esm/schemas.static.types.d.ts +1 -1
  5. package/build/esm/utilities/assertOptions.js +1 -1
  6. package/build/esm/utilities/normalizeFieldValue.d.ts +1 -1
  7. package/build/utilities/assertOptions.js +1 -1
  8. package/package.json +13 -12
  9. package/build/esm/__tests__/behavioral/AssertingSelectOptions.test.d.ts +0 -7
  10. package/build/esm/__tests__/behavioral/AssertingSelectOptions.test.js +0 -93
  11. package/build/esm/__tests__/behavioral/AssertingValidationErrors.test.d.ts +0 -18
  12. package/build/esm/__tests__/behavioral/AssertingValidationErrors.test.js +0 -217
  13. package/build/esm/__tests__/behavioral/BuildSchema.test.d.ts +0 -5
  14. package/build/esm/__tests__/behavioral/BuildSchema.test.js +0 -66
  15. package/build/esm/__tests__/behavioral/CreatingEntityInstances.test.d.ts +0 -7
  16. package/build/esm/__tests__/behavioral/CreatingEntityInstances.test.js +0 -93
  17. package/build/esm/__tests__/behavioral/DroppingFields.test.d.ts +0 -5
  18. package/build/esm/__tests__/behavioral/DroppingFields.test.js +0 -86
  19. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplates.test.d.ts +0 -9
  20. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplates.test.js +0 -137
  21. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplatesWithSuffix.test.d.ts +0 -5
  22. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplatesWithSuffix.test.js +0 -146
  23. package/build/esm/__tests__/behavioral/GeneratesTemplates.test.d.ts +0 -5
  24. package/build/esm/__tests__/behavioral/GeneratesTemplates.test.js +0 -67
  25. package/build/esm/__tests__/behavioral/GeneratesTypeMappers.test.d.ts +0 -5
  26. package/build/esm/__tests__/behavioral/GeneratesTypeMappers.test.js +0 -29
  27. package/build/esm/__tests__/behavioral/GeneratesVersionedRelationshipTemplates.test.d.ts +0 -11
  28. package/build/esm/__tests__/behavioral/GeneratesVersionedRelationshipTemplates.test.js +0 -191
  29. package/build/esm/__tests__/behavioral/GettingFieldsOffASchema.test.d.ts +0 -7
  30. package/build/esm/__tests__/behavioral/GettingFieldsOffASchema.test.js +0 -88
  31. package/build/esm/__tests__/behavioral/HandlesDynamicFields.test.d.ts +0 -17
  32. package/build/esm/__tests__/behavioral/HandlesDynamicFields.test.js +0 -284
  33. package/build/esm/__tests__/behavioral/HandlesHidingPrivateFields.test.d.ts +0 -11
  34. package/build/esm/__tests__/behavioral/HandlesHidingPrivateFields.test.js +0 -111
  35. package/build/esm/__tests__/behavioral/HandlesRelationships.test.d.ts +0 -9
  36. package/build/esm/__tests__/behavioral/HandlesRelationships.test.js +0 -175
  37. package/build/esm/__tests__/behavioral/HandlesRequiredFields.test.d.ts +0 -4
  38. package/build/esm/__tests__/behavioral/HandlesRequiredFields.test.js +0 -37
  39. package/build/esm/__tests__/behavioral/HandlesVersionedRelationships.test.d.ts +0 -6
  40. package/build/esm/__tests__/behavioral/HandlesVersionedRelationships.test.js +0 -102
  41. package/build/esm/__tests__/behavioral/HandlesVersioning.test.d.ts +0 -8
  42. package/build/esm/__tests__/behavioral/HandlesVersioning.test.js +0 -93
  43. package/build/esm/__tests__/behavioral/IsIdWithVersion.test.d.ts +0 -4
  44. package/build/esm/__tests__/behavioral/IsIdWithVersion.test.js +0 -30
  45. package/build/esm/__tests__/behavioral/MakingFieldsOptional.test.d.ts +0 -4
  46. package/build/esm/__tests__/behavioral/MakingFieldsOptional.test.js +0 -57
  47. package/build/esm/__tests__/behavioral/NormalizeToSchemaIdWithVersion.test.d.ts +0 -6
  48. package/build/esm/__tests__/behavioral/NormalizeToSchemaIdWithVersion.test.js +0 -77
  49. package/build/esm/__tests__/behavioral/NormalizingSchemaValues.test.d.ts +0 -8
  50. package/build/esm/__tests__/behavioral/NormalizingSchemaValues.test.js +0 -148
  51. package/build/esm/__tests__/behavioral/ResetsSchemasEveryTest.test.d.ts +0 -6
  52. package/build/esm/__tests__/behavioral/ResetsSchemasEveryTest.test.js +0 -45
  53. package/build/esm/__tests__/behavioral/SchemaDefaultValues.test.d.ts +0 -9
  54. package/build/esm/__tests__/behavioral/SchemaDefaultValues.test.js +0 -138
  55. package/build/esm/__tests__/behavioral/SelectChoicesToHash.test.d.ts +0 -4
  56. package/build/esm/__tests__/behavioral/SelectChoicesToHash.test.js +0 -43
  57. package/build/esm/__tests__/behavioral/SettingMinAndMaxValuesOnArrayFields.test.d.ts +0 -9
  58. package/build/esm/__tests__/behavioral/SettingMinAndMaxValuesOnArrayFields.test.js +0 -104
  59. package/build/esm/__tests__/behavioral/UsingSchemas.test.d.ts +0 -13
  60. package/build/esm/__tests__/behavioral/UsingSchemas.test.js +0 -281
  61. package/build/esm/__tests__/behavioral/UsingTheSchemaRegisteryForNamespacedSchemas.test.d.ts +0 -14
  62. package/build/esm/__tests__/behavioral/UsingTheSchemaRegisteryForNamespacedSchemas.test.js +0 -140
  63. package/build/esm/__tests__/behavioral/UsingTheSchemaRegistry.test.d.ts +0 -15
  64. package/build/esm/__tests__/behavioral/UsingTheSchemaRegistry.test.js +0 -117
  65. package/build/esm/__tests__/behavioral/ValidatingSchemaValues.test.d.ts +0 -28
  66. package/build/esm/__tests__/behavioral/ValidatingSchemaValues.test.js +0 -674
  67. package/build/esm/__tests__/data/personWithCars.d.ts +0 -188
  68. package/build/esm/__tests__/data/personWithCars.js +0 -163
  69. package/build/esm/__tests__/data/versionedPersonWithCars.d.ts +0 -323
  70. package/build/esm/__tests__/data/versionedPersonWithCars.js +0 -281
  71. package/build/esm/__tests__/implementation/BooleanField.test.d.ts +0 -6
  72. package/build/esm/__tests__/implementation/BooleanField.test.js +0 -59
  73. package/build/esm/__tests__/implementation/DurationField.test.d.ts +0 -7
  74. package/build/esm/__tests__/implementation/DurationField.test.js +0 -45
  75. package/build/esm/__tests__/implementation/EmailField.test.d.ts +0 -4
  76. package/build/esm/__tests__/implementation/EmailField.test.js +0 -39
  77. package/build/esm/__tests__/implementation/ErrorMapUtil.test.d.ts +0 -11
  78. package/build/esm/__tests__/implementation/ErrorMapUtil.test.js +0 -176
  79. package/build/esm/__tests__/implementation/FieldFactory.test.d.ts +0 -4
  80. package/build/esm/__tests__/implementation/FieldFactory.test.js +0 -35
  81. package/build/esm/__tests__/implementation/FileField.test.d.ts +0 -19
  82. package/build/esm/__tests__/implementation/FileField.test.js +0 -125
  83. package/build/esm/__tests__/implementation/NumberField.test.d.ts +0 -5
  84. package/build/esm/__tests__/implementation/NumberField.test.js +0 -54
  85. package/build/esm/__tests__/implementation/PhoneField.test.d.ts +0 -7
  86. package/build/esm/__tests__/implementation/PhoneField.test.js +0 -82
  87. package/build/esm/__tests__/implementation/SchemaFieldTransformingOptions.test.d.ts +0 -5
  88. package/build/esm/__tests__/implementation/SchemaFieldTransformingOptions.test.js +0 -209
  89. package/build/esm/__tests__/implementation/SchemaFieldValidation.test.d.ts +0 -8
  90. package/build/esm/__tests__/implementation/SchemaFieldValidation.test.js +0 -87
  91. package/build/esm/__tests__/implementation/SelectField.test.d.ts +0 -8
  92. package/build/esm/__tests__/implementation/SelectField.test.js +0 -127
  93. package/build/esm/__tests__/implementation/TextField.test.d.ts +0 -4
  94. package/build/esm/__tests__/implementation/TextField.test.js +0 -34
  95. package/build/esm/__tests__/implementation/ValidateErrorMessageFormatter.test.d.ts +0 -16
  96. package/build/esm/__tests__/implementation/ValidateErrorMessageFormatter.test.js +0 -216
@@ -1,281 +0,0 @@
1
- import StaticSchemaEntityImplementation from '../../StaticSchemaEntityImplementation.js';
2
- import buildSchema from '../../utilities/buildSchema.js';
3
- // turn off duplicate checks because tests all run in the same runtime
4
- StaticSchemaEntityImplementation.enableDuplicateCheckWhenTracking = false;
5
- const buildVersionedPersonWithCars = () => {
6
- const carV1Schema = buildSchema({
7
- id: 'car',
8
- name: 'car',
9
- version: 'v1',
10
- fields: {
11
- name: {
12
- type: 'text',
13
- isRequired: true,
14
- },
15
- onlyOnCar: {
16
- type: 'text',
17
- },
18
- },
19
- });
20
- const carV2Schema = buildSchema({
21
- id: 'car',
22
- name: 'car',
23
- version: 'v2',
24
- fields: {
25
- name: {
26
- type: 'text',
27
- isRequired: true,
28
- },
29
- newRequiredOnCar: {
30
- type: 'text',
31
- isRequired: true,
32
- },
33
- },
34
- });
35
- const truckV1Definition = buildSchema({
36
- id: 'truck',
37
- name: 'Truck',
38
- version: 'v1',
39
- fields: {
40
- name: {
41
- type: 'text',
42
- isRequired: true,
43
- },
44
- onlyOnTruck: {
45
- type: 'text',
46
- },
47
- },
48
- });
49
- const personV1Schema = buildSchema({
50
- id: 'person',
51
- name: 'user schema test',
52
- version: 'v1',
53
- fields: {
54
- name: {
55
- type: 'text',
56
- isArray: false,
57
- value: 'tay',
58
- },
59
- requiredCar: {
60
- type: 'schema',
61
- isRequired: true,
62
- options: {
63
- schema: carV1Schema,
64
- },
65
- },
66
- optionalCar: {
67
- type: 'schema',
68
- options: {
69
- schema: carV1Schema,
70
- },
71
- },
72
- optionalCarWithCallback: {
73
- type: 'schema',
74
- options: {
75
- schemasCallback: () => [carV1Schema],
76
- },
77
- },
78
- optionalIsArrayCars: {
79
- type: 'schema',
80
- isArray: true,
81
- options: {
82
- schema: carV1Schema,
83
- },
84
- },
85
- requiredIsArrayCars: {
86
- type: 'schema',
87
- isArray: true,
88
- isRequired: true,
89
- options: {
90
- schema: carV1Schema,
91
- },
92
- },
93
- optionalCarOrTruck: {
94
- type: 'schema',
95
- options: {
96
- schemas: [carV1Schema, truckV1Definition],
97
- },
98
- },
99
- optionalIsArrayCarOrTruck: {
100
- type: 'schema',
101
- isArray: true,
102
- options: {
103
- schemas: [carV1Schema, truckV1Definition],
104
- },
105
- },
106
- requiredIsArrayCarOrTruck: {
107
- type: 'schema',
108
- isArray: true,
109
- isRequired: true,
110
- options: {
111
- schemas: [carV1Schema, truckV1Definition],
112
- },
113
- },
114
- optionalSelect: {
115
- type: 'select',
116
- options: {
117
- choices: [
118
- { value: 'foo', label: 'Foo' },
119
- { value: 'bar', label: 'Bar' },
120
- ],
121
- },
122
- },
123
- optionalSelectWithDefaultValue: {
124
- type: 'select',
125
- defaultValue: 'hello',
126
- options: {
127
- choices: [
128
- { value: 'hello', label: 'world' },
129
- { value: 'goodbye', label: 'darling' },
130
- ],
131
- },
132
- },
133
- optionalTextWithDefaultValue: {
134
- type: 'text',
135
- defaultValue: 'world',
136
- },
137
- optionalCarWithDefaultValue: {
138
- type: 'schema',
139
- defaultValue: { name: 'fast car' },
140
- options: {
141
- schema: carV1Schema,
142
- },
143
- },
144
- optionalIsArrayCarOrTruckWithDefaultValue: {
145
- type: 'schema',
146
- isArray: true,
147
- defaultValue: [{ schemaId: 'car', values: { name: 'fast car' } }],
148
- options: {
149
- schemas: [carV1Schema, truckV1Definition],
150
- },
151
- },
152
- optionalCarOrTruckWithDefaultValue: {
153
- type: 'schema',
154
- defaultValue: { schemaId: 'car', values: { name: 'fast car' } },
155
- options: {
156
- schemas: [carV1Schema, truckV1Definition],
157
- },
158
- },
159
- },
160
- });
161
- const personV2Schema = buildSchema({
162
- id: 'person',
163
- name: 'user schema test',
164
- version: 'v2',
165
- fields: {
166
- name: {
167
- type: 'text',
168
- isArray: false,
169
- value: 'tay',
170
- },
171
- requiredCar: {
172
- type: 'schema',
173
- isRequired: true,
174
- options: {
175
- schema: carV2Schema,
176
- },
177
- },
178
- optionalCar: {
179
- type: 'schema',
180
- options: {
181
- schema: carV2Schema,
182
- },
183
- },
184
- optionalCarWithCallback: {
185
- type: 'schema',
186
- options: {
187
- schemasCallback: () => [carV1Schema, carV2Schema, truckV1Definition],
188
- },
189
- },
190
- optionalIsArrayCars: {
191
- type: 'schema',
192
- isArray: true,
193
- options: {
194
- schema: carV1Schema,
195
- },
196
- },
197
- requiredIsArrayCars: {
198
- type: 'schema',
199
- isArray: true,
200
- isRequired: true,
201
- options: {
202
- schema: carV1Schema,
203
- },
204
- },
205
- optionalCarOrTruck: {
206
- type: 'schema',
207
- options: {
208
- schemas: [carV1Schema, carV2Schema, truckV1Definition],
209
- },
210
- },
211
- optionalIsArrayCarOrTruck: {
212
- type: 'schema',
213
- isArray: true,
214
- options: {
215
- schemas: [carV1Schema, truckV1Definition],
216
- },
217
- },
218
- requiredIsArrayCarOrTruck: {
219
- type: 'schema',
220
- isArray: true,
221
- isRequired: true,
222
- options: {
223
- schemas: [carV1Schema, truckV1Definition],
224
- },
225
- },
226
- optionalSelect: {
227
- type: 'select',
228
- options: {
229
- choices: [
230
- { value: 'foo', label: 'Foo' },
231
- { value: 'bar', label: 'Bar' },
232
- ],
233
- },
234
- },
235
- optionalSelectWithDefaultValue: {
236
- type: 'select',
237
- defaultValue: 'hello',
238
- options: {
239
- choices: [
240
- { value: 'hello', label: 'world' },
241
- { value: 'goodbye', label: 'darling' },
242
- ],
243
- },
244
- },
245
- optionalTextWithDefaultValue: {
246
- type: 'text',
247
- defaultValue: 'world',
248
- },
249
- optionalCarWithDefaultValue: {
250
- type: 'schema',
251
- defaultValue: { name: 'fast car' },
252
- options: {
253
- schema: carV1Schema,
254
- },
255
- },
256
- optionalIsArrayCarOrTruckWithDefaultValue: {
257
- type: 'schema',
258
- isArray: true,
259
- defaultValue: [{ schemaId: 'car', values: { name: 'fast car' } }],
260
- options: {
261
- schemas: [carV1Schema, truckV1Definition],
262
- },
263
- },
264
- optionalCarOrTruckWithDefaultValue: {
265
- type: 'schema',
266
- defaultValue: { schemaId: 'car', values: { name: 'fast car' } },
267
- options: {
268
- schemas: [carV1Schema, truckV1Definition],
269
- },
270
- },
271
- },
272
- });
273
- return {
274
- personV1Schema,
275
- carV1Schema,
276
- carV2Schema,
277
- truckV1Definition,
278
- personV2Schema,
279
- };
280
- };
281
- export default buildVersionedPersonWithCars;
@@ -1,6 +0,0 @@
1
- import AbstractSpruceTest from '@sprucelabs/test';
2
- export default class BooleanFieldTest extends AbstractSpruceTest {
3
- protected static transformTests(value: any, expected: boolean): Promise<void>;
4
- protected static canHandleDefaultValue(): void;
5
- protected static canHandleArrayDefaultValue(): void;
6
- }
@@ -1,59 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- import AbstractSpruceTest, { test, assert } from '@sprucelabs/test';
17
- import FieldFactory from '../../factories/FieldFactory.js';
18
- export default class BooleanFieldTest extends AbstractSpruceTest {
19
- static transformTests(value, expected) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const field = FieldFactory.Field('transformTest', {
22
- type: 'boolean',
23
- });
24
- const result = field.toValueType(value);
25
- assert.isEqual(result, expected);
26
- });
27
- }
28
- static canHandleDefaultValue() {
29
- const def = {
30
- label: 'Public',
31
- type: 'boolean',
32
- hint: 'Is this location viewable by guests?',
33
- defaultValue: false,
34
- };
35
- assert.isType(def);
36
- }
37
- static canHandleArrayDefaultValue() {
38
- const def = {
39
- type: 'boolean',
40
- isArray: true,
41
- defaultValue: [true],
42
- };
43
- assert.isType(def);
44
- }
45
- }
46
- __decorate([
47
- test('can transform string false to boolean false', 'false', false),
48
- test('can transform string true to boolean true', 'true', true),
49
- test('can transform gibberish to truthy', 'waka', true),
50
- test('empty string is false', '', false),
51
- test('false is false', false, false),
52
- test('true is true', true, true)
53
- ], BooleanFieldTest, "transformTests", null);
54
- __decorate([
55
- test()
56
- ], BooleanFieldTest, "canHandleDefaultValue", null);
57
- __decorate([
58
- test()
59
- ], BooleanFieldTest, "canHandleArrayDefaultValue", null);
@@ -1,7 +0,0 @@
1
- import AbstractSpruceTest from '@sprucelabs/test';
2
- import { DurationFieldValue } from '../../fields/DurationField.types';
3
- export default class DurationFieldTest extends AbstractSpruceTest {
4
- protected static testCompletingDurationObject(partial: Partial<DurationFieldValue>, expected: DurationFieldValue): void;
5
- protected static canBuildDuration(value: any, expected: any): void;
6
- protected static reduceDurationToMs(value: any, expected: number): void;
7
- }
@@ -1,45 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import AbstractSpruceTest, { test, assert } from '@sprucelabs/test';
8
- import FieldFactory from '../../factories/FieldFactory.js';
9
- import { buildDuration, reduceDurationToMs } from '../../fields/index.js';
10
- export default class DurationFieldTest extends AbstractSpruceTest {
11
- static testCompletingDurationObject(partial, expected) {
12
- const field = FieldFactory.Field('test', { type: 'duration' });
13
- const value = field.toValueType(partial);
14
- assert.isEqualDeep(value, expected, `Duration field did not map ${JSON.stringify(partial)} to ${JSON.stringify(expected)}`);
15
- // test build directly
16
- assert.isEqualDeep(buildDuration(partial), expected, `Duration field did not map ${JSON.stringify(partial)} to ${JSON.stringify(expected)}`);
17
- }
18
- static canBuildDuration(value, expected) {
19
- const results = buildDuration(value);
20
- assert.doesInclude(results, expected);
21
- }
22
- static reduceDurationToMs(value, expected) {
23
- const results = reduceDurationToMs(value);
24
- assert.isEqual(results, expected);
25
- }
26
- }
27
- __decorate([
28
- test('can get seconds from ms', { ms: 2340 }, { ms: 340, seconds: 2, minutes: 0, hours: 0 }),
29
- test('can get minutes from ms and seconds', { ms: 4500, seconds: 85 }, { ms: 500, seconds: 29, minutes: 1, hours: 0 }),
30
- test('can get minutes and seconds from part of an hour', { hours: 2.52 }, { ms: 0, seconds: 12, minutes: 31, hours: 2 })
31
- ], DurationFieldTest, "testCompletingDurationObject", null);
32
- __decorate([
33
- test('2000 to seconds', 2000, { seconds: 2 }),
34
- test('2500 ms to seconds and ms', 2500, { seconds: 2, ms: 500 }),
35
- test('60 sec to minutes', { seconds: 60 }, { minutes: 1, seconds: 0 })
36
- ], DurationFieldTest, "canBuildDuration", null);
37
- __decorate([
38
- test('ms to ms', { ms: 1000 }, 1000),
39
- test('seconds to ms', { seconds: 1 }, 1000),
40
- test('2 seconds to ms', { seconds: 2 }, 2000),
41
- test('2.5 seconds to ms', { seconds: 2, ms: 500 }, 2500),
42
- test('1 minute to ms', { minutes: 1 }, 1000 * 60),
43
- test('1.5 minute to ms', { minutes: 1, seconds: 30 }, 1000 * 90),
44
- test('1 hour to ms', { hours: 1 }, 1000 * 60 * 60)
45
- ], DurationFieldTest, "reduceDurationToMs", null);
@@ -1,4 +0,0 @@
1
- import AbstractSpruceTest from '@sprucelabs/test';
2
- export default class EmailFieldTest extends AbstractSpruceTest {
3
- protected static transformTests(email: any, expected: any): Promise<void>;
4
- }
@@ -1,39 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- import AbstractSpruceTest, { test, assert } from '@sprucelabs/test';
17
- import FieldFactory from '../../factories/FieldFactory.js';
18
- export default class EmailFieldTest extends AbstractSpruceTest {
19
- static transformTests(email, expected) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const field = FieldFactory.Field('testField', {
22
- type: 'email',
23
- });
24
- const errors = field.validate(email);
25
- assert.isEqualDeep(errors, expected);
26
- });
27
- }
28
- }
29
- __decorate([
30
- test('fails with obviously bad email', 'email', [
31
- { code: 'INVALID_PARAMETER', name: 'testField' },
32
- ]),
33
- test('fails with barely bad email', 'email@email', [
34
- { code: 'INVALID_PARAMETER', name: 'testField' },
35
- ]),
36
- test('passes with .com email', 'email@email.com', []),
37
- test('passes with .ai email', 'email@email.ai', []),
38
- test('passes with .eu email', 'email@email.eu', [])
39
- ], EmailFieldTest, "transformTests", null);
@@ -1,11 +0,0 @@
1
- import AbstractSpruceTest from '@sprucelabs/test';
2
- export default class ErrorMapUtilTest extends AbstractSpruceTest {
3
- protected static canCreateErrorMapUtil(): Promise<void>;
4
- protected static mapsMissingField(): Promise<void>;
5
- protected static maps2MissingFields(): Promise<void>;
6
- protected static mapsInvalidParameters(): Promise<void>;
7
- protected static mapsUnexpectedParameters(): Promise<void>;
8
- protected static mapsAll(): Promise<void>;
9
- protected static mapsSubErrors(): void;
10
- private static Error;
11
- }
@@ -1,176 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- import AbstractSpruceTest, { test, assert } from '@sprucelabs/test';
17
- import { errorAssertUtil } from '@sprucelabs/test-utils';
18
- import mapFieldErrorsToParameterErrors from '../../utilities/mapFieldErrorsToParameterErrors.js';
19
- export default class ErrorMapUtilTest extends AbstractSpruceTest {
20
- static canCreateErrorMapUtil() {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- assert.isFunction(mapFieldErrorsToParameterErrors);
23
- });
24
- }
25
- static mapsMissingField() {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const errs = this.Error([
28
- {
29
- code: 'MISSING_PARAMETER',
30
- friendlyMessage: "'First name' is required!",
31
- name: 'firstName',
32
- },
33
- ]);
34
- const errors = mapFieldErrorsToParameterErrors(errs);
35
- assert.isLength(errors, 1);
36
- errorAssertUtil.assertError(errors[0], 'MISSING_PARAMETERS', {
37
- parameters: ['firstName'],
38
- });
39
- });
40
- }
41
- static maps2MissingFields() {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const errs = this.Error([
44
- {
45
- code: 'MISSING_PARAMETER',
46
- friendlyMessage: "'First name' is required!",
47
- name: 'firstName',
48
- },
49
- {
50
- code: 'MISSING_PARAMETER',
51
- name: 'lastName',
52
- },
53
- ]);
54
- const errors = mapFieldErrorsToParameterErrors(errs);
55
- assert.isLength(errors, 1);
56
- errorAssertUtil.assertError(errors[0], 'MISSING_PARAMETERS', {
57
- parameters: ['firstName', 'lastName'],
58
- });
59
- });
60
- }
61
- static mapsInvalidParameters() {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- const errs = this.Error([
64
- {
65
- code: 'INVALID_PARAMETER',
66
- name: 'phone',
67
- },
68
- ]);
69
- const errors = mapFieldErrorsToParameterErrors(errs);
70
- assert.isLength(errors, 1);
71
- errorAssertUtil.assertError(errors[0], 'INVALID_PARAMETERS', {
72
- parameters: ['phone'],
73
- });
74
- });
75
- }
76
- static mapsUnexpectedParameters() {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- const errs = this.Error([
79
- {
80
- code: 'UNEXPECTED_PARAMETER',
81
- name: 'phone',
82
- },
83
- ]);
84
- const errors = mapFieldErrorsToParameterErrors(errs);
85
- assert.isLength(errors, 1);
86
- errorAssertUtil.assertError(errors[0], 'UNEXPECTED_PARAMETERS', {
87
- parameters: ['phone'],
88
- });
89
- });
90
- }
91
- static mapsAll() {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- const errs = this.Error([
94
- {
95
- code: 'UNEXPECTED_PARAMETER',
96
- name: 'phone',
97
- },
98
- {
99
- code: 'INVALID_PARAMETER',
100
- name: 'email',
101
- },
102
- {
103
- code: 'MISSING_PARAMETER',
104
- friendlyMessage: "'First name' is required!",
105
- name: 'firstName',
106
- },
107
- ]);
108
- const errors = mapFieldErrorsToParameterErrors(errs);
109
- assert.isLength(errors, 3);
110
- errorAssertUtil.assertError(errors[0], 'MISSING_PARAMETERS', {
111
- parameters: ['firstName'],
112
- });
113
- errorAssertUtil.assertError(errors[1], 'INVALID_PARAMETERS', {
114
- parameters: ['email'],
115
- });
116
- errorAssertUtil.assertError(errors[2], 'UNEXPECTED_PARAMETERS', {
117
- parameters: ['phone'],
118
- });
119
- });
120
- }
121
- static mapsSubErrors() {
122
- const errs = this.Error([
123
- {
124
- code: 'UNEXPECTED_PARAMETER',
125
- name: 'phone',
126
- },
127
- {
128
- code: 'INVALID_PARAMETER',
129
- name: 'address',
130
- errors: [
131
- {
132
- code: 'MISSING_PARAMETER',
133
- name: 'street1',
134
- },
135
- ],
136
- },
137
- {
138
- code: 'MISSING_PARAMETER',
139
- friendlyMessage: "'First name' is required!",
140
- name: 'firstName',
141
- },
142
- ]);
143
- const errors = mapFieldErrorsToParameterErrors(errs);
144
- assert.isLength(errors, 2);
145
- errorAssertUtil.assertError(errors[0], 'MISSING_PARAMETERS', {
146
- parameters: ['address.street1', 'firstName'],
147
- });
148
- errorAssertUtil.assertError(errors[1], 'UNEXPECTED_PARAMETERS', {
149
- parameters: ['phone'],
150
- });
151
- }
152
- static Error(errors) {
153
- return errors;
154
- }
155
- }
156
- __decorate([
157
- test()
158
- ], ErrorMapUtilTest, "canCreateErrorMapUtil", null);
159
- __decorate([
160
- test()
161
- ], ErrorMapUtilTest, "mapsMissingField", null);
162
- __decorate([
163
- test()
164
- ], ErrorMapUtilTest, "maps2MissingFields", null);
165
- __decorate([
166
- test()
167
- ], ErrorMapUtilTest, "mapsInvalidParameters", null);
168
- __decorate([
169
- test()
170
- ], ErrorMapUtilTest, "mapsUnexpectedParameters", null);
171
- __decorate([
172
- test()
173
- ], ErrorMapUtilTest, "mapsAll", null);
174
- __decorate([
175
- test()
176
- ], ErrorMapUtilTest, "mapsSubErrors", null);
@@ -1,4 +0,0 @@
1
- import AbstractSpruceTest from '@sprucelabs/test';
2
- export default class TextFieldTest extends AbstractSpruceTest {
3
- protected static buildSelectField(): Promise<void>;
4
- }
@@ -1,35 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- import AbstractSpruceTest, { test, assert } from '@sprucelabs/test';
17
- import FieldFactory from '../../factories/FieldFactory.js';
18
- const choices = [
19
- { value: 'foo', label: 'Foo' },
20
- { value: 'bar', label: 'Bar' },
21
- ];
22
- export default class TextFieldTest extends AbstractSpruceTest {
23
- static buildSelectField() {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const field = FieldFactory.Field('test', {
26
- type: 'select',
27
- options: { choices },
28
- });
29
- assert.isEqualDeep(field.definition.options.choices, choices);
30
- });
31
- }
32
- }
33
- __decorate([
34
- test()
35
- ], TextFieldTest, "buildSelectField", null);