@raytio/core 10.0.1 → 11.0.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/CHANGELOG.md +10 -0
- package/README.md +129 -55
- package/dist/__tests__/docs.test.d.ts +1 -0
- package/dist/__tests__/docs.test.js +24 -0
- package/dist/crypto/getAADecryptor.d.ts +8 -3
- package/dist/crypto/helpers.d.ts +2 -2
- package/dist/general/conditional.d.ts +12 -2
- package/dist/general/conditional.js +11 -1
- package/dist/general/date.d.ts +2 -0
- package/dist/general/date.js +18 -0
- package/dist/general/index.d.ts +1 -0
- package/dist/general/index.js +1 -0
- package/dist/rules/calculateScore.d.ts +7 -2
- package/dist/rules/calculateScore.js +8 -2
- package/dist/rules/convertInstanceToRuleInput.d.ts +2 -2
- package/dist/rules/convertInstanceToRuleInput.js +2 -3
- package/dist/rules/evaluateScoreCondition.js +0 -1
- package/dist/rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.d.ts +1 -0
- package/dist/rules/helpers/__tests__/addInfiniteThresholdBoundaries.test.js +27 -0
- package/dist/rules/helpers/__tests__/checkTypeofValue.test.d.ts +1 -0
- package/dist/rules/helpers/__tests__/checkTypeofValue.test.js +49 -0
- package/dist/rules/helpers/__tests__/getValuesFromPath.test.d.ts +1 -0
- package/dist/rules/helpers/__tests__/getValuesFromPath.test.js +67 -0
- package/dist/rules/helpers/__tests__/thresholds.test.d.ts +1 -0
- package/dist/rules/helpers/__tests__/thresholds.test.js +32 -0
- package/dist/rules/helpers/checkTypeofValue.js +11 -6
- package/dist/rules/helpers/thresholds.js +1 -2
- package/dist/rules/operators/__tests__/bool.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/bool.test.js +21 -0
- package/dist/rules/operators/__tests__/date.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/date.test.js +81 -0
- package/dist/rules/operators/__tests__/hfield.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/hfield.test.js +38 -0
- package/dist/rules/operators/__tests__/hschema.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/hschema.test.js +24 -0
- package/dist/rules/operators/__tests__/number.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/number.test.js +53 -0
- package/dist/rules/operators/__tests__/string.test.d.ts +1 -0
- package/dist/rules/operators/__tests__/string.test.js +74 -0
- package/dist/rules/types/config.d.ts +21 -17
- package/dist/rules/types/dataValueTypes.d.ts +4 -4
- package/dist/rules/types/internal.d.ts +3 -3
- package/dist/rules/version.d.ts +1 -1
- package/dist/rules/version.js +1 -1
- package/dist/schema/labels.js +1 -1
- package/dist/util/canonicalJsonify.js +1 -1
- package/dist/util/handleResponse.js +1 -1
- package/dist/verifications/getPOVerification.d.ts +7 -4
- package/dist/verifications/getPOVerification.js +15 -4
- package/dist/verifications/safeHarbour.d.ts +2 -2
- package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.d.ts +1 -0
- package/dist/verifications/verifyCheck/__tests__/getOwnRealVerifications.test.js +152 -0
- package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.d.ts +1 -0
- package/dist/verifications/verifyCheck/__tests__/getSomeoneElsesRealVerifications.test.js +205 -0
- package/dist/verifications/verifyCheck/getOwnRealVerifications.js +5 -2
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.d.ts +1 -1
- package/dist/verifications/verifyCheck/getSomeoneElsesRealVerifications.js +3 -2
- package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.d.ts +1 -0
- package/dist/verifications/verifyCheck/operations/__tests__/checkOwnVerification.test.js +91 -0
- package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.d.ts +1 -0
- package/dist/verifications/verifyCheck/operations/__tests__/checkSomeoneElsesVerifications.test.js +49 -0
- package/dist/verifications/verifyCheck/operations/__tests__/sampleBundle.json +43 -0
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.d.ts +1 -1
- package/dist/verifications/verifyCheck/operations/checkOwnVerification.js +1 -1
- package/package.json +13 -10
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const addInfiniteThresholdBoundaries_1 = require("../addInfiniteThresholdBoundaries");
|
|
4
|
+
describe("addInfiniteThresholdBoundaries", () => {
|
|
5
|
+
it("correctly re-adds Infinity to the first and last boundary", () => {
|
|
6
|
+
expect((0, addInfiniteThresholdBoundaries_1.addInfiniteThresholdBoundaries)([
|
|
7
|
+
{ colour: "", from: null, to: 1, name: "❤️" },
|
|
8
|
+
{ colour: "", from: 2, to: 50, name: "💛" },
|
|
9
|
+
{ colour: "", from: 51, to: null, name: "💚" },
|
|
10
|
+
])).toStrictEqual([
|
|
11
|
+
{ colour: "", from: -Infinity, to: 1, name: "❤️" },
|
|
12
|
+
{ colour: "", from: 2, to: 50, name: "💛" },
|
|
13
|
+
{ colour: "", from: 51, to: Infinity, name: "💚" },
|
|
14
|
+
]);
|
|
15
|
+
expect((0, addInfiniteThresholdBoundaries_1.addInfiniteThresholdBoundaries)([])).toStrictEqual([]);
|
|
16
|
+
expect((0, addInfiniteThresholdBoundaries_1.addInfiniteThresholdBoundaries)([
|
|
17
|
+
{ colour: "", from: 1, to: 10, name: "my useless single category" },
|
|
18
|
+
])).toStrictEqual([
|
|
19
|
+
{
|
|
20
|
+
colour: "",
|
|
21
|
+
from: -Infinity,
|
|
22
|
+
to: Infinity,
|
|
23
|
+
name: "my useless single category",
|
|
24
|
+
},
|
|
25
|
+
]);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("@raytio/types");
|
|
4
|
+
const checkTypeofValue_1 = require("../checkTypeofValue");
|
|
5
|
+
const symbols_1 = require("../symbols");
|
|
6
|
+
const hField = { __typeof__: symbols_1.HFieldSymbol };
|
|
7
|
+
const hSchema = { __typeof__: symbols_1.HSchemaSymbol };
|
|
8
|
+
describe("checkTypeofValue", () => {
|
|
9
|
+
it.each `
|
|
10
|
+
val | type | isValid
|
|
11
|
+
${[]} | ${"Array"} | ${true}
|
|
12
|
+
${[]} | ${"Number"} | ${false}
|
|
13
|
+
${false} | ${"Bool"} | ${true}
|
|
14
|
+
${undefined} | ${"Bool"} | ${false}
|
|
15
|
+
${new Date()} | ${"Date"} | ${true}
|
|
16
|
+
${2020} | ${"Date"} | ${false}
|
|
17
|
+
${"Y"} | ${"DateUnit"} | ${true}
|
|
18
|
+
${"y"} | ${"DateUnit"} | ${false}
|
|
19
|
+
${types_1.FieldVerification.Expired} | ${"FieldVerification"} | ${true}
|
|
20
|
+
${12345} | ${"FieldVerification"} | ${false}
|
|
21
|
+
${hField} | ${"HField"} | ${true}
|
|
22
|
+
${{}} | ${"HField"} | ${false}
|
|
23
|
+
${hSchema} | ${"HSchema"} | ${true}
|
|
24
|
+
${{}} | ${"HSchema"} | ${false}
|
|
25
|
+
${123} | ${"Number"} | ${true}
|
|
26
|
+
${types_1.FieldVerification.Expired} | ${"Number"} | ${true}
|
|
27
|
+
${"123"} | ${"Number"} | ${false}
|
|
28
|
+
${types_1.POVerification.Expired} | ${"POVerification"} | ${true}
|
|
29
|
+
${12345} | ${"POVerification"} | ${false}
|
|
30
|
+
${/a/} | ${"RegEx"} | ${true}
|
|
31
|
+
${"/a/"} | ${"RegEx"} | ${false}
|
|
32
|
+
${""} | ${"String"} | ${true}
|
|
33
|
+
${1} | ${"String"} | ${false}
|
|
34
|
+
${""} | ${"Verifier"} | ${true}
|
|
35
|
+
${1} | ${"Verifier"} | ${false}
|
|
36
|
+
${0} | ${"invalidddd"} | ${false}
|
|
37
|
+
`("asserts that $val is/isNot $type ($isValid)", ({ val, type, isValid }) => {
|
|
38
|
+
expect((0, checkTypeofValue_1.checkTypeofValue)(type, val)).toBe(isValid);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe("simplifyValueType", () => {
|
|
42
|
+
it.each `
|
|
43
|
+
input | output
|
|
44
|
+
${"Verifier"} | ${"String"}
|
|
45
|
+
${"some other value"} | ${"some other value"}
|
|
46
|
+
`("can simplify functionally equivalent types ($input -> $output)", ({ input, output }) => {
|
|
47
|
+
expect((0, checkTypeofValue_1.simplifyValueType)(input)).toStrictEqual(output);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("@raytio/types");
|
|
4
|
+
const getValuesFromPath_1 = require("../getValuesFromPath");
|
|
5
|
+
const symbols_1 = require("../symbols");
|
|
6
|
+
const hSchema = {
|
|
7
|
+
__typeof__: symbols_1.HSchemaSymbol,
|
|
8
|
+
verification: types_1.POVerification.PartiallyVerified,
|
|
9
|
+
verifiedBy: ["Waka Kotahi"],
|
|
10
|
+
};
|
|
11
|
+
const hField = {
|
|
12
|
+
__typeof__: symbols_1.HFieldSymbol,
|
|
13
|
+
cameFromSchema: "ss_NZ_DL",
|
|
14
|
+
verification: types_1.FieldVerification.Verified,
|
|
15
|
+
verifiedBy: ["Waka Kotahi"],
|
|
16
|
+
};
|
|
17
|
+
const data = {
|
|
18
|
+
ss_NZ_DL: [
|
|
19
|
+
{
|
|
20
|
+
hSchema,
|
|
21
|
+
properties: {
|
|
22
|
+
fName: { type: "String", value: "Wolfgang", hField },
|
|
23
|
+
age: { type: "Number", value: 19.25, hField },
|
|
24
|
+
"address|housenumber": {
|
|
25
|
+
type: "Number",
|
|
26
|
+
value: 31,
|
|
27
|
+
hField: null,
|
|
28
|
+
},
|
|
29
|
+
"address|street": {
|
|
30
|
+
type: "String",
|
|
31
|
+
value: "Circular Quay",
|
|
32
|
+
hField: null,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
describe("getValuesFromPath", () => {
|
|
39
|
+
it.each `
|
|
40
|
+
path | out
|
|
41
|
+
${["field", "ss_NZ_DL", "fName", "value"]} | ${["Wolfgang"]}
|
|
42
|
+
${["field", "ss_NZ_DL", "fName", "valueLength"]} | ${[8]}
|
|
43
|
+
${["field", "ss_NZ_DL", "fName", "meta"]} | ${[hField]}
|
|
44
|
+
${["schema", "ss_NZ_DL", "meta"]} | ${[hSchema]}
|
|
45
|
+
${["field", "ss_NZ_DL", "fakeeee", "value"]} | ${[undefined]}
|
|
46
|
+
${["schema", "fakeeee", "meta"]} | ${[]}
|
|
47
|
+
${["field", "ss_NZ_DL", "address", "subField|street"]} | ${["Circular Quay"]}
|
|
48
|
+
${["field", "ss_NZ_DL", "address", "subField|fakeee"]} | ${[undefined]}
|
|
49
|
+
${["field", "ss_NZ_DL", "address", "subField|"]} | ${[undefined]}
|
|
50
|
+
`("can get a value from a valid path ($path)", ({ path, out }) => {
|
|
51
|
+
expect((0, getValuesFromPath_1.getValuesFromPath)(path, data)).toStrictEqual(out);
|
|
52
|
+
});
|
|
53
|
+
it.each `
|
|
54
|
+
path | error
|
|
55
|
+
${["jkhsfjkdf"]} | ${"Invalid ValuePath[0] (jkhsfjkdf)"}
|
|
56
|
+
${["schema", "constructor", "meta"]} | ${"Unacceptable object property"}
|
|
57
|
+
${["schema", "ss_NZ_DL", "fakeeee"]} | ${"Invalid ValuePath[2] for schema (fakeeee)"}
|
|
58
|
+
${["schema", "ss_NZ_DL", "constructor", "meta"]} | ${"Unacceptable object property"}
|
|
59
|
+
${["field", "ss_NZ_DL", "fName", "fakeeee"]} | ${"Invalid ValuePath[3] for field (fakeeee)"}
|
|
60
|
+
${["field"]} | ${"Invalid ValuePath[3] for field (undefined)"}
|
|
61
|
+
${["schema"]} | ${"Invalid ValuePath[2] for schema (undefined)"}
|
|
62
|
+
${""} | ${"Invalid ValuePath[0] (undefined)"}
|
|
63
|
+
${["field", "ss_NZ_DL", "age", "valueLength"]} | ${"valueLength may only be used on arrays and strings"}
|
|
64
|
+
`("throws an error for invalid paths ($path)", ({ path, error }) => {
|
|
65
|
+
expect(() => (0, getValuesFromPath_1.getValuesFromPath)(path, data)).toThrow(new Error(error));
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const thresholds_1 = require("../thresholds");
|
|
4
|
+
describe("getThresholdBoundary", () => {
|
|
5
|
+
it("gets the min and max for plus", () => {
|
|
6
|
+
expect((0, thresholds_1.getThresholdBoundary)("+", [
|
|
7
|
+
{ trueWeight: 3, falseWeight: 5 },
|
|
8
|
+
{ trueWeight: -20, falseWeight: -10 },
|
|
9
|
+
])).toStrictEqual([-17, -5]);
|
|
10
|
+
expect((0, thresholds_1.getThresholdBoundary)("+", [
|
|
11
|
+
{ trueWeight: -7, falseWeight: -8 },
|
|
12
|
+
])).toStrictEqual([-8, -7]);
|
|
13
|
+
});
|
|
14
|
+
it("gets the min and max for multiply", () => {
|
|
15
|
+
expect((0, thresholds_1.getThresholdBoundary)("*", [
|
|
16
|
+
{ trueWeight: 7, falseWeight: -2 },
|
|
17
|
+
{ trueWeight: -1, falseWeight: 2 },
|
|
18
|
+
{ trueWeight: -5, falseWeight: 4 },
|
|
19
|
+
])).toStrictEqual([-70, 56]);
|
|
20
|
+
expect((0, thresholds_1.getThresholdBoundary)("*", [
|
|
21
|
+
{ trueWeight: 7, falseWeight: -2 },
|
|
22
|
+
])).toStrictEqual([-2, 7]);
|
|
23
|
+
});
|
|
24
|
+
it("works for empty arrays", () => {
|
|
25
|
+
expect((0, thresholds_1.getThresholdBoundary)("+", [])).toStrictEqual([0, 0]);
|
|
26
|
+
expect((0, thresholds_1.getThresholdBoundary)("*", [])).toStrictEqual([Infinity, -Infinity]);
|
|
27
|
+
});
|
|
28
|
+
it("throws an error for invalid combinators", () => {
|
|
29
|
+
// @ts-expect-error testing invalid input
|
|
30
|
+
expect(() => (0, thresholds_1.getThresholdBoundary)("^", [])).toThrow(new Error("Invalid combinator"));
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -5,8 +5,11 @@ const types_1 = require("@raytio/types");
|
|
|
5
5
|
const symbols_1 = require("./symbols");
|
|
6
6
|
const types_2 = require("../types");
|
|
7
7
|
const VALID_DATE_UNITS = types_2.DATE_UNITS;
|
|
8
|
-
// we need this function
|
|
9
|
-
const isObjectWithTypeofProp = (x) => typeof x === "object" &&
|
|
8
|
+
// we need this function because TS's typeguards aren't great
|
|
9
|
+
const isObjectWithTypeofProp = (x) => typeof x === "object" &&
|
|
10
|
+
!!x &&
|
|
11
|
+
"__typeof__" in x &&
|
|
12
|
+
typeof x.__typeof__ === "symbol";
|
|
10
13
|
/** asserts that the provided `value` meets the constaints of `type` */
|
|
11
14
|
function checkTypeofValue(type, value) {
|
|
12
15
|
switch (type) {
|
|
@@ -21,12 +24,14 @@ function checkTypeofValue(type, value) {
|
|
|
21
24
|
case "FieldVerification":
|
|
22
25
|
return typeof value === "number" && value in types_1.FieldVerification;
|
|
23
26
|
case "HField":
|
|
24
|
-
// this is fakeable
|
|
25
|
-
//
|
|
27
|
+
// this is not fakeable because we use a unique symbol for __typeof__, like
|
|
28
|
+
// what react does with $$typeof. But even if you could construct a fake object,
|
|
29
|
+
// it wouldn't be a concern in this context.
|
|
26
30
|
return isObjectWithTypeofProp(value) && value.__typeof__ === symbols_1.HFieldSymbol;
|
|
27
31
|
case "HSchema":
|
|
28
|
-
// this is fakeable
|
|
29
|
-
//
|
|
32
|
+
// this is not fakeable because we use a unique symbol for __typeof__, like
|
|
33
|
+
// what react does with $$typeof. But even if you could construct a fake object,
|
|
34
|
+
// it wouldn't be a concern in this context.
|
|
30
35
|
return (isObjectWithTypeofProp(value) && value.__typeof__ === symbols_1.HSchemaSymbol);
|
|
31
36
|
case "Number":
|
|
32
37
|
return typeof value === "number";
|
|
@@ -22,9 +22,8 @@ function getThresholdBoundary(combinator, rules) {
|
|
|
22
22
|
return [lowest, highest];
|
|
23
23
|
}
|
|
24
24
|
case "*": {
|
|
25
|
-
// eslint-disable-next-line fp/no-let
|
|
26
25
|
let [lowest, highest] = [Infinity, -Infinity];
|
|
27
|
-
// eslint-disable-next-line fp/no-
|
|
26
|
+
// eslint-disable-next-line fp/no-mutation
|
|
28
27
|
for (let i = 0; i < 2 * rules.length; i += 1) {
|
|
29
28
|
// loop for every possible combination (2*rules.rength), and check that combination
|
|
30
29
|
const product = i
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bool_1 = require("../bool");
|
|
4
|
+
describe("boolOperators", () => {
|
|
5
|
+
it.each `
|
|
6
|
+
a | b | result
|
|
7
|
+
${true} | ${true} | ${true}
|
|
8
|
+
${false} | ${true} | ${false}
|
|
9
|
+
${false} | ${false} | ${true}
|
|
10
|
+
`("bool_eq $a, $b", ({ a, b, result }) => {
|
|
11
|
+
expect(bool_1.boolOperators.bool_eq.implementation(a, b)).toBe(result);
|
|
12
|
+
});
|
|
13
|
+
it.each `
|
|
14
|
+
a | b | result
|
|
15
|
+
${true} | ${true} | ${false}
|
|
16
|
+
${false} | ${true} | ${true}
|
|
17
|
+
${false} | ${false} | ${false}
|
|
18
|
+
`("bool_neq $a, $b", ({ a, b, result }) => {
|
|
19
|
+
expect(bool_1.boolOperators.bool_neq.implementation(a, b)).toBe(result);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const date_1 = require("../date");
|
|
4
|
+
describe("dateOperators", () => {
|
|
5
|
+
it.each `
|
|
6
|
+
a | b | result
|
|
7
|
+
${new Date("2001-06-06T01:00:00Z")} | ${new Date("2001-06-06T23:59:59Z")} | ${true}
|
|
8
|
+
${new Date("2001-02-02")} | ${new Date("2001-02-03")} | ${false}
|
|
9
|
+
`("date_eq $a, $b", ({ a, b, result }) => {
|
|
10
|
+
expect(date_1.dateOperators.date_eq.implementation(a, b)).toBe(result);
|
|
11
|
+
});
|
|
12
|
+
it.each `
|
|
13
|
+
a | b | result
|
|
14
|
+
${new Date("2001-06-06T01:00:00Z")} | ${new Date("2001-06-06T23:59:59Z")} | ${false}
|
|
15
|
+
${new Date("2001-02-02")} | ${new Date("2001-02-03")} | ${true}
|
|
16
|
+
`("date_neq $a, $b", ({ a, b, result }) => {
|
|
17
|
+
expect(date_1.dateOperators.date_neq.implementation(a, b)).toBe(result);
|
|
18
|
+
});
|
|
19
|
+
it.each `
|
|
20
|
+
a | result
|
|
21
|
+
${new Date("2001-01-01")} | ${true}
|
|
22
|
+
${new Date("bobs ur uncle")} | ${false}
|
|
23
|
+
`("date_valid $a", ({ a, result }) => {
|
|
24
|
+
expect(date_1.dateOperators.date_valid.implementation(a)).toBe(result);
|
|
25
|
+
});
|
|
26
|
+
it.each `
|
|
27
|
+
a | result
|
|
28
|
+
${new Date("2001-01-01")} | ${false}
|
|
29
|
+
${new Date("bobs ur uncle")} | ${true}
|
|
30
|
+
`("date_invalid $a", ({ a, result }) => {
|
|
31
|
+
expect(date_1.dateOperators.date_invalid.implementation(a)).toBe(result);
|
|
32
|
+
});
|
|
33
|
+
it.each `
|
|
34
|
+
a | b | result
|
|
35
|
+
${new Date("2001-02-02")} | ${new Date("2001-02-03")} | ${true}
|
|
36
|
+
${new Date("2001-01-01")} | ${new Date("1999-01-01")} | ${false}
|
|
37
|
+
`("date_before $a, $b", ({ a, b, result }) => {
|
|
38
|
+
expect(date_1.dateOperators.date_before.implementation(a, b)).toBe(result);
|
|
39
|
+
});
|
|
40
|
+
it.each `
|
|
41
|
+
a | b | result
|
|
42
|
+
${new Date("2001-02-02")} | ${new Date("2001-02-03")} | ${false}
|
|
43
|
+
${new Date("2001-01-01")} | ${new Date("1999-01-01")} | ${true}
|
|
44
|
+
`("date_after $a, $b", ({ a, b, result }) => {
|
|
45
|
+
expect(date_1.dateOperators.date_after.implementation(a, b)).toBe(result);
|
|
46
|
+
});
|
|
47
|
+
it.each `
|
|
48
|
+
a | b | c | result
|
|
49
|
+
${new Date("2001")} | ${new Date("2000")} | ${new Date("2002")} | ${true}
|
|
50
|
+
${new Date("2001")} | ${new Date("2005")} | ${new Date("2000")} | ${false}
|
|
51
|
+
${new Date("1900")} | ${new Date("1900")} | ${new Date("1900")} | ${true}
|
|
52
|
+
`("date_between $a, $b, $c", ({ a, b, c, result }) => {
|
|
53
|
+
expect(date_1.dateOperators.date_between.implementation(a, b, c)).toBe(result);
|
|
54
|
+
});
|
|
55
|
+
it.each `
|
|
56
|
+
date | num | units | result
|
|
57
|
+
${new Date("2010")} | ${10} | ${"Y"} | ${true}
|
|
58
|
+
${new Date("2010")} | ${20} | ${"Y"} | ${false}
|
|
59
|
+
${new Date("2030")} | ${1} | ${"Y"} | ${false}
|
|
60
|
+
${new Date()} | ${1} | ${"ms"} | ${true /* reminaing tests are just for 100% coverage */}
|
|
61
|
+
${new Date()} | ${1} | ${"s"} | ${false}
|
|
62
|
+
${new Date()} | ${1} | ${"m"} | ${false}
|
|
63
|
+
${new Date()} | ${1} | ${"h"} | ${false}
|
|
64
|
+
${new Date()} | ${1} | ${"D"} | ${false}
|
|
65
|
+
${new Date()} | ${1} | ${"W"} | ${false}
|
|
66
|
+
${new Date()} | ${1} | ${"M"} | ${false}
|
|
67
|
+
`("date_older_than $date, $num, $units", ({ date, num, units, result }) => {
|
|
68
|
+
expect(date_1.dateOperators.date_older_than.implementation(date, num, units)).toBe(result);
|
|
69
|
+
});
|
|
70
|
+
it("date_older_than (throws an error for an invalid DateUnit)", () => {
|
|
71
|
+
expect(() => date_1.dateOperators.date_older_than.implementation(new Date(), 6, "Quaters")).toThrow(new Error("Invalid date unit: Quaters"));
|
|
72
|
+
});
|
|
73
|
+
it.each `
|
|
74
|
+
date | num | units | result
|
|
75
|
+
${new Date("2030")} | ${1} | ${"Y"} | ${true}
|
|
76
|
+
${new Date("2030")} | ${10} | ${"Y"} | ${false}
|
|
77
|
+
${new Date()} | ${1} | ${"h"} | ${false}
|
|
78
|
+
`("date_newer_than $date, $num, $units", ({ date, num, units, result }) => {
|
|
79
|
+
expect(date_1.dateOperators.date_newer_than.implementation(date, num, units)).toBe(result);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("@raytio/types");
|
|
4
|
+
const hfield_1 = require("../hfield");
|
|
5
|
+
describe("fieldOperators", () => {
|
|
6
|
+
it("field_shared", () => {
|
|
7
|
+
expect(hfield_1.fieldOperators.field_shared.implementation()).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
it.each `
|
|
10
|
+
field | verifier | result
|
|
11
|
+
${{ verifiedBy: ["MoH"] }} | ${"MoH"} | ${true}
|
|
12
|
+
${{ verifiedBy: ["MinEdu"] }} | ${"Ministry of Health"} | ${false}
|
|
13
|
+
${{ verifiedBy: [] }} | ${"Ministry of Health"} | ${false}
|
|
14
|
+
`("field_verifiedBy {...}, $verifier", ({ field, verifier, result }) => {
|
|
15
|
+
expect(hfield_1.fieldOperators.field_verifiedBy.implementation(field, verifier)).toBe(result);
|
|
16
|
+
});
|
|
17
|
+
it.each `
|
|
18
|
+
field | value | result
|
|
19
|
+
${{ verification: types_1.FieldVerification.Verified }} | ${types_1.FieldVerification.Verified} | ${true}
|
|
20
|
+
${{ verification: types_1.FieldVerification.NotVerified }} | ${types_1.FieldVerification.Verified} | ${false}
|
|
21
|
+
`("field_hasVerStatus {...}, $value", ({ field, value, result }) => {
|
|
22
|
+
expect(hfield_1.fieldOperators.field_hasVerStatus.implementation(field, value)).toBe(result);
|
|
23
|
+
});
|
|
24
|
+
it.each `
|
|
25
|
+
field | value | result
|
|
26
|
+
${{ cameFromSchema: "ss_A" }} | ${"ss_A"} | ${true}
|
|
27
|
+
${{ cameFromSchema: "ss_A" }} | ${"ss_B"} | ${false}
|
|
28
|
+
`("field_cameFromSchema {...}, $value", ({ field, value, result }) => {
|
|
29
|
+
expect(hfield_1.fieldOperators.field_cameFromSchema.implementation(field, value)).toBe(result);
|
|
30
|
+
});
|
|
31
|
+
it.each `
|
|
32
|
+
field | value | result
|
|
33
|
+
${{ cameFromSchema: "ss_A" }} | ${"ss_A"} | ${false}
|
|
34
|
+
${{ cameFromSchema: "ss_A" }} | ${"ss_B"} | ${true}
|
|
35
|
+
`("field_ncameFromSchema {...}, $value", ({ field, value, result }) => {
|
|
36
|
+
expect(hfield_1.fieldOperators.field_ncameFromSchema.implementation(field, value)).toBe(result);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const types_1 = require("@raytio/types");
|
|
4
|
+
const hschema_1 = require("../hschema");
|
|
5
|
+
describe("schemaOperators", () => {
|
|
6
|
+
it("schema_shared", () => {
|
|
7
|
+
expect(hschema_1.schemaOperators.schema_shared.implementation()).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
it.each `
|
|
10
|
+
field | verifier | result
|
|
11
|
+
${{ verifiedBy: ["MoH"] }} | ${"MoH"} | ${true}
|
|
12
|
+
${{ verifiedBy: ["MinEdu"] }} | ${"Ministry of Health"} | ${false}
|
|
13
|
+
${{ verifiedBy: [] }} | ${"Ministry of Health"} | ${false}
|
|
14
|
+
`("schema_verifiedBy {...}, $verifier", ({ field, verifier, result }) => {
|
|
15
|
+
expect(hschema_1.schemaOperators.schema_verifiedBy.implementation(field, verifier)).toBe(result);
|
|
16
|
+
});
|
|
17
|
+
it.each `
|
|
18
|
+
field | value | result
|
|
19
|
+
${{ verification: types_1.POVerification.FullyVerified }} | ${types_1.POVerification.FullyVerified} | ${true}
|
|
20
|
+
${{ verification: types_1.POVerification.NotVerified }} | ${types_1.POVerification.FullyVerified} | ${false}
|
|
21
|
+
`("schema_hasVerStatus {...}, $value", ({ field, value, result }) => {
|
|
22
|
+
expect(hschema_1.schemaOperators.schema_hasVerStatus.implementation(field, value)).toBe(result);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const number_1 = require("../number");
|
|
4
|
+
describe("numberOperators", () => {
|
|
5
|
+
it.each `
|
|
6
|
+
a | b | result
|
|
7
|
+
${1} | ${1} | ${true}
|
|
8
|
+
${1} | ${2} | ${false}
|
|
9
|
+
${3.3333} | ${3.3333} | ${true}
|
|
10
|
+
`("num_eq $a, $b", ({ a, b, result }) => {
|
|
11
|
+
expect(number_1.numberOperators.num_eq.implementation(a, b)).toBe(result);
|
|
12
|
+
});
|
|
13
|
+
it.each `
|
|
14
|
+
a | b | result
|
|
15
|
+
${1} | ${1} | ${false}
|
|
16
|
+
${1} | ${2} | ${true}
|
|
17
|
+
${3.3333} | ${3.3333} | ${false}
|
|
18
|
+
`("num_neq $a, $b", ({ a, b, result }) => {
|
|
19
|
+
expect(number_1.numberOperators.num_neq.implementation(a, b)).toBe(result);
|
|
20
|
+
});
|
|
21
|
+
it.each `
|
|
22
|
+
a | b | result
|
|
23
|
+
${0} | ${1} | ${false}
|
|
24
|
+
${1} | ${1} | ${true}
|
|
25
|
+
${2} | ${1} | ${true}
|
|
26
|
+
`("num_gt_eq $a, $b", ({ a, b, result }) => {
|
|
27
|
+
expect(number_1.numberOperators.num_gt_eq.implementation(a, b)).toBe(result);
|
|
28
|
+
});
|
|
29
|
+
it.each `
|
|
30
|
+
a | b | result
|
|
31
|
+
${0} | ${1} | ${false}
|
|
32
|
+
${1} | ${1} | ${false}
|
|
33
|
+
${2} | ${1} | ${true}
|
|
34
|
+
`("num_gt $a, $b", ({ a, b, result }) => {
|
|
35
|
+
expect(number_1.numberOperators.num_gt.implementation(a, b)).toBe(result);
|
|
36
|
+
});
|
|
37
|
+
it.each `
|
|
38
|
+
a | b | result
|
|
39
|
+
${0} | ${1} | ${true}
|
|
40
|
+
${1} | ${1} | ${true}
|
|
41
|
+
${2} | ${1} | ${false}
|
|
42
|
+
`("num_lt_eq $a, $b", ({ a, b, result }) => {
|
|
43
|
+
expect(number_1.numberOperators.num_lt_eq.implementation(a, b)).toBe(result);
|
|
44
|
+
});
|
|
45
|
+
it.each `
|
|
46
|
+
a | b | result
|
|
47
|
+
${0} | ${1} | ${true}
|
|
48
|
+
${1} | ${1} | ${false}
|
|
49
|
+
${2} | ${1} | ${false}
|
|
50
|
+
`("num_lt $a, $b", ({ a, b, result }) => {
|
|
51
|
+
expect(number_1.numberOperators.num_lt.implementation(a, b)).toBe(result);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const string_1 = require("../string");
|
|
4
|
+
describe("stringOperators", () => {
|
|
5
|
+
it.each `
|
|
6
|
+
a | b | result
|
|
7
|
+
${"AA"} | ${"aa"} | ${true}
|
|
8
|
+
${"Aa"} | ${"Bb"} | ${false}
|
|
9
|
+
`("string_eq $a, $b", ({ a, b, result }) => {
|
|
10
|
+
expect(string_1.stringOperators.string_eq.implementation(a, b)).toBe(result);
|
|
11
|
+
});
|
|
12
|
+
it.each `
|
|
13
|
+
a | b | result
|
|
14
|
+
${"AA"} | ${"aa"} | ${false}
|
|
15
|
+
${"Aa"} | ${"Bb"} | ${true}
|
|
16
|
+
`("string_neq $a, $b", ({ a, b, result }) => {
|
|
17
|
+
expect(string_1.stringOperators.string_neq.implementation(a, b)).toBe(result);
|
|
18
|
+
});
|
|
19
|
+
it.each `
|
|
20
|
+
str | substr | result
|
|
21
|
+
${"alOOf"} | ${"oo"} | ${true}
|
|
22
|
+
${"Hello"} | ${""} | ${true}
|
|
23
|
+
${"Hello"} | ${"X"} | ${false}
|
|
24
|
+
`("string_contains $str, $substr", ({ str, substr, result }) => {
|
|
25
|
+
expect(string_1.stringOperators.string_contains.implementation(str, substr)).toBe(result);
|
|
26
|
+
});
|
|
27
|
+
it.each `
|
|
28
|
+
str | substr | result
|
|
29
|
+
${"alOOf"} | ${"oo"} | ${false}
|
|
30
|
+
${"Hello"} | ${""} | ${false}
|
|
31
|
+
${"Hello"} | ${"X"} | ${true}
|
|
32
|
+
`("string_ncontains $str, $substr", ({ str, substr, result }) => {
|
|
33
|
+
expect(string_1.stringOperators.string_ncontains.implementation(str, substr)).toBe(result);
|
|
34
|
+
});
|
|
35
|
+
it.each `
|
|
36
|
+
str | substr | result
|
|
37
|
+
${"alOOf"} | ${"alo"} | ${true}
|
|
38
|
+
${"Hello"} | ${""} | ${true}
|
|
39
|
+
${"Hello"} | ${"X"} | ${false}
|
|
40
|
+
`("string_startsWith $str, $substr", ({ str, substr, result }) => {
|
|
41
|
+
expect(string_1.stringOperators.string_startsWith.implementation(str, substr)).toBe(result);
|
|
42
|
+
});
|
|
43
|
+
it.each `
|
|
44
|
+
str | substr | result
|
|
45
|
+
${"alOOf"} | ${"alo"} | ${false}
|
|
46
|
+
${"Hello"} | ${""} | ${false}
|
|
47
|
+
${"Hello"} | ${"X"} | ${true}
|
|
48
|
+
`("string_nstartsWith $str, $substr", ({ str, substr, result }) => {
|
|
49
|
+
expect(string_1.stringOperators.string_nstartsWith.implementation(str, substr)).toBe(result);
|
|
50
|
+
});
|
|
51
|
+
it.each `
|
|
52
|
+
str | substr | result
|
|
53
|
+
${"alOOf"} | ${"oof"} | ${true}
|
|
54
|
+
${"Hello"} | ${""} | ${true}
|
|
55
|
+
${"Hello"} | ${"X"} | ${false}
|
|
56
|
+
`("string_endsWith $str, $substr", ({ str, substr, result }) => {
|
|
57
|
+
expect(string_1.stringOperators.string_endsWith.implementation(str, substr)).toBe(result);
|
|
58
|
+
});
|
|
59
|
+
it.each `
|
|
60
|
+
str | substr | result
|
|
61
|
+
${"alOOf"} | ${"oof"} | ${false}
|
|
62
|
+
${"Hello"} | ${""} | ${false}
|
|
63
|
+
${"Hello"} | ${"X"} | ${true}
|
|
64
|
+
`("string_nendsWith $str, $substr", ({ str, substr, result }) => {
|
|
65
|
+
expect(string_1.stringOperators.string_nendsWith.implementation(str, substr)).toBe(result);
|
|
66
|
+
});
|
|
67
|
+
it.each `
|
|
68
|
+
str | regex | result
|
|
69
|
+
${"Hello"} | ${/[^A-za-z]/} | ${false}
|
|
70
|
+
${"Hēllō"} | ${/[^A-za-z]/} | ${true}
|
|
71
|
+
`("string_regex $str, $regex", ({ str, regex, result }) => {
|
|
72
|
+
expect(string_1.stringOperators.string_regex.implementation(str, regex)).toBe(result);
|
|
73
|
+
});
|
|
74
|
+
});
|