@sprucelabs/schema 25.5.62 → 25.5.66

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 (94) 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/normalizeFieldValue.d.ts +1 -1
  6. package/package.json +15 -14
  7. package/build/esm/__tests__/behavioral/AssertingSelectOptions.test.d.ts +0 -7
  8. package/build/esm/__tests__/behavioral/AssertingSelectOptions.test.js +0 -93
  9. package/build/esm/__tests__/behavioral/AssertingValidationErrors.test.d.ts +0 -18
  10. package/build/esm/__tests__/behavioral/AssertingValidationErrors.test.js +0 -217
  11. package/build/esm/__tests__/behavioral/BuildSchema.test.d.ts +0 -5
  12. package/build/esm/__tests__/behavioral/BuildSchema.test.js +0 -66
  13. package/build/esm/__tests__/behavioral/CreatingEntityInstances.test.d.ts +0 -7
  14. package/build/esm/__tests__/behavioral/CreatingEntityInstances.test.js +0 -93
  15. package/build/esm/__tests__/behavioral/DroppingFields.test.d.ts +0 -5
  16. package/build/esm/__tests__/behavioral/DroppingFields.test.js +0 -86
  17. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplates.test.d.ts +0 -9
  18. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplates.test.js +0 -137
  19. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplatesWithSuffix.test.d.ts +0 -5
  20. package/build/esm/__tests__/behavioral/GeneratesRelationshipTemplatesWithSuffix.test.js +0 -146
  21. package/build/esm/__tests__/behavioral/GeneratesTemplates.test.d.ts +0 -5
  22. package/build/esm/__tests__/behavioral/GeneratesTemplates.test.js +0 -67
  23. package/build/esm/__tests__/behavioral/GeneratesTypeMappers.test.d.ts +0 -5
  24. package/build/esm/__tests__/behavioral/GeneratesTypeMappers.test.js +0 -29
  25. package/build/esm/__tests__/behavioral/GeneratesVersionedRelationshipTemplates.test.d.ts +0 -11
  26. package/build/esm/__tests__/behavioral/GeneratesVersionedRelationshipTemplates.test.js +0 -191
  27. package/build/esm/__tests__/behavioral/GettingFieldsOffASchema.test.d.ts +0 -7
  28. package/build/esm/__tests__/behavioral/GettingFieldsOffASchema.test.js +0 -88
  29. package/build/esm/__tests__/behavioral/HandlesDynamicFields.test.d.ts +0 -17
  30. package/build/esm/__tests__/behavioral/HandlesDynamicFields.test.js +0 -284
  31. package/build/esm/__tests__/behavioral/HandlesHidingPrivateFields.test.d.ts +0 -11
  32. package/build/esm/__tests__/behavioral/HandlesHidingPrivateFields.test.js +0 -111
  33. package/build/esm/__tests__/behavioral/HandlesRelationships.test.d.ts +0 -9
  34. package/build/esm/__tests__/behavioral/HandlesRelationships.test.js +0 -175
  35. package/build/esm/__tests__/behavioral/HandlesRequiredFields.test.d.ts +0 -4
  36. package/build/esm/__tests__/behavioral/HandlesRequiredFields.test.js +0 -37
  37. package/build/esm/__tests__/behavioral/HandlesVersionedRelationships.test.d.ts +0 -6
  38. package/build/esm/__tests__/behavioral/HandlesVersionedRelationships.test.js +0 -102
  39. package/build/esm/__tests__/behavioral/HandlesVersioning.test.d.ts +0 -8
  40. package/build/esm/__tests__/behavioral/HandlesVersioning.test.js +0 -93
  41. package/build/esm/__tests__/behavioral/IsIdWithVersion.test.d.ts +0 -4
  42. package/build/esm/__tests__/behavioral/IsIdWithVersion.test.js +0 -30
  43. package/build/esm/__tests__/behavioral/MakingFieldsOptional.test.d.ts +0 -4
  44. package/build/esm/__tests__/behavioral/MakingFieldsOptional.test.js +0 -57
  45. package/build/esm/__tests__/behavioral/NormalizeToSchemaIdWithVersion.test.d.ts +0 -6
  46. package/build/esm/__tests__/behavioral/NormalizeToSchemaIdWithVersion.test.js +0 -77
  47. package/build/esm/__tests__/behavioral/NormalizingSchemaValues.test.d.ts +0 -8
  48. package/build/esm/__tests__/behavioral/NormalizingSchemaValues.test.js +0 -148
  49. package/build/esm/__tests__/behavioral/ResetsSchemasEveryTest.test.d.ts +0 -6
  50. package/build/esm/__tests__/behavioral/ResetsSchemasEveryTest.test.js +0 -45
  51. package/build/esm/__tests__/behavioral/SchemaDefaultValues.test.d.ts +0 -9
  52. package/build/esm/__tests__/behavioral/SchemaDefaultValues.test.js +0 -138
  53. package/build/esm/__tests__/behavioral/SelectChoicesToHash.test.d.ts +0 -4
  54. package/build/esm/__tests__/behavioral/SelectChoicesToHash.test.js +0 -43
  55. package/build/esm/__tests__/behavioral/SettingMinAndMaxValuesOnArrayFields.test.d.ts +0 -9
  56. package/build/esm/__tests__/behavioral/SettingMinAndMaxValuesOnArrayFields.test.js +0 -104
  57. package/build/esm/__tests__/behavioral/UsingSchemas.test.d.ts +0 -13
  58. package/build/esm/__tests__/behavioral/UsingSchemas.test.js +0 -281
  59. package/build/esm/__tests__/behavioral/UsingTheSchemaRegisteryForNamespacedSchemas.test.d.ts +0 -14
  60. package/build/esm/__tests__/behavioral/UsingTheSchemaRegisteryForNamespacedSchemas.test.js +0 -140
  61. package/build/esm/__tests__/behavioral/UsingTheSchemaRegistry.test.d.ts +0 -15
  62. package/build/esm/__tests__/behavioral/UsingTheSchemaRegistry.test.js +0 -117
  63. package/build/esm/__tests__/behavioral/ValidatingSchemaValues.test.d.ts +0 -28
  64. package/build/esm/__tests__/behavioral/ValidatingSchemaValues.test.js +0 -674
  65. package/build/esm/__tests__/data/personWithCars.d.ts +0 -188
  66. package/build/esm/__tests__/data/personWithCars.js +0 -163
  67. package/build/esm/__tests__/data/versionedPersonWithCars.d.ts +0 -323
  68. package/build/esm/__tests__/data/versionedPersonWithCars.js +0 -281
  69. package/build/esm/__tests__/implementation/BooleanField.test.d.ts +0 -6
  70. package/build/esm/__tests__/implementation/BooleanField.test.js +0 -59
  71. package/build/esm/__tests__/implementation/DurationField.test.d.ts +0 -7
  72. package/build/esm/__tests__/implementation/DurationField.test.js +0 -45
  73. package/build/esm/__tests__/implementation/EmailField.test.d.ts +0 -4
  74. package/build/esm/__tests__/implementation/EmailField.test.js +0 -39
  75. package/build/esm/__tests__/implementation/ErrorMapUtil.test.d.ts +0 -11
  76. package/build/esm/__tests__/implementation/ErrorMapUtil.test.js +0 -176
  77. package/build/esm/__tests__/implementation/FieldFactory.test.d.ts +0 -4
  78. package/build/esm/__tests__/implementation/FieldFactory.test.js +0 -35
  79. package/build/esm/__tests__/implementation/FileField.test.d.ts +0 -19
  80. package/build/esm/__tests__/implementation/FileField.test.js +0 -125
  81. package/build/esm/__tests__/implementation/NumberField.test.d.ts +0 -5
  82. package/build/esm/__tests__/implementation/NumberField.test.js +0 -54
  83. package/build/esm/__tests__/implementation/PhoneField.test.d.ts +0 -7
  84. package/build/esm/__tests__/implementation/PhoneField.test.js +0 -82
  85. package/build/esm/__tests__/implementation/SchemaFieldTransformingOptions.test.d.ts +0 -5
  86. package/build/esm/__tests__/implementation/SchemaFieldTransformingOptions.test.js +0 -209
  87. package/build/esm/__tests__/implementation/SchemaFieldValidation.test.d.ts +0 -8
  88. package/build/esm/__tests__/implementation/SchemaFieldValidation.test.js +0 -87
  89. package/build/esm/__tests__/implementation/SelectField.test.d.ts +0 -8
  90. package/build/esm/__tests__/implementation/SelectField.test.js +0 -127
  91. package/build/esm/__tests__/implementation/TextField.test.d.ts +0 -4
  92. package/build/esm/__tests__/implementation/TextField.test.js +0 -34
  93. package/build/esm/__tests__/implementation/ValidateErrorMessageFormatter.test.d.ts +0 -16
  94. package/build/esm/__tests__/implementation/ValidateErrorMessageFormatter.test.js +0 -216
