@sprucelabs/schema 25.3.535 → 25.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/esm/__tests__/behavioral/AssertingSelectOptions.test.d.ts +7 -0
- package/build/esm/__tests__/behavioral/AssertingSelectOptions.test.js +93 -0
- package/build/esm/index.d.ts +1 -0
- package/build/esm/index.js +1 -0
- package/build/esm/tests/selectAssert.utility.d.ts +5 -0
- package/build/esm/tests/selectAssert.utility.js +11 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +3 -1
- package/build/tests/selectAssert.utility.d.ts +5 -0
- package/build/tests/selectAssert.utility.js +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import AbstractSpruceTest from '@sprucelabs/test';
|
|
2
|
+
export default class AssertingSelectOptionsTest extends AbstractSpruceTest {
|
|
3
|
+
protected static canCreateAssertSelectOptions(): void;
|
|
4
|
+
protected static knowsIfChoicesDontMatch(choices: any, expected: any): void;
|
|
5
|
+
protected static knowsIfSingeOptionMatches(options: any, expected: any): void;
|
|
6
|
+
protected static canType(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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 selectAssertUtil from '../../tests/selectAssert.utility.js';
|
|
9
|
+
export default class AssertingSelectOptionsTest extends AbstractSpruceTest {
|
|
10
|
+
static canCreateAssertSelectOptions() {
|
|
11
|
+
assert.isFunction(selectAssertUtil.assertSelectChoicesMatch);
|
|
12
|
+
}
|
|
13
|
+
static knowsIfChoicesDontMatch(choices, expected) {
|
|
14
|
+
assert.doesThrow(() => selectAssertUtil.assertSelectChoicesMatch(choices, expected));
|
|
15
|
+
}
|
|
16
|
+
static knowsIfSingeOptionMatches(options, expected) {
|
|
17
|
+
selectAssertUtil.assertSelectChoicesMatch(options, expected);
|
|
18
|
+
}
|
|
19
|
+
static canType() {
|
|
20
|
+
selectAssertUtil.assertSelectChoicesMatch([
|
|
21
|
+
{
|
|
22
|
+
value: 'hello',
|
|
23
|
+
label: 'World!',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
value: 'no',
|
|
27
|
+
label: 'Way',
|
|
28
|
+
},
|
|
29
|
+
], ['hello', 'no']);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
__decorate([
|
|
33
|
+
test()
|
|
34
|
+
], AssertingSelectOptionsTest, "canCreateAssertSelectOptions", null);
|
|
35
|
+
__decorate([
|
|
36
|
+
test('throws if single option does not match', [
|
|
37
|
+
{
|
|
38
|
+
value: 'hello',
|
|
39
|
+
label: 'World!',
|
|
40
|
+
},
|
|
41
|
+
], ['no']),
|
|
42
|
+
test('throws if choices outnumber expected does not match', [
|
|
43
|
+
{
|
|
44
|
+
value: 'hello',
|
|
45
|
+
label: 'World!',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
value: 'no',
|
|
49
|
+
label: 'way!',
|
|
50
|
+
},
|
|
51
|
+
], ['no']),
|
|
52
|
+
test('throws if not all choices match', [
|
|
53
|
+
{
|
|
54
|
+
value: 'hello',
|
|
55
|
+
label: 'World!',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
value: 'no',
|
|
59
|
+
label: 'way!',
|
|
60
|
+
},
|
|
61
|
+
], ['no', 'word'])
|
|
62
|
+
], AssertingSelectOptionsTest, "knowsIfChoicesDontMatch", null);
|
|
63
|
+
__decorate([
|
|
64
|
+
test('matches single choices', [
|
|
65
|
+
{
|
|
66
|
+
value: 'hello',
|
|
67
|
+
label: 'World!',
|
|
68
|
+
},
|
|
69
|
+
], ['hello']),
|
|
70
|
+
test('matches in order', [
|
|
71
|
+
{
|
|
72
|
+
value: 'hello',
|
|
73
|
+
label: 'World!',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
value: 'no',
|
|
77
|
+
label: 'Way',
|
|
78
|
+
},
|
|
79
|
+
], ['hello', 'no']),
|
|
80
|
+
test('matches out of order', [
|
|
81
|
+
{
|
|
82
|
+
value: 'hello',
|
|
83
|
+
label: 'World!',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
value: 'no',
|
|
87
|
+
label: 'Way',
|
|
88
|
+
},
|
|
89
|
+
], ['no', 'hello'])
|
|
90
|
+
], AssertingSelectOptionsTest, "knowsIfSingeOptionMatches", null);
|
|
91
|
+
__decorate([
|
|
92
|
+
test('is typed correctly (will always pass)')
|
|
93
|
+
], AssertingSelectOptionsTest, "canType", null);
|
package/build/esm/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import StaticSchemaEntityImplementation from './StaticSchemaEntityImplementation
|
|
|
3
3
|
import { FieldRegistration } from './utilities/registerFieldType';
|
|
4
4
|
export default StaticSchemaEntityImplementation;
|
|
5
5
|
export { default as validationErrorAssertUtil } from './tests/validationErrorAssert.utility';
|
|
6
|
+
export { default as selectAssertUtil } from './tests/selectAssert.utility';
|
|
6
7
|
export * from './schemas.static.types';
|
|
7
8
|
export * from './fields';
|
|
8
9
|
export * from './errors/options.types';
|
package/build/esm/index.js
CHANGED
|
@@ -17,6 +17,7 @@ import textRegistration from './addons/textField.addon.js';
|
|
|
17
17
|
import StaticSchemaEntityImplementation from './StaticSchemaEntityImplementation.js';
|
|
18
18
|
export default StaticSchemaEntityImplementation;
|
|
19
19
|
export { default as validationErrorAssertUtil } from './tests/validationErrorAssert.utility.js';
|
|
20
|
+
export { default as selectAssertUtil } from './tests/selectAssert.utility.js';
|
|
20
21
|
export * from './schemas.static.types.js';
|
|
21
22
|
export * from './fields/index.js';
|
|
22
23
|
export * from './errors/options.types.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SelectChoice } from '../fields/SelectField.types';
|
|
2
|
+
declare const selectAssertUtil: {
|
|
3
|
+
assertSelectChoicesMatch<Choice extends SelectChoice, Values extends Choice["value"][number] = Choice["value"][number]>(choices: Choice[], expected: Values[]): void;
|
|
4
|
+
};
|
|
5
|
+
export default selectAssertUtil;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { assert } from '@sprucelabs/test';
|
|
2
|
+
const selectAssertUtil = {
|
|
3
|
+
assertSelectChoicesMatch(choices, expected) {
|
|
4
|
+
assert.isEqual(choices.length, expected.length, `Expected ${expected.length} choices, but found ${choices.length}!`);
|
|
5
|
+
const actualValues = choices.map((c) => c.value);
|
|
6
|
+
actualValues.sort();
|
|
7
|
+
expected.sort();
|
|
8
|
+
assert.isEqualDeep(actualValues, expected, `The options you sent don't match!`);
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
export default selectAssertUtil;
|
package/build/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import StaticSchemaEntityImplementation from './StaticSchemaEntityImplementation
|
|
|
3
3
|
import { FieldRegistration } from './utilities/registerFieldType';
|
|
4
4
|
export default StaticSchemaEntityImplementation;
|
|
5
5
|
export { default as validationErrorAssertUtil } from './tests/validationErrorAssert.utility';
|
|
6
|
+
export { default as selectAssertUtil } from './tests/selectAssert.utility';
|
|
6
7
|
export * from './schemas.static.types';
|
|
7
8
|
export * from './fields';
|
|
8
9
|
export * from './errors/options.types';
|
package/build/index.js
CHANGED
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.mapFieldErrorsToParameterErrors = exports.assertOptions = exports.fieldRegistrations = exports.SchemaRegistry = exports.SchemaEntityFactory = exports.FieldFactory = exports.normalizeSchemaToIdWithVersion = exports.isIdWithVersion = exports.formatPhoneNumber = exports.areSchemasTheSame = exports.isSchemaValid = exports.validateSchema = exports.dropPrivateFields = exports.dropFields = exports.makeFieldsOptional = exports.areSchemaValuesValid = exports.normalizeSchemaValues = exports.validateSchemaValues = exports.defaultSchemaValues = exports.registerFieldType = exports.buildSchema = exports.buildErrorSchema = exports.SchemaError = exports.validationErrorAssertUtil = void 0;
|
|
16
|
+
exports.mapFieldErrorsToParameterErrors = exports.assertOptions = exports.fieldRegistrations = exports.SchemaRegistry = exports.SchemaEntityFactory = exports.FieldFactory = exports.normalizeSchemaToIdWithVersion = exports.isIdWithVersion = exports.formatPhoneNumber = exports.areSchemasTheSame = exports.isSchemaValid = exports.validateSchema = exports.dropPrivateFields = exports.dropFields = exports.makeFieldsOptional = exports.areSchemaValuesValid = exports.normalizeSchemaValues = exports.validateSchemaValues = exports.defaultSchemaValues = exports.registerFieldType = exports.buildSchema = exports.buildErrorSchema = exports.SchemaError = exports.selectAssertUtil = exports.validationErrorAssertUtil = void 0;
|
|
17
17
|
__exportStar(require("./StaticSchemaEntityImplementation"), exports);
|
|
18
18
|
const addressField_addon_1 = __importDefault(require("./addons/addressField.addon"));
|
|
19
19
|
const booleanField_addon_1 = __importDefault(require("./addons/booleanField.addon"));
|
|
@@ -34,6 +34,8 @@ const StaticSchemaEntityImplementation_1 = __importDefault(require("./StaticSche
|
|
|
34
34
|
exports.default = StaticSchemaEntityImplementation_1.default;
|
|
35
35
|
var validationErrorAssert_utility_1 = require("./tests/validationErrorAssert.utility");
|
|
36
36
|
Object.defineProperty(exports, "validationErrorAssertUtil", { enumerable: true, get: function () { return __importDefault(validationErrorAssert_utility_1).default; } });
|
|
37
|
+
var selectAssert_utility_1 = require("./tests/selectAssert.utility");
|
|
38
|
+
Object.defineProperty(exports, "selectAssertUtil", { enumerable: true, get: function () { return __importDefault(selectAssert_utility_1).default; } });
|
|
37
39
|
__exportStar(require("./schemas.static.types"), exports);
|
|
38
40
|
__exportStar(require("./fields"), exports);
|
|
39
41
|
__exportStar(require("./errors/options.types"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SelectChoice } from '../fields/SelectField.types';
|
|
2
|
+
declare const selectAssertUtil: {
|
|
3
|
+
assertSelectChoicesMatch<Choice extends SelectChoice, Values extends Choice["value"][number] = Choice["value"][number]>(choices: Choice[], expected: Values[]): void;
|
|
4
|
+
};
|
|
5
|
+
export default selectAssertUtil;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const test_1 = require("@sprucelabs/test");
|
|
4
|
+
const selectAssertUtil = {
|
|
5
|
+
assertSelectChoicesMatch(choices, expected) {
|
|
6
|
+
test_1.assert.isEqual(choices.length, expected.length, `Expected ${expected.length} choices, but found ${choices.length}!`);
|
|
7
|
+
const actualValues = choices.map((c) => c.value);
|
|
8
|
+
actualValues.sort();
|
|
9
|
+
expected.sort();
|
|
10
|
+
test_1.assert.isEqualDeep(actualValues, expected, `The options you sent don't match!`);
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
exports.default = selectAssertUtil;
|