immosquare-cleaner 0.1.23 → 0.1.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/immosquare-cleaner/version.rb +1 -1
- data/linters/rubocop-3.2.2.yml +1 -0
- data/linters/rubocop.yml +2 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/LICENSE +19 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/README.md +71 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/conf/config-schema.js +79 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/conf/environments.js +215 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs +1104 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/dist/eslintrc-universal.cjs.map +1 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/dist/eslintrc.cjs +4333 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/dist/eslintrc.cjs.map +1 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/cascading-config-array-factory.js +532 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array/config-array.js +523 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array/config-dependency.js +115 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array/extracted-config.js +145 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array/ignore-pattern.js +238 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array/index.js +19 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array/override-tester.js +225 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/config-array-factory.js +1149 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/flat-compat.js +318 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/index-universal.js +29 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/index.js +56 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/ajv.js +191 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/config-ops.js +135 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/config-validator.js +325 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/deprecation-warnings.js +63 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/naming.js +96 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/relative-module-resolver.js +42 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/lib/shared/types.js +149 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/node_modules/strip-json-comments/index.d.ts +36 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/node_modules/strip-json-comments/index.js +77 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/node_modules/strip-json-comments/license +9 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/node_modules/strip-json-comments/package.json +47 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/node_modules/strip-json-comments/readme.md +78 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/package.json +82 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/eslintrc/universal.js +9 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/js/LICENSE +19 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/js/README.md +57 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/js/package.json +31 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/js/src/configs/eslint-all.js +278 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/js/src/configs/eslint-recommended.js +76 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@eslint/js/src/index.js +17 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/LICENSE +201 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/README.md +342 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/api.js +1061 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/CHANGELOG.md +8 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/LICENSE +29 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/README.md +234 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/package.json +33 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/src/index.js +7 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/src/merge-strategy.js +53 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/src/object-schema.js +235 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/src/validation-strategy.js +102 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/tests/merge-strategy.js +66 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/tests/object-schema.js +611 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/@humanwhocodes/object-schema/tests/validation-strategy.js +186 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/LICENSE +15 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/README.md +224 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/minimatch.js +947 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/node_modules/brace-expansion/LICENSE +21 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/node_modules/brace-expansion/README.md +129 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/node_modules/brace-expansion/index.js +201 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/node_modules/brace-expansion/package.json +47 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/node_modules/minimatch/package.json +33 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/@humanwhocodes/config-array/package.json +61 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/index.d.ts +415 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/license +9 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/package.json +68 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/readme.md +341 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/source/index.js +229 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/source/templates.js +134 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/chalk/source/util.js +39 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/LICENSE +15 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/README.md +230 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/minimatch.js +947 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/node_modules/brace-expansion/LICENSE +21 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/node_modules/brace-expansion/README.md +129 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/node_modules/brace-expansion/index.js +201 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/node_modules/brace-expansion/package.json +47 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/minimatch/package.json +33 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/index.d.ts +17 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/index.js +4 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/license +9 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/node_modules/ansi-regex/index.d.ts +37 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/node_modules/ansi-regex/index.js +10 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/node_modules/ansi-regex/license +9 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/node_modules/ansi-regex/package.json +55 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/node_modules/ansi-regex/readme.md +78 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/package.json +54 -0
- data/node_modules/@eslint-community/eslint-utils/node_modules/eslint/node_modules/strip-ansi/readme.md +46 -0
- data/node_modules/eslint-plugin-import/node_modules/debug/node_modules/ms/index.js +162 -0
- data/node_modules/eslint-plugin-import/node_modules/debug/node_modules/ms/license.md +21 -0
- data/node_modules/eslint-plugin-import/node_modules/debug/node_modules/ms/package.json +38 -0
- data/node_modules/eslint-plugin-import/node_modules/debug/node_modules/ms/readme.md +59 -0
- data/node_modules/npm-check-updates/build/package.json +2 -3
- data/node_modules/npm-check-updates/build/src/lib/runGlobal.js +18 -11
- data/node_modules/npm-check-updates/build/src/lib/runGlobal.js.map +1 -1
- data/node_modules/npm-check-updates/build/src/package-managers/bun.js +2 -3
- data/node_modules/npm-check-updates/build/src/package-managers/bun.js.map +1 -1
- data/node_modules/npm-check-updates/build/src/package-managers/npm.js +12 -8
- data/node_modules/npm-check-updates/build/src/package-managers/npm.js.map +1 -1
- data/node_modules/npm-check-updates/build/src/package-managers/pnpm.js +37 -14
- data/node_modules/npm-check-updates/build/src/package-managers/pnpm.js.map +1 -1
- data/node_modules/npm-check-updates/build/src/package-managers/yarn.js +36 -11
- data/node_modules/npm-check-updates/build/src/package-managers/yarn.js.map +1 -1
- data/node_modules/npm-check-updates/package.json +2 -3
- data/node_modules/prettier/LICENSE +3 -3
- data/node_modules/prettier/index.cjs +1 -1
- data/node_modules/prettier/index.mjs +14 -22
- data/node_modules/prettier/package.json +1 -1
- data/node_modules/prettier/plugins/acorn.js +10 -10
- data/node_modules/prettier/plugins/acorn.mjs +10 -10
- data/node_modules/prettier/plugins/angular.js +1 -1
- data/node_modules/prettier/plugins/angular.mjs +1 -1
- data/node_modules/prettier/plugins/babel.js +8 -8
- data/node_modules/prettier/plugins/babel.mjs +8 -8
- data/node_modules/prettier/plugins/estree.js +24 -24
- data/node_modules/prettier/plugins/estree.mjs +24 -24
- data/node_modules/prettier/plugins/flow.js +17 -17
- data/node_modules/prettier/plugins/flow.mjs +17 -17
- data/node_modules/prettier/plugins/graphql.js +6 -6
- data/node_modules/prettier/plugins/graphql.mjs +6 -6
- data/node_modules/prettier/plugins/html.js +1 -1
- data/node_modules/prettier/plugins/html.mjs +1 -1
- data/node_modules/prettier/plugins/markdown.js +1 -1
- data/node_modules/prettier/plugins/markdown.mjs +1 -1
- data/node_modules/prettier/plugins/meriyah.js +4 -4
- data/node_modules/prettier/plugins/meriyah.mjs +4 -4
- data/node_modules/prettier/plugins/typescript.js +19 -19
- data/node_modules/prettier/plugins/typescript.mjs +19 -19
- data/node_modules/prettier/standalone.js +10 -10
- data/node_modules/prettier/standalone.mjs +9 -9
- data/package.json +2 -2
- metadata +95 -4
@@ -0,0 +1,66 @@
|
|
1
|
+
/**
|
2
|
+
* @filedescription Merge Strategy Tests
|
3
|
+
*/
|
4
|
+
/* global it, describe, beforeEach */
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
//-----------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//-----------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const assert = require("chai").assert;
|
13
|
+
const { MergeStrategy } = require("../src/");
|
14
|
+
|
15
|
+
//-----------------------------------------------------------------------------
|
16
|
+
// Class
|
17
|
+
//-----------------------------------------------------------------------------
|
18
|
+
|
19
|
+
describe("MergeStrategy", () => {
|
20
|
+
|
21
|
+
|
22
|
+
describe("overwrite()", () => {
|
23
|
+
|
24
|
+
it("should overwrite the first value with the second when the second is defined", () => {
|
25
|
+
const result = MergeStrategy.overwrite(1, 2);
|
26
|
+
assert.strictEqual(result, 2);
|
27
|
+
});
|
28
|
+
|
29
|
+
it("should overwrite the first value with the second when the second is undefined", () => {
|
30
|
+
const result = MergeStrategy.overwrite(1, undefined);
|
31
|
+
assert.strictEqual(result, undefined);
|
32
|
+
});
|
33
|
+
|
34
|
+
});
|
35
|
+
|
36
|
+
describe("replace()", () => {
|
37
|
+
|
38
|
+
it("should overwrite the first value with the second when the second is defined", () => {
|
39
|
+
const result = MergeStrategy.replace(1, 2);
|
40
|
+
assert.strictEqual(result, 2);
|
41
|
+
});
|
42
|
+
|
43
|
+
it("should return the first value when the second is undefined", () => {
|
44
|
+
const result = MergeStrategy.replace(1, undefined);
|
45
|
+
assert.strictEqual(result, 1);
|
46
|
+
});
|
47
|
+
|
48
|
+
});
|
49
|
+
|
50
|
+
describe("assign()", () => {
|
51
|
+
|
52
|
+
it("should merge properties from two objects when called", () => {
|
53
|
+
|
54
|
+
const object1 = { foo: 1, bar: 3 };
|
55
|
+
const object2 = { foo: 2 };
|
56
|
+
|
57
|
+
const result = MergeStrategy.assign(object1, object2);
|
58
|
+
assert.deepStrictEqual(result, {
|
59
|
+
foo: 2,
|
60
|
+
bar: 3
|
61
|
+
});
|
62
|
+
});
|
63
|
+
|
64
|
+
});
|
65
|
+
|
66
|
+
});
|
@@ -0,0 +1,611 @@
|
|
1
|
+
/**
|
2
|
+
* @filedescription Object Schema Tests
|
3
|
+
*/
|
4
|
+
/* global it, describe, beforeEach */
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
//-----------------------------------------------------------------------------
|
9
|
+
// Requirements
|
10
|
+
//-----------------------------------------------------------------------------
|
11
|
+
|
12
|
+
const assert = require("chai").assert;
|
13
|
+
const { ObjectSchema } = require("../src/");
|
14
|
+
|
15
|
+
//-----------------------------------------------------------------------------
|
16
|
+
// Class
|
17
|
+
//-----------------------------------------------------------------------------
|
18
|
+
|
19
|
+
describe("ObjectSchema", () => {
|
20
|
+
|
21
|
+
let schema;
|
22
|
+
|
23
|
+
describe("new ObjectSchema()", () => {
|
24
|
+
|
25
|
+
it("should add a new key when a strategy is passed", () => {
|
26
|
+
schema = new ObjectSchema({
|
27
|
+
foo: {
|
28
|
+
merge() {},
|
29
|
+
validate() {}
|
30
|
+
}
|
31
|
+
});
|
32
|
+
|
33
|
+
assert.isTrue(schema.hasKey("foo"));
|
34
|
+
});
|
35
|
+
|
36
|
+
it("should throw an error when a strategy is missing a merge() method", () => {
|
37
|
+
assert.throws(() => {
|
38
|
+
schema = new ObjectSchema({
|
39
|
+
foo: {
|
40
|
+
validate() { }
|
41
|
+
}
|
42
|
+
});
|
43
|
+
}, /Definition for key "foo" must have a merge property/);
|
44
|
+
});
|
45
|
+
|
46
|
+
it("should throw an error when a strategy is missing a merge() method", () => {
|
47
|
+
assert.throws(() => {
|
48
|
+
schema = new ObjectSchema();
|
49
|
+
}, /Schema definitions missing/);
|
50
|
+
});
|
51
|
+
|
52
|
+
it("should throw an error when a strategy is missing a validate() method", () => {
|
53
|
+
assert.throws(() => {
|
54
|
+
schema = new ObjectSchema({
|
55
|
+
foo: {
|
56
|
+
merge() { },
|
57
|
+
}
|
58
|
+
});
|
59
|
+
}, /Definition for key "foo" must have a validate\(\) method/);
|
60
|
+
});
|
61
|
+
|
62
|
+
it("should throw an error when merge is an invalid string", () => {
|
63
|
+
assert.throws(() => {
|
64
|
+
new ObjectSchema({
|
65
|
+
foo: {
|
66
|
+
merge: "bar",
|
67
|
+
validate() { }
|
68
|
+
}
|
69
|
+
});
|
70
|
+
}, /key "foo" missing valid merge strategy/);
|
71
|
+
});
|
72
|
+
|
73
|
+
it("should throw an error when validate is an invalid string", () => {
|
74
|
+
assert.throws(() => {
|
75
|
+
new ObjectSchema({
|
76
|
+
foo: {
|
77
|
+
merge: "assign",
|
78
|
+
validate: "s"
|
79
|
+
}
|
80
|
+
});
|
81
|
+
}, /key "foo" missing valid validation strategy/);
|
82
|
+
});
|
83
|
+
|
84
|
+
});
|
85
|
+
|
86
|
+
|
87
|
+
describe("merge()", () => {
|
88
|
+
|
89
|
+
it("should throw an error when an unexpected key is found", () => {
|
90
|
+
let schema = new ObjectSchema({});
|
91
|
+
|
92
|
+
assert.throws(() => {
|
93
|
+
schema.merge({ foo: true }, { foo: true });
|
94
|
+
}, /Unexpected key "foo"/);
|
95
|
+
});
|
96
|
+
|
97
|
+
it("should throw an error when merge() throws an error", () => {
|
98
|
+
let schema = new ObjectSchema({
|
99
|
+
foo: {
|
100
|
+
merge() {
|
101
|
+
throw new Error("Boom!");
|
102
|
+
},
|
103
|
+
validate() {}
|
104
|
+
}
|
105
|
+
});
|
106
|
+
|
107
|
+
assert.throws(() => {
|
108
|
+
schema.merge({ foo: true }, { foo: true });
|
109
|
+
}, /Key "foo": Boom!/);
|
110
|
+
|
111
|
+
});
|
112
|
+
|
113
|
+
it("should call the merge() strategy for one key when called", () => {
|
114
|
+
|
115
|
+
schema = new ObjectSchema({
|
116
|
+
foo: {
|
117
|
+
merge() {
|
118
|
+
return "bar";
|
119
|
+
},
|
120
|
+
validate() {}
|
121
|
+
}
|
122
|
+
});
|
123
|
+
|
124
|
+
const result = schema.merge({ foo: true }, { foo: false });
|
125
|
+
assert.propertyVal(result, "foo", "bar");
|
126
|
+
});
|
127
|
+
|
128
|
+
it("should not call the merge() strategy when both objects don't contain the key", () => {
|
129
|
+
|
130
|
+
let called = false;
|
131
|
+
|
132
|
+
schema = new ObjectSchema({
|
133
|
+
foo: {
|
134
|
+
merge() {
|
135
|
+
called = true;
|
136
|
+
},
|
137
|
+
validate() {}
|
138
|
+
}
|
139
|
+
});
|
140
|
+
|
141
|
+
schema.merge({}, {});
|
142
|
+
assert.isFalse(called, "The merge() strategy should not have been called.");
|
143
|
+
});
|
144
|
+
|
145
|
+
it("should omit returning the key when the merge() strategy returns undefined", () => {
|
146
|
+
schema = new ObjectSchema({
|
147
|
+
foo: {
|
148
|
+
merge() {
|
149
|
+
return undefined;
|
150
|
+
},
|
151
|
+
validate() { }
|
152
|
+
}
|
153
|
+
});
|
154
|
+
|
155
|
+
const result = schema.merge({ foo: true }, { foo: false });
|
156
|
+
assert.notProperty(result, "foo");
|
157
|
+
});
|
158
|
+
|
159
|
+
it("should call the merge() strategy for two keys when called", () => {
|
160
|
+
schema = new ObjectSchema({
|
161
|
+
foo: {
|
162
|
+
merge() {
|
163
|
+
return "bar";
|
164
|
+
},
|
165
|
+
validate() { }
|
166
|
+
},
|
167
|
+
bar: {
|
168
|
+
merge() {
|
169
|
+
return "baz";
|
170
|
+
},
|
171
|
+
validate() {}
|
172
|
+
}
|
173
|
+
});
|
174
|
+
|
175
|
+
const result = schema.merge({ foo: true, bar: 1 }, { foo: true, bar: 2 });
|
176
|
+
assert.propertyVal(result, "foo", "bar");
|
177
|
+
assert.propertyVal(result, "bar", "baz");
|
178
|
+
});
|
179
|
+
|
180
|
+
it("should call the merge() strategy for two keys when called on three objects", () => {
|
181
|
+
schema = new ObjectSchema({
|
182
|
+
foo: {
|
183
|
+
merge() {
|
184
|
+
return "bar";
|
185
|
+
},
|
186
|
+
validate() { }
|
187
|
+
},
|
188
|
+
bar: {
|
189
|
+
merge() {
|
190
|
+
return "baz";
|
191
|
+
},
|
192
|
+
validate() { }
|
193
|
+
}
|
194
|
+
});
|
195
|
+
|
196
|
+
const result = schema.merge(
|
197
|
+
{ foo: true, bar: 1 },
|
198
|
+
{ foo: true, bar: 3 },
|
199
|
+
{ foo: false, bar: 2 }
|
200
|
+
);
|
201
|
+
assert.propertyVal(result, "foo", "bar");
|
202
|
+
assert.propertyVal(result, "bar", "baz");
|
203
|
+
});
|
204
|
+
|
205
|
+
it("should call the merge() strategy when defined as 'overwrite'", () => {
|
206
|
+
schema = new ObjectSchema({
|
207
|
+
foo: {
|
208
|
+
merge: "overwrite",
|
209
|
+
validate() { }
|
210
|
+
}
|
211
|
+
});
|
212
|
+
|
213
|
+
const result = schema.merge(
|
214
|
+
{ foo: true },
|
215
|
+
{ foo: false }
|
216
|
+
);
|
217
|
+
assert.propertyVal(result, "foo", false);
|
218
|
+
});
|
219
|
+
|
220
|
+
it("should call the merge() strategy when defined as 'assign'", () => {
|
221
|
+
schema = new ObjectSchema({
|
222
|
+
foo: {
|
223
|
+
merge: "assign",
|
224
|
+
validate() { }
|
225
|
+
}
|
226
|
+
});
|
227
|
+
|
228
|
+
const result = schema.merge(
|
229
|
+
{ foo: { bar: true } },
|
230
|
+
{ foo: { baz: false } }
|
231
|
+
);
|
232
|
+
|
233
|
+
assert.strictEqual(result.foo.bar, true);
|
234
|
+
assert.strictEqual(result.foo.baz, false);
|
235
|
+
});
|
236
|
+
|
237
|
+
it("should call the merge strategy when there's a subschema", () => {
|
238
|
+
|
239
|
+
schema = new ObjectSchema({
|
240
|
+
name: {
|
241
|
+
schema: {
|
242
|
+
first: {
|
243
|
+
merge: "replace",
|
244
|
+
validate: "string"
|
245
|
+
},
|
246
|
+
last: {
|
247
|
+
merge: "replace",
|
248
|
+
validate: "string"
|
249
|
+
}
|
250
|
+
}
|
251
|
+
}
|
252
|
+
});
|
253
|
+
|
254
|
+
const result = schema.merge({
|
255
|
+
name: {
|
256
|
+
first: "n",
|
257
|
+
last: "z"
|
258
|
+
}
|
259
|
+
}, {
|
260
|
+
name: {
|
261
|
+
first: "g"
|
262
|
+
}
|
263
|
+
});
|
264
|
+
|
265
|
+
assert.strictEqual(result.name.first, "g");
|
266
|
+
assert.strictEqual(result.name.last, "z");
|
267
|
+
});
|
268
|
+
|
269
|
+
it("should return separate objects when using subschema", () => {
|
270
|
+
|
271
|
+
schema = new ObjectSchema({
|
272
|
+
age: {
|
273
|
+
merge: "replace",
|
274
|
+
validate: "number"
|
275
|
+
},
|
276
|
+
address: {
|
277
|
+
schema: {
|
278
|
+
street: {
|
279
|
+
schema: {
|
280
|
+
number: {
|
281
|
+
merge: "replace",
|
282
|
+
validate: "number"
|
283
|
+
},
|
284
|
+
streetName: {
|
285
|
+
merge: "replace",
|
286
|
+
validate: "string"
|
287
|
+
}
|
288
|
+
}
|
289
|
+
},
|
290
|
+
state: {
|
291
|
+
merge: "replace",
|
292
|
+
validate: "string"
|
293
|
+
}
|
294
|
+
}
|
295
|
+
}
|
296
|
+
});
|
297
|
+
|
298
|
+
const baseObject = {
|
299
|
+
address: {
|
300
|
+
street: {
|
301
|
+
number: 100,
|
302
|
+
streetName: "Foo St"
|
303
|
+
},
|
304
|
+
state: "HA"
|
305
|
+
}
|
306
|
+
};
|
307
|
+
|
308
|
+
const result = schema.merge(baseObject, {
|
309
|
+
age: 29
|
310
|
+
});
|
311
|
+
|
312
|
+
assert.notStrictEqual(result.address.street, baseObject.address.street);
|
313
|
+
assert.deepStrictEqual(result.address, baseObject.address);
|
314
|
+
});
|
315
|
+
|
316
|
+
it("should not error when calling the merge strategy when there's a subschema and no matching key in second object", () => {
|
317
|
+
|
318
|
+
schema = new ObjectSchema({
|
319
|
+
name: {
|
320
|
+
schema: {
|
321
|
+
first: {
|
322
|
+
merge: "replace",
|
323
|
+
validate: "string"
|
324
|
+
},
|
325
|
+
last: {
|
326
|
+
merge: "replace",
|
327
|
+
validate: "string"
|
328
|
+
}
|
329
|
+
}
|
330
|
+
}
|
331
|
+
});
|
332
|
+
|
333
|
+
const result = schema.merge({
|
334
|
+
name: {
|
335
|
+
first: "n",
|
336
|
+
last: "z"
|
337
|
+
}
|
338
|
+
}, {
|
339
|
+
});
|
340
|
+
|
341
|
+
assert.strictEqual(result.name.first, "n");
|
342
|
+
assert.strictEqual(result.name.last, "z");
|
343
|
+
});
|
344
|
+
|
345
|
+
it("should not error when calling the merge strategy when there's multiple subschemas and no matching key in second object", () => {
|
346
|
+
|
347
|
+
schema = new ObjectSchema({
|
348
|
+
user: {
|
349
|
+
schema: {
|
350
|
+
name: {
|
351
|
+
schema: {
|
352
|
+
first: {
|
353
|
+
merge: "replace",
|
354
|
+
validate: "string"
|
355
|
+
},
|
356
|
+
last: {
|
357
|
+
merge: "replace",
|
358
|
+
validate: "string"
|
359
|
+
}
|
360
|
+
}
|
361
|
+
}
|
362
|
+
|
363
|
+
}
|
364
|
+
}
|
365
|
+
});
|
366
|
+
|
367
|
+
const result = schema.merge({
|
368
|
+
user: {
|
369
|
+
name: {
|
370
|
+
first: "n",
|
371
|
+
last: "z"
|
372
|
+
}
|
373
|
+
}
|
374
|
+
}, {
|
375
|
+
});
|
376
|
+
|
377
|
+
assert.strictEqual(result.user.name.first, "n");
|
378
|
+
assert.strictEqual(result.user.name.last, "z");
|
379
|
+
});
|
380
|
+
|
381
|
+
|
382
|
+
});
|
383
|
+
|
384
|
+
describe("validate()", () => {
|
385
|
+
|
386
|
+
it("should throw an error when an unexpected key is found", () => {
|
387
|
+
let schema = new ObjectSchema({});
|
388
|
+
assert.throws(() => {
|
389
|
+
schema.validate({ foo: true });
|
390
|
+
}, /Unexpected key "foo"/);
|
391
|
+
});
|
392
|
+
|
393
|
+
it("should not throw an error when an expected key is found", () => {
|
394
|
+
schema = new ObjectSchema({
|
395
|
+
foo: {
|
396
|
+
merge() {
|
397
|
+
return "bar";
|
398
|
+
},
|
399
|
+
validate() {}
|
400
|
+
}
|
401
|
+
});
|
402
|
+
|
403
|
+
schema.validate({ foo: true });
|
404
|
+
});
|
405
|
+
|
406
|
+
it("should pass the property value into validate() when key is found", () => {
|
407
|
+
schema = new ObjectSchema({
|
408
|
+
foo: {
|
409
|
+
merge() {
|
410
|
+
return "bar";
|
411
|
+
},
|
412
|
+
validate(value) {
|
413
|
+
assert.isTrue(value);
|
414
|
+
}
|
415
|
+
}
|
416
|
+
});
|
417
|
+
|
418
|
+
schema.validate({ foo: true });
|
419
|
+
});
|
420
|
+
|
421
|
+
it("should not throw an error when expected keys are found", () => {
|
422
|
+
schema = new ObjectSchema({
|
423
|
+
foo: {
|
424
|
+
merge() {
|
425
|
+
return "bar";
|
426
|
+
},
|
427
|
+
validate() {}
|
428
|
+
},
|
429
|
+
bar: {
|
430
|
+
merge() {
|
431
|
+
return "baz";
|
432
|
+
},
|
433
|
+
validate() {}
|
434
|
+
}
|
435
|
+
});
|
436
|
+
|
437
|
+
schema.validate({ foo: true, bar: true });
|
438
|
+
});
|
439
|
+
|
440
|
+
it("should not throw an error when expected keys are found with required keys", () => {
|
441
|
+
schema = new ObjectSchema({
|
442
|
+
foo: {
|
443
|
+
merge() {
|
444
|
+
return "bar";
|
445
|
+
},
|
446
|
+
validate() { }
|
447
|
+
},
|
448
|
+
bar: {
|
449
|
+
requires: ["foo"],
|
450
|
+
merge() {
|
451
|
+
return "baz";
|
452
|
+
},
|
453
|
+
validate() { }
|
454
|
+
}
|
455
|
+
});
|
456
|
+
|
457
|
+
schema.validate({ foo: true, bar: true });
|
458
|
+
});
|
459
|
+
|
460
|
+
it("should throw an error when expected keys are found without required keys", () => {
|
461
|
+
schema = new ObjectSchema({
|
462
|
+
foo: {
|
463
|
+
merge() {
|
464
|
+
return "bar";
|
465
|
+
},
|
466
|
+
validate() { }
|
467
|
+
},
|
468
|
+
baz: {
|
469
|
+
merge() {
|
470
|
+
return "baz";
|
471
|
+
},
|
472
|
+
validate() { }
|
473
|
+
},
|
474
|
+
bar: {
|
475
|
+
name: "bar",
|
476
|
+
requires: ["foo", "baz"],
|
477
|
+
merge() { },
|
478
|
+
validate() { }
|
479
|
+
}
|
480
|
+
});
|
481
|
+
|
482
|
+
assert.throws(() => {
|
483
|
+
schema.validate({ bar: true });
|
484
|
+
}, /Key "bar" requires keys "foo", "baz"./);
|
485
|
+
});
|
486
|
+
|
487
|
+
|
488
|
+
it("should throw an error when an expected key is found but is invalid", () => {
|
489
|
+
|
490
|
+
schema = new ObjectSchema({
|
491
|
+
foo: {
|
492
|
+
merge() {
|
493
|
+
return "bar";
|
494
|
+
},
|
495
|
+
validate() {
|
496
|
+
throw new Error("Invalid key.");
|
497
|
+
}
|
498
|
+
}
|
499
|
+
});
|
500
|
+
|
501
|
+
assert.throws(() => {
|
502
|
+
schema.validate({ foo: true });
|
503
|
+
}, /Key "foo": Invalid key/);
|
504
|
+
});
|
505
|
+
|
506
|
+
it("should throw an error when an expected key is found but is invalid with a string validator", () => {
|
507
|
+
|
508
|
+
schema = new ObjectSchema({
|
509
|
+
foo: {
|
510
|
+
merge() {
|
511
|
+
return "bar";
|
512
|
+
},
|
513
|
+
validate: "string"
|
514
|
+
}
|
515
|
+
});
|
516
|
+
|
517
|
+
assert.throws(() => {
|
518
|
+
schema.validate({ foo: true });
|
519
|
+
}, /Key "foo": Expected a string/);
|
520
|
+
});
|
521
|
+
|
522
|
+
it("should throw an error when an expected key is found but is invalid with a number validator", () => {
|
523
|
+
|
524
|
+
schema = new ObjectSchema({
|
525
|
+
foo: {
|
526
|
+
merge() {
|
527
|
+
return "bar";
|
528
|
+
},
|
529
|
+
validate: "number"
|
530
|
+
}
|
531
|
+
});
|
532
|
+
|
533
|
+
assert.throws(() => {
|
534
|
+
schema.validate({ foo: true });
|
535
|
+
}, /Key "foo": Expected a number/);
|
536
|
+
});
|
537
|
+
|
538
|
+
it("should throw an error when a required key is missing", () => {
|
539
|
+
|
540
|
+
schema = new ObjectSchema({
|
541
|
+
foo: {
|
542
|
+
required: true,
|
543
|
+
merge() {
|
544
|
+
return "bar";
|
545
|
+
},
|
546
|
+
validate() {}
|
547
|
+
}
|
548
|
+
});
|
549
|
+
|
550
|
+
assert.throws(() => {
|
551
|
+
schema.validate({});
|
552
|
+
}, /Missing required key "foo"/);
|
553
|
+
});
|
554
|
+
|
555
|
+
it("should throw an error when a subschema is provided and the value doesn't validate", () => {
|
556
|
+
|
557
|
+
schema = new ObjectSchema({
|
558
|
+
name: {
|
559
|
+
schema: {
|
560
|
+
first: {
|
561
|
+
merge: "replace",
|
562
|
+
validate: "string"
|
563
|
+
},
|
564
|
+
last: {
|
565
|
+
merge: "replace",
|
566
|
+
validate: "string"
|
567
|
+
}
|
568
|
+
}
|
569
|
+
}
|
570
|
+
});
|
571
|
+
|
572
|
+
assert.throws(() => {
|
573
|
+
schema.validate({
|
574
|
+
name: {
|
575
|
+
first: 123,
|
576
|
+
last: "z"
|
577
|
+
}
|
578
|
+
});
|
579
|
+
|
580
|
+
}, /Key "name": Key "first": Expected a string/);
|
581
|
+
});
|
582
|
+
|
583
|
+
it("should not throw an error when a subschema is provided and the value validates", () => {
|
584
|
+
|
585
|
+
schema = new ObjectSchema({
|
586
|
+
name: {
|
587
|
+
schema: {
|
588
|
+
first: {
|
589
|
+
merge: "replace",
|
590
|
+
validate: "string"
|
591
|
+
},
|
592
|
+
last: {
|
593
|
+
merge: "replace",
|
594
|
+
validate: "string"
|
595
|
+
}
|
596
|
+
}
|
597
|
+
}
|
598
|
+
});
|
599
|
+
|
600
|
+
schema.validate({
|
601
|
+
name: {
|
602
|
+
first: "n",
|
603
|
+
last: "z"
|
604
|
+
}
|
605
|
+
});
|
606
|
+
|
607
|
+
});
|
608
|
+
|
609
|
+
});
|
610
|
+
|
611
|
+
});
|