@@ -1,674 +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 { test, assert } from '@sprucelabs/test';
17
- import AbstractSchemaTest from '../../AbstractSchemaTest.js';
18
- import SpruceError from '../../errors/SpruceError.js';
19
- import validationErrorAssertUtil from '../../tests/validationErrorAssert.utility.js';
20
- import areSchemaValuesValid from '../../utilities/areSchemaValuesValid.js';
21
- import buildSchema from '../../utilities/buildSchema.js';
22
- import isSchemaValid from '../../utilities/isSchemaValid.js';
23
- import validateSchemaValues from '../../utilities/validateSchemaValues.js';
24
- const profileImagesSchema = buildSchema({
25
- id: 'profileImage',
26
- name: 'Profile Image Sizes',
27
- description: 'Various sizes that a profile image comes in.',
28
- fields: {
29
- profile60: {
30
- label: '60x60',
31
- type: 'text',
32
- isRequired: true,
33
- },
34
- profile150: {
35
- label: '150x150',
36
- type: 'text',
37
- isRequired: true,
38
- },
39
- 'profile60@2x': {
40
- label: '60x60',
41
- type: 'text',
42
- isRequired: true,
43
- },
44
- 'profile150@2x': {
45
- label: '150x150',
46
- type: 'text',
47
- isRequired: true,
48
- },
49
- },
50
- });
51
- const dynamicSchema = buildSchema({
52
- id: 'dynamicSchema',
53
- name: 'dynamic schema',
54
- dynamicFieldSignature: {
55
- type: 'text',
56
- keyName: 'anything',
57
- },
58
- });
59
- const personSchema = buildSchema({
60
- id: 'testPerson',
61
- name: 'A test person',
62
- fields: {
63
- firstName: {
64
- label: 'First name',
65
- type: 'text',
66
- isRequired: true,
67
- },
68
- lastName: {
69
- type: 'text',
70
- isRequired: true,
71
- },
72
- email: {
73
- type: 'text',
74
- isRequired: false,
75
- },
76
- profileImages: {
77
- isRequired: true,
78
- type: 'schema',
79
- options: {
80
- schema: profileImagesSchema,
81
- },
82
- },
83
- },
84
- });
85
- const personWithFavColorsSchema = buildSchema({
86
- id: 'personWithFavColors',
87
- fields: {
88
- firstName: {
89
- type: 'text',
90
- isRequired: true,
91
- },
92
- lastName: {
93
- type: 'text',
94
- isRequired: true,
95
- },
96
- favoriteColors: {
97
- type: 'text',
98
- isArray: true,
99
- isRequired: true,
100
- },
101
- },
102
- });
103
- const toolSchema = buildSchema({
104
- id: 'tool',
105
- fields: {
106
- name: {
107
- type: 'text',
108
- isRequired: true,
109
- },
110
- },
111
- });
112
- const fruitSchema = buildSchema({
113
- id: 'fruit',
114
- fields: {
115
- color: {
116
- type: 'select',
117
- isRequired: true,
118
- options: {
119
- choices: [
120
- {
121
- value: 'yellow',
122
- label: 'Yellow',
123
- },
124
- {
125
- value: 'green',
126
- label: 'Green',
127
- },
128
- ],
129
- },
130
- },
131
- },
132
- });
133
- const versionedToolSchema = buildSchema({
134
- id: 'versionedTool',
135
- version: '1.0',
136
- fields: {
137
- name: {
138
- type: 'text',
139
- isRequired: true,
140
- },
141
- age: {
142
- type: 'number',
143
- isRequired: true,
144
- },
145
- },
146
- });
147
- const version2ToolSchema = buildSchema({
148
- id: 'versionedTool',
149
- version: '2.0',
150
- fields: {
151
- size: {
152
- type: 'text',
153
- isRequired: true,
154
- },
155
- },
156
- });
157
- const versionedFruitSchema = buildSchema({
158
- id: 'versionedFruit',
159
- version: '1.0',
160
- fields: {
161
- color: {
162
- type: 'select',
163
- isRequired: true,
164
- options: {
165
- choices: [
166
- {
167
- value: 'yellow',
168
- label: 'Yellow',
169
- },
170
- {
171
- value: 'green',
172
- label: 'Green',
173
- },
174
- ],
175
- },
176
- },
177
- },
178
- });
179
- const personWithFavToolsSchema = buildSchema({
180
- id: 'personWithFavTools',
181
- name: 'Person with favorite tools',
182
- fields: {
183
- firstName: {
184
- type: 'text',
185
- isRequired: true,
186
- },
187
- lastName: {
188
- type: 'text',
189
- },
190
- favoriteTools: {
191
- isRequired: true,
192
- type: 'schema',
193
- isArray: true,
194
- options: {
195
- schema: toolSchema,
196
- },
197
- },
198
- },
199
- });
200
- const personWithFavToolsOrFruitSchema = buildSchema({
201
- id: 'personWithFavToolsOrFruit',
202
- name: 'Person with favorite tools',
203
- fields: {
204
- firstName: {
205
- type: 'text',
206
- isRequired: true,
207
- },
208
- phone: {
209
- type: 'phone',
210
- },
211
- lastName: {
212
- type: 'text',
213
- },
214
- favoriteToolsOrFruit: {
215
- isRequired: true,
216
- type: 'schema',
217
- isArray: true,
218
- options: {
219
- schemas: [toolSchema, fruitSchema],
220
- },
221
- },
222
- },
223
- });
224
- const versionedPersonWithFavToolsOrFruitSchema = buildSchema({
225
- id: 'versionedPersonWithFavToolsOrFruit',
226
- name: 'Person with favorite tools',
227
- fields: {
228
- firstName: {
229
- type: 'text',
230
- label: 'First name',
231
- isRequired: true,
232
- },
233
- lastName: {
234
- type: 'text',
235
- },
236
- favoriteToolsOrFruit: {
237
- isRequired: true,
238
- type: 'schema',
239
- isArray: true,
240
- options: {
241
- schemas: [
242
- versionedFruitSchema,
243
- versionedToolSchema,
244
- version2ToolSchema,
245
- ],
246
- },
247
- },
248
- },
249
- });
250
- const dynamicFieldSchema = buildSchema({
251
- id: 'dynamicSchemaValuesTest',
252
- dynamicFieldSignature: {
253
- type: 'schema',
254
- keyName: 'eventName',
255
- options: {
256
- schema: personSchema,
257
- },
258
- },
259
- });
260
- export default class CanValidateSchemasTest extends AbstractSchemaTest {
261
- static beforeEach() {
262
- const _super = Object.create(null, {
263
- beforeEach: { get: () => super.beforeEach }
264
- });
265
- return __awaiter(this, void 0, void 0, function* () {
266
- yield _super.beforeEach.call(this);
267
- });
268
- }
269
- static canValidateBasicSchemaValues() {
270
- return __awaiter(this, void 0, void 0, function* () {
271
- const err = assert.doesThrow(() => validateSchemaValues(personSchema, {}));
272
- assert.doesInclude(err.message, '3 errors');
273
- assert.doesInclude(err.message, `1. 'firstName' is required`);
274
- assert.doesInclude(err.message, `2. 'lastName' is required`);
275
- assert.doesInclude(err.message, `3. 'profileImages' is required`);
276
- });
277
- }
278
- static canValidateSchemaWithArrayValues() {
279
- return __awaiter(this, void 0, void 0, function* () {
280
- assert.doesThrow(() => validateSchemaValues(personWithFavColorsSchema, {
281
- firstName: 'tay',
282
- lastName: 'ro',
283
- }), /'favoriteColors' is required/gi);
284
- });
285
- }
286
- static typesValidatedValues() {
287
- return __awaiter(this, void 0, void 0, function* () {
288
- const values = {
289
- firstName: 'Bob',
290
- lastName: 'Bob',
291
- profileImages: {
292
- profile60: '@',
293
- profile150: '@',
294
- 'profile60@2x': '@',
295
- 'profile150@2x': '@',
296
- },
297
- };
298
- validateSchemaValues(personSchema, values);
299
- assert.isType(values);
300
- assert.isType(values.email);
301
- });
302
- }
303
- static canValidateSpecificFields() {
304
- return __awaiter(this, void 0, void 0, function* () {
305
- const err = assert.doesThrow(() => validateSchemaValues(personSchema, {}, { fields: ['firstName'] }));
306
- assert.doesNotInclude(err.message, /lastName/gi);
307
- });
308
- }
309
- static canCheckValidityWithoutThrowing() {
310
- return __awaiter(this, void 0, void 0, function* () {
311
- const isValid = areSchemaValuesValid(personSchema, {});
312
- assert.isFalse(isValid);
313
- });
314
- }
315
- static canCheckValidityOnDynamicFieldsWithoutThrowing() {
316
- return __awaiter(this, void 0, void 0, function* () {
317
- const isValid = isSchemaValid(dynamicSchema);
318
- assert.isTrue(isValid);
319
- });
320
- }
321
- static canCheckValidityOnSpecificFields() {
322
- return __awaiter(this, void 0, void 0, function* () {
323
- const isValid = areSchemaValuesValid(personSchema, { firstName: 'test' }, { fields: ['firstName'] });
324
- assert.isTrue(isValid);
325
- });
326
- }
327
- static failsOnSpecificFields() {
328
- return __awaiter(this, void 0, void 0, function* () {
329
- const isValid = areSchemaValuesValid(personSchema, { firstName: 'test' }, { fields: ['lastName'] });
330
- assert.isFalse(isValid);
331
- });
332
- }
333
- static passesWithValidPerson() {
334
- return __awaiter(this, void 0, void 0, function* () {
335
- const person = {
336
- firstName: 'firstName',
337
- lastName: 'lastName',
338
- profileImages: {
339
- profile60: '@',
340
- profile150: '@',
341
- 'profile60@2x': '@',
342
- 'profile150@2x': '@',
343
- },
344
- };
345
- validateSchemaValues(personSchema, person);
346
- });
347
- }
348
- static failsWithBadSchema() {
349
- return __awaiter(this, void 0, void 0, function* () {
350
- assert.doesThrow(
351
- //@ts-ignore
352
- () => validateSchemaValues(null, {}), /Invalid schema/);
353
- });
354
- }
355
- static failsWhenValidatingFieldsNotOnSchema() {
356
- return __awaiter(this, void 0, void 0, function* () {
357
- const err = assert.doesThrow(() => validateSchemaValues(personSchema, {
358
- taco: 'bravo',
359
- firstName: 'first',
360
- lastName: 'last',
361
- profileImages: {
362
- profile60: '@',
363
- profile150: '@',
364
- 'profile60@2x': '@',
365
- 'profile150@2x': '@',
366
- },
367
- }), /does not exist/);
368
- validationErrorAssertUtil.assertError(err, {
369
- unexpected: ['taco'],
370
- });
371
- assert.doesInclude(err.message, 'taco');
372
- });
373
- }
374
- static givesInvalidFieldErrorWhenValidatingEmptyArrayNestedSchemas() {
375
- return __awaiter(this, void 0, void 0, function* () {
376
- const err = assert.doesThrow(() => validateSchemaValues(personWithFavToolsSchema, {
377
- firstName: 'first',
378
- lastName: 'last',
379
- favoriteTools: [],
380
- }), /'favoriteTools' must have at least 1/);
381
- validationErrorAssertUtil.assertError(err, {
382
- invalid: ['favoriteTools'],
383
- });
384
- });
385
- }
386
- static givesInvalidFieldErrorWhenValidatingNestedSchemas() {
387
- return __awaiter(this, void 0, void 0, function* () {
388
- const err = assert.doesThrow(() => validateSchemaValues(personWithFavToolsSchema, {
389
- firstName: 'first',
390
- lastName: 'last',
391
- //@ts-ignore
392
- favoriteTools: [{}],
393
- }), /'favoriteTools.name' is required/);
394
- validationErrorAssertUtil.assertError(err, {
395
- missing: ['favoriteTools.name'],
396
- });
397
- });
398
- }
399
- static canValidateNestedArraySchema() {
400
- return __awaiter(this, void 0, void 0, function* () {
401
- validateSchemaValues(personWithFavToolsSchema, {
402
- firstName: 'Tay',
403
- favoriteTools: [
404
- {
405
- name: 'Laptop',
406
- },
407
- ],
408
- });
409
- });
410
- }
411
- static canValidateArrayOfUnionValuesMissingRequired() {
412
- return __awaiter(this, void 0, void 0, function* () {
413
- assert.doesThrow(() => validateSchemaValues(personWithFavToolsOrFruitSchema, {
414
- firstName: 'Ryan',
415
- favoriteToolsOrFruit: [],
416
- }), /'favoriteToolsOrFruit' must have at least 1/gi);
417
- });
418
- }
419
- static canValidateArrayOfUnionValues() {
420
- return __awaiter(this, void 0, void 0, function* () {
421
- validateSchemaValues(personWithFavToolsOrFruitSchema, {
422
- firstName: 'Ryan',
423
- favoriteToolsOrFruit: [
424
- {
425
- schemaId: 'fruit',
426
- values: {
427
- color: 'green',
428
- },
429
- },
430
- {
431
- schemaId: 'fruit',
432
- values: {
433
- color: 'yellow',
434
- },
435
- },
436
- {
437
- schemaId: 'tool',
438
- values: {
439
- name: 'wrench',
440
- },
441
- },
442
- ],
443
- });
444
- });
445
- }
446
- static canValidateArrayOfVersionedUnionValues() {
447
- return __awaiter(this, void 0, void 0, function* () {
448
- validateSchemaValues(versionedPersonWithFavToolsOrFruitSchema, {
449
- firstName: 'Ryan',
450
- favoriteToolsOrFruit: [
451
- {
452
- schemaId: 'versionedFruit',
453
- version: '1.0',
454
- values: {
455
- color: 'green',
456
- },
457
- },
458
- {
459
- schemaId: 'versionedFruit',
460
- version: '1.0',
461
- values: {
462
- color: 'yellow',
463
- },
464
- },
465
- {
466
- schemaId: 'versionedTool',
467
- version: '1.0',
468
- values: {
469
- name: 'wrench',
470
- age: 10,
471
- },
472
- },
473
- {
474
- schemaId: 'versionedTool',
475
- version: '2.0',
476
- values: {
477
- size: 'wrench',
478
- },
479
- },
480
- ],
481
- });
482
- });
483
- }
484
- static canValidateArrayOfVersionedUnionValuesAndThrowsReallyHelpfulError() {
485
- return __awaiter(this, void 0, void 0, function* () {
486
- /*Const err =*/
487
- assert.doesThrow(() => validateSchemaValues(versionedPersonWithFavToolsOrFruitSchema, {
488
- favoriteToolsOrFruit: [
489
- {
490
- schemaId: 'versionedFruit',
491
- version: '1.0',
492
- values: {
493
- color: 'green',
494
- },
495
- },
496
- {
497
- schemaId: 'versionedFruit',
498
- version: '1.0',
499
- values: {
500
- color: 'yellow',
501
- },
502
- },
503
- {
504
- schemaId: 'versionedTool',
505
- version: '1.0',
506
- values: {
507
- size: 'wrench',
508
- },
509
- },
510
- {
511
- schemaId: 'versionedTool',
512
- version: '2.0',
513
- values: {
514
- name: 'wrench',
515
- },
516
- },
517
- ],
518
- }));
519
- // NOTE uncomment here and above to see error output
520
- // const message = err.friendlyMessage()
521
- // console.log(message)
522
- // debugger
523
- });
524
- }
525
- static throwsWhenAddingExtraFieldAtTopLevel() {
526
- assert.doesThrow(() => validateSchemaValues(personWithFavToolsOrFruitSchema, {
527
- firstName: 'Ryan',
528
- doesNotExist: true,
529
- favoriteToolsOrFruit: [
530
- {
531
- schemaId: 'fruit',
532
- values: {
533
- color: 'green',
534
- },
535
- },
536
- ],
537
- }), /doesNotExist/);
538
- }
539
- static throwsWhenAddingExtraFieldInNestedSchema() {
540
- assert.doesThrow(() => validateSchemaValues(personWithFavToolsOrFruitSchema, {
541
- firstName: 'Ryan',
542
- favoriteToolsOrFruit: [
543
- {
544
- schemaId: 'fruit',
545
- values: {
546
- doesNotExist: true,
547
- color: 'green',
548
- },
549
- },
550
- ],
551
- }), /doesNotExist/);
552
- }
553
- static validationErrorsAreTyped() {
554
- try {
555
- validateSchemaValues(personWithFavToolsOrFruitSchema, {
556
- firstName: 'Ryan',
557
- favoriteToolsOrFruit: [],
558
- });
559
- }
560
- catch (err) {
561
- if (err instanceof SpruceError) {
562
- if (err.options.code === 'VALIDATION_FAILED') {
563
- const first = err.options.errors[0].code;
564
- assert.isExactType(true);
565
- }
566
- }
567
- else {
568
- assert.fail('Bad error returned');
569
- }
570
- }
571
- }
572
- static printsSoPretty() {
573
- try {
574
- validateSchemaValues(personWithFavToolsOrFruitSchema, {
575
- //@ts-ignore
576
- taco: [],
577
- phone: 'satnoehusntah',
578
- favoriteToolsOrFruit: [{ schemaId: 'tool', values: { cheba: 'hut' } }],
579
- });
580
- }
581
- catch (err) {
582
- this.log(err.message);
583
- }
584
- }
585
- static dynamicSchemasHaveFieldNameInError() {
586
- const err = assert.doesThrow(() => validateSchemaValues(dynamicFieldSchema, {
587
- //@ts-ignore
588
- taco: {
589
- //@ts-ignore
590
- hey: 'there',
591
- },
592
- }));
593
- assert.doesInclude(err.message, 'taco');
594
- assert.doesInclude(err.message, 'hey');
595
- }
596
- static invalidFieldsGiveDescriptionsOnWhySomethingIsInvalid() {
597
- const err = assert.doesThrow(() => validateSchemaValues(personWithFavToolsOrFruitSchema, {
598
- phone: 'cheesy',
599
- }));
600
- assert.doesInclude(err.message, 'US number');
601
- }
602
- }
603
- __decorate([
604
- test()
605
- ], CanValidateSchemasTest, "canValidateBasicSchemaValues", null);
606
- __decorate([
607
- test()
608
- ], CanValidateSchemasTest, "canValidateSchemaWithArrayValues", null);
609
- __decorate([
610
- test()
611
- ], CanValidateSchemasTest, "typesValidatedValues", null);
612
- __decorate([
613
- test()
614
- ], CanValidateSchemasTest, "canValidateSpecificFields", null);
615
- __decorate([
616
- test()
617
- ], CanValidateSchemasTest, "canCheckValidityWithoutThrowing", null);
618
- __decorate([
619
- test()
620
- ], CanValidateSchemasTest, "canCheckValidityOnDynamicFieldsWithoutThrowing", null);
621
- __decorate([
622
- test()
623
- ], CanValidateSchemasTest, "canCheckValidityOnSpecificFields", null);
624
- __decorate([
625
- test()
626
- ], CanValidateSchemasTest, "failsOnSpecificFields", null);
627
- __decorate([
628
- test()
629
- ], CanValidateSchemasTest, "passesWithValidPerson", null);
630
- __decorate([
631
- test()
632
- ], CanValidateSchemasTest, "failsWithBadSchema", null);
633
- __decorate([
634
- test()
635
- ], CanValidateSchemasTest, "failsWhenValidatingFieldsNotOnSchema", null);
636
- __decorate([
637
- test()
638
- ], CanValidateSchemasTest, "givesInvalidFieldErrorWhenValidatingEmptyArrayNestedSchemas", null);
639
- __decorate([
640
- test()
641
- ], CanValidateSchemasTest, "givesInvalidFieldErrorWhenValidatingNestedSchemas", null);
642
- __decorate([
643
- test()
644
- ], CanValidateSchemasTest, "canValidateNestedArraySchema", null);
645
- __decorate([
646
- test()
647
- ], CanValidateSchemasTest, "canValidateArrayOfUnionValuesMissingRequired", null);
648
- __decorate([
649
- test()
650
- ], CanValidateSchemasTest, "canValidateArrayOfUnionValues", null);
651
- __decorate([
652
- test()
653
- ], CanValidateSchemasTest, "canValidateArrayOfVersionedUnionValues", null);
654
- __decorate([
655
- test()
656
- ], CanValidateSchemasTest, "canValidateArrayOfVersionedUnionValuesAndThrowsReallyHelpfulError", null);
657
- __decorate([
658
- test()
659
- ], CanValidateSchemasTest, "throwsWhenAddingExtraFieldAtTopLevel", null);
660
- __decorate([
661
- test()
662
- ], CanValidateSchemasTest, "throwsWhenAddingExtraFieldInNestedSchema", null);
663
- __decorate([
664
- test('validation errors are typed (will always pass, lint will fail)')
665
- ], CanValidateSchemasTest, "validationErrorsAreTyped", null);
666
- __decorate([
667
- test.skip('pretty print of validation test (skip to pass tests)')
668
- ], CanValidateSchemasTest, "printsSoPretty", null);
669
- __decorate([
670
- test()
671
- ], CanValidateSchemasTest, "dynamicSchemasHaveFieldNameInError", null);
672
- __decorate([
673
- test()
674
- ], CanValidateSchemasTest, "invalidFieldsGiveDescriptionsOnWhySomethingIsInvalid", null);