@featurevisor/core 3.1.0 → 3.3.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/lib/datasource/datasource.d.ts +1 -1
- package/lib/datasource/datasource.js +4 -14
- package/lib/datasource/datasource.js.map +1 -1
- package/lib/datasource/requiredFeatures.d.ts +7 -0
- package/lib/datasource/requiredFeatures.js +38 -0
- package/lib/datasource/requiredFeatures.js.map +1 -0
- package/lib/linter/checkCircularDependency.d.ts +1 -1
- package/lib/linter/checkCircularDependency.js +3 -22
- package/lib/linter/checkCircularDependency.js.map +1 -1
- package/lib/linter/conditionSchema.js +27 -3
- package/lib/linter/conditionSchema.js.map +1 -1
- package/lib/linter/testSchema.d.ts +4 -0
- package/lib/linter/testSchema.js +46 -4
- package/lib/linter/testSchema.js.map +1 -1
- package/lib/promoter/index.js +62 -1
- package/lib/promoter/index.js.map +1 -1
- package/lib/tester/testFeature.js +17 -16
- package/lib/tester/testFeature.js.map +1 -1
- package/package.json +10 -7
- package/CHANGELOG.md +0 -2246
- package/coverage/clover.xml +0 -5456
- package/coverage/coverage-final.json +0 -64
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -371
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/src/assess-distribution/index.html +0 -116
- package/coverage/lcov-report/src/assess-distribution/index.ts.html +0 -754
- package/coverage/lcov-report/src/benchmark/index.html +0 -116
- package/coverage/lcov-report/src/benchmark/index.ts.html +0 -793
- package/coverage/lcov-report/src/builder/allocator.ts.html +0 -220
- package/coverage/lcov-report/src/builder/applyContextToConditions.ts.html +0 -502
- package/coverage/lcov-report/src/builder/applyContextToDatafile.ts.html +0 -772
- package/coverage/lcov-report/src/builder/applyContextToSegments.ts.html +0 -580
- package/coverage/lcov-report/src/builder/buildDatafile.ts.html +0 -2053
- package/coverage/lcov-report/src/builder/buildProject.ts.html +0 -1117
- package/coverage/lcov-report/src/builder/buildRuntimeDatafiles.ts.html +0 -256
- package/coverage/lcov-report/src/builder/getFeatureRanges.ts.html +0 -268
- package/coverage/lcov-report/src/builder/hashes.ts.html +0 -412
- package/coverage/lcov-report/src/builder/index.html +0 -311
- package/coverage/lcov-report/src/builder/index.ts.html +0 -91
- package/coverage/lcov-report/src/builder/mutateVariables.ts.html +0 -421
- package/coverage/lcov-report/src/builder/mutator.ts.html +0 -796
- package/coverage/lcov-report/src/builder/revision.ts.html +0 -151
- package/coverage/lcov-report/src/builder/traffic.ts.html +0 -661
- package/coverage/lcov-report/src/cli/cli.ts.html +0 -400
- package/coverage/lcov-report/src/cli/index.html +0 -131
- package/coverage/lcov-report/src/cli/plugins.ts.html +0 -214
- package/coverage/lcov-report/src/config/index.html +0 -131
- package/coverage/lcov-report/src/config/index.ts.html +0 -88
- package/coverage/lcov-report/src/config/projectConfig.ts.html +0 -925
- package/coverage/lcov-report/src/datasource/adapter.ts.html +0 -253
- package/coverage/lcov-report/src/datasource/datasource.ts.html +0 -1000
- package/coverage/lcov-report/src/datasource/filesystemAdapter.ts.html +0 -1576
- package/coverage/lcov-report/src/datasource/index.html +0 -161
- package/coverage/lcov-report/src/datasource/index.ts.html +0 -94
- package/coverage/lcov-report/src/evaluate/index.html +0 -116
- package/coverage/lcov-report/src/evaluate/index.ts.html +0 -814
- package/coverage/lcov-report/src/find-duplicate-segments/findDuplicateSegments.ts.html +0 -313
- package/coverage/lcov-report/src/find-duplicate-segments/index.html +0 -131
- package/coverage/lcov-report/src/find-duplicate-segments/index.ts.html +0 -307
- package/coverage/lcov-report/src/find-usage/index.html +0 -116
- package/coverage/lcov-report/src/find-usage/index.ts.html +0 -1780
- package/coverage/lcov-report/src/generate-code/index.html +0 -131
- package/coverage/lcov-report/src/generate-code/index.ts.html +0 -403
- package/coverage/lcov-report/src/generate-code/typescript.ts.html +0 -1909
- package/coverage/lcov-report/src/index.html +0 -131
- package/coverage/lcov-report/src/info/index.html +0 -116
- package/coverage/lcov-report/src/info/index.ts.html +0 -472
- package/coverage/lcov-report/src/init/index.html +0 -116
- package/coverage/lcov-report/src/init/index.ts.html +0 -280
- package/coverage/lcov-report/src/linter/attributeSchema.ts.html +0 -1963
- package/coverage/lcov-report/src/linter/checkCircularDependency.ts.html +0 -220
- package/coverage/lcov-report/src/linter/checkPercentageExceedingSlot.ts.html +0 -268
- package/coverage/lcov-report/src/linter/conditionSchema.ts.html +0 -2224
- package/coverage/lcov-report/src/linter/featureSchema.ts.html +0 -5851
- package/coverage/lcov-report/src/linter/groupSchema.ts.html +0 -226
- package/coverage/lcov-report/src/linter/index.html +0 -326
- package/coverage/lcov-report/src/linter/index.ts.html +0 -88
- package/coverage/lcov-report/src/linter/lintProject.ts.html +0 -2704
- package/coverage/lcov-report/src/linter/mutationNotation.ts.html +0 -1411
- package/coverage/lcov-report/src/linter/printError.ts.html +0 -289
- package/coverage/lcov-report/src/linter/schema.ts.html +0 -1558
- package/coverage/lcov-report/src/linter/segmentSchema.ts.html +0 -139
- package/coverage/lcov-report/src/linter/targetSchema.ts.html +0 -223
- package/coverage/lcov-report/src/linter/testSchema.ts.html +0 -529
- package/coverage/lcov-report/src/linter/zodHelpers.ts.html +0 -133
- package/coverage/lcov-report/src/list/index.html +0 -131
- package/coverage/lcov-report/src/list/index.ts.html +0 -2065
- package/coverage/lcov-report/src/list/matrix.ts.html +0 -721
- package/coverage/lcov-report/src/promoter/index.html +0 -116
- package/coverage/lcov-report/src/promoter/index.ts.html +0 -3883
- package/coverage/lcov-report/src/sets.ts.html +0 -313
- package/coverage/lcov-report/src/targeting.ts.html +0 -403
- package/coverage/lcov-report/src/tester/cliFormat.ts.html +0 -133
- package/coverage/lcov-report/src/tester/helpers.ts.html +0 -313
- package/coverage/lcov-report/src/tester/index.html +0 -206
- package/coverage/lcov-report/src/tester/prettyDuration.ts.html +0 -187
- package/coverage/lcov-report/src/tester/printTestResult.ts.html +0 -337
- package/coverage/lcov-report/src/tester/testFeature.ts.html +0 -1186
- package/coverage/lcov-report/src/tester/testProject.ts.html +0 -1018
- package/coverage/lcov-report/src/tester/testSegment.ts.html +0 -316
- package/coverage/lcov-report/src/utils/extractKeys.ts.html +0 -493
- package/coverage/lcov-report/src/utils/git.ts.html +0 -559
- package/coverage/lcov-report/src/utils/index.html +0 -161
- package/coverage/lcov-report/src/utils/index.ts.html +0 -94
- package/coverage/lcov-report/src/utils/pretty.ts.html +0 -121
- package/coverage/lcov.info +0 -11615
- package/jest.config.js +0 -22
- package/json-schema/README.md +0 -5
- package/json-schema/attribute.json +0 -40
- package/json-schema/feature.json +0 -394
- package/json-schema/segment.json +0 -137
- package/src/assess-distribution/index.ts +0 -223
- package/src/benchmark/index.ts +0 -236
- package/src/builder/allocator.spec.ts +0 -105
- package/src/builder/allocator.ts +0 -45
- package/src/builder/applyContextToConditions.spec.ts +0 -2677
- package/src/builder/applyContextToConditions.ts +0 -139
- package/src/builder/applyContextToDatafile.spec.ts +0 -2626
- package/src/builder/applyContextToDatafile.ts +0 -229
- package/src/builder/applyContextToSegments.spec.ts +0 -1593
- package/src/builder/applyContextToSegments.ts +0 -165
- package/src/builder/buildDatafile.spec.ts +0 -445
- package/src/builder/buildDatafile.ts +0 -656
- package/src/builder/buildProject.ts +0 -344
- package/src/builder/buildRuntimeDatafiles.ts +0 -57
- package/src/builder/getFeatureRanges.ts +0 -61
- package/src/builder/hashes.ts +0 -109
- package/src/builder/index.ts +0 -2
- package/src/builder/mutateVariables.spec.ts +0 -1179
- package/src/builder/mutateVariables.ts +0 -112
- package/src/builder/mutator.spec.ts +0 -413
- package/src/builder/mutator.ts +0 -237
- package/src/builder/revision.spec.ts +0 -22
- package/src/builder/revision.ts +0 -22
- package/src/builder/traffic.spec.ts +0 -946
- package/src/builder/traffic.ts +0 -192
- package/src/cli/cli.ts +0 -105
- package/src/cli/index.ts +0 -2
- package/src/cli/plugins.ts +0 -43
- package/src/config/index.ts +0 -1
- package/src/config/projectConfig.spec.ts +0 -194
- package/src/config/projectConfig.ts +0 -280
- package/src/datasource/adapter.ts +0 -56
- package/src/datasource/datasource.ts +0 -305
- package/src/datasource/filesystemAdapter.spec.ts +0 -212
- package/src/datasource/filesystemAdapter.ts +0 -497
- package/src/datasource/index.ts +0 -3
- package/src/dependencies.ts +0 -13
- package/src/evaluate/index.ts +0 -243
- package/src/find-duplicate-segments/findDuplicateSegments.ts +0 -76
- package/src/find-duplicate-segments/index.ts +0 -74
- package/src/find-usage/index.ts +0 -565
- package/src/generate-code/index.ts +0 -106
- package/src/generate-code/typescript.spec.ts +0 -214
- package/src/generate-code/typescript.ts +0 -608
- package/src/index.ts +0 -20
- package/src/info/index.ts +0 -129
- package/src/init/index.ts +0 -65
- package/src/linter/attributeSchema.spec.ts +0 -342
- package/src/linter/attributeSchema.ts +0 -626
- package/src/linter/checkCircularDependency.ts +0 -45
- package/src/linter/checkPercentageExceedingSlot.ts +0 -61
- package/src/linter/conditionSchema.spec.ts +0 -510
- package/src/linter/conditionSchema.ts +0 -713
- package/src/linter/featureSchema.spec.ts +0 -1985
- package/src/linter/featureSchema.ts +0 -1922
- package/src/linter/groupSchema.ts +0 -47
- package/src/linter/index.ts +0 -1
- package/src/linter/lintProject.spec.ts +0 -336
- package/src/linter/lintProject.ts +0 -873
- package/src/linter/mutationNotation.spec.ts +0 -704
- package/src/linter/mutationNotation.ts +0 -442
- package/src/linter/printError.ts +0 -68
- package/src/linter/schema.spec.ts +0 -690
- package/src/linter/schema.ts +0 -491
- package/src/linter/segmentSchema.spec.ts +0 -358
- package/src/linter/segmentSchema.ts +0 -18
- package/src/linter/targetSchema.spec.ts +0 -159
- package/src/linter/targetSchema.ts +0 -46
- package/src/linter/testSchema.spec.ts +0 -258
- package/src/linter/testSchema.ts +0 -148
- package/src/linter/zodHelpers.ts +0 -16
- package/src/list/index.spec.ts +0 -135
- package/src/list/index.ts +0 -660
- package/src/list/matrix.spec.ts +0 -49
- package/src/list/matrix.ts +0 -212
- package/src/promoter/index.spec.ts +0 -617
- package/src/promoter/index.ts +0 -1266
- package/src/sets.ts +0 -76
- package/src/targeting.spec.ts +0 -74
- package/src/targeting.ts +0 -106
- package/src/tester/cliFormat.ts +0 -16
- package/src/tester/helpers.spec.ts +0 -149
- package/src/tester/helpers.ts +0 -76
- package/src/tester/index.ts +0 -2
- package/src/tester/prettyDuration.ts +0 -34
- package/src/tester/printTestResult.ts +0 -84
- package/src/tester/testFeature.ts +0 -367
- package/src/tester/testProject.spec.ts +0 -50
- package/src/tester/testProject.ts +0 -311
- package/src/tester/testSegment.ts +0 -77
- package/src/utils/extractKeys.ts +0 -136
- package/src/utils/git.ts +0 -158
- package/src/utils/index.ts +0 -3
- package/src/utils/pretty.ts +0 -12
- package/tsconfig.cjs.json +0 -13
- package/tsconfig.typecheck.json +0 -9
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Group, Rule } from "@featurevisor/types";
|
|
2
|
-
|
|
3
|
-
import { Datasource } from "../datasource";
|
|
4
|
-
|
|
5
|
-
// @NOTE: ideally in future, this check should be done from Feature level,
|
|
6
|
-
// as well as Group level as done here
|
|
7
|
-
export async function checkForFeatureExceedingGroupSlotPercentage(
|
|
8
|
-
datasource: Datasource,
|
|
9
|
-
group: Group,
|
|
10
|
-
availableFeatureKeys: string[],
|
|
11
|
-
) {
|
|
12
|
-
for (const slot of group.slots) {
|
|
13
|
-
const maxPercentageForRule = slot.percentage;
|
|
14
|
-
|
|
15
|
-
if (slot.feature) {
|
|
16
|
-
const featureKey = slot.feature;
|
|
17
|
-
const featureExists = availableFeatureKeys.indexOf(featureKey) > -1;
|
|
18
|
-
|
|
19
|
-
if (!featureExists) {
|
|
20
|
-
throw new Error(`Unknown feature "${featureKey}"`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const parsedFeature = await datasource.readFeature(featureKey);
|
|
24
|
-
|
|
25
|
-
const hasEnvironments =
|
|
26
|
-
parsedFeature.rules &&
|
|
27
|
-
!Array.isArray(parsedFeature.rules) &&
|
|
28
|
-
Object.keys(parsedFeature.rules).length > 0;
|
|
29
|
-
|
|
30
|
-
if (hasEnvironments && parsedFeature.rules) {
|
|
31
|
-
// with environments
|
|
32
|
-
const environmentKeys = Object.keys(parsedFeature.rules);
|
|
33
|
-
|
|
34
|
-
for (const environmentKey of environmentKeys) {
|
|
35
|
-
const rules = parsedFeature.rules[environmentKey];
|
|
36
|
-
|
|
37
|
-
for (const rule of rules) {
|
|
38
|
-
if (rule.percentage > maxPercentageForRule) {
|
|
39
|
-
// @NOTE: this does not help with same feature belonging to multiple slots. fix that.
|
|
40
|
-
throw new Error(
|
|
41
|
-
`Feature ${featureKey}'s rule ${rule.key} in ${environmentKey} has a percentage of ${rule.percentage} which is greater than the maximum percentage of ${maxPercentageForRule} for the slot`,
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
} else if (parsedFeature.rules) {
|
|
47
|
-
// no environments
|
|
48
|
-
const rules = parsedFeature.rules as Rule[];
|
|
49
|
-
|
|
50
|
-
for (const rule of rules) {
|
|
51
|
-
if (rule.percentage > maxPercentageForRule) {
|
|
52
|
-
// @NOTE: this does not help with same feature belonging to multiple slots. fix that.
|
|
53
|
-
throw new Error(
|
|
54
|
-
`Feature ${featureKey}'s rule ${rule.key} has a percentage of ${rule.percentage} which is greater than the maximum percentage of ${maxPercentageForRule} for the slot`,
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,510 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for condition schema validation (segment conditions, feature rules, etc.).
|
|
3
|
-
* Covers getConditionsZodSchema: attribute path resolution, operator/value compatibility,
|
|
4
|
-
* schema-aware value validation, regexFlags, nesting, and "*" (everyone).
|
|
5
|
-
*/
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
|
|
8
|
-
import type { Attribute } from "@featurevisor/types";
|
|
9
|
-
import type { ProjectConfig } from "../config";
|
|
10
|
-
import { getConditionsZodSchema } from "./conditionSchema";
|
|
11
|
-
|
|
12
|
-
function minimalProjectConfig(): ProjectConfig {
|
|
13
|
-
return {
|
|
14
|
-
featuresDirectoryPath: "",
|
|
15
|
-
segmentsDirectoryPath: "",
|
|
16
|
-
attributesDirectoryPath: "",
|
|
17
|
-
groupsDirectoryPath: "",
|
|
18
|
-
schemasDirectoryPath: "",
|
|
19
|
-
targetsDirectoryPath: "",
|
|
20
|
-
testsDirectoryPath: "",
|
|
21
|
-
stateDirectoryPath: "",
|
|
22
|
-
datafilesDirectoryPath: "",
|
|
23
|
-
datafileNamePattern: "",
|
|
24
|
-
revisionFileName: "",
|
|
25
|
-
catalogDirectoryPath: "",
|
|
26
|
-
setsDirectoryPath: "",
|
|
27
|
-
environments: ["staging", "production"],
|
|
28
|
-
sets: false,
|
|
29
|
-
namespaceCharacter: ".",
|
|
30
|
-
tags: ["all"],
|
|
31
|
-
adapter: {},
|
|
32
|
-
plugins: [],
|
|
33
|
-
defaultBucketBy: "userId",
|
|
34
|
-
parser: "yml",
|
|
35
|
-
prettyState: true,
|
|
36
|
-
prettyDatafile: false,
|
|
37
|
-
stringify: true,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const TEST_ATTRIBUTES: Record<string, Attribute> = {
|
|
42
|
-
userId: {
|
|
43
|
-
description: "User ID",
|
|
44
|
-
type: "string",
|
|
45
|
-
},
|
|
46
|
-
country: {
|
|
47
|
-
description: "Country",
|
|
48
|
-
type: "string",
|
|
49
|
-
enum: ["de", "fr", "nl", "us"],
|
|
50
|
-
},
|
|
51
|
-
device: {
|
|
52
|
-
description: "Device",
|
|
53
|
-
type: "string",
|
|
54
|
-
},
|
|
55
|
-
email: {
|
|
56
|
-
description: "Email",
|
|
57
|
-
type: "string",
|
|
58
|
-
pattern: "^[^@]+@[^@]+\\.[^@]+$",
|
|
59
|
-
},
|
|
60
|
-
age: {
|
|
61
|
-
description: "Age",
|
|
62
|
-
type: "integer",
|
|
63
|
-
minimum: 18,
|
|
64
|
-
},
|
|
65
|
-
browser: {
|
|
66
|
-
description: "Browser",
|
|
67
|
-
type: "object",
|
|
68
|
-
properties: {
|
|
69
|
-
name: {
|
|
70
|
-
type: "string",
|
|
71
|
-
enum: ["chrome", "firefox", "safari"],
|
|
72
|
-
},
|
|
73
|
-
version: {
|
|
74
|
-
type: "semver",
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
account: {
|
|
79
|
-
description: "Account",
|
|
80
|
-
type: "object",
|
|
81
|
-
properties: {
|
|
82
|
-
plan: {
|
|
83
|
-
type: "string",
|
|
84
|
-
enum: ["free", "pro"],
|
|
85
|
-
},
|
|
86
|
-
locale: {
|
|
87
|
-
type: "string",
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
labels: {
|
|
92
|
-
description: "Labels",
|
|
93
|
-
type: "object",
|
|
94
|
-
additionalProperties: {
|
|
95
|
-
type: "string",
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
permissions: {
|
|
99
|
-
description: "Permissions",
|
|
100
|
-
type: "array",
|
|
101
|
-
items: {
|
|
102
|
-
type: "string",
|
|
103
|
-
enum: ["read", "write", "admin"],
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
version: {
|
|
107
|
-
description: "Version",
|
|
108
|
-
oneOf: [{ type: "string" }, { type: "double" }],
|
|
109
|
-
},
|
|
110
|
-
traits: {
|
|
111
|
-
description: "Traits",
|
|
112
|
-
type: "object",
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
function getConditionsSchema() {
|
|
117
|
-
return getConditionsZodSchema(minimalProjectConfig(), TEST_ATTRIBUTES);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function parseConditions(input: unknown): z.ZodSafeParseResult<unknown> {
|
|
121
|
-
return getConditionsSchema().safeParse(input);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function expectConditionsSuccess(input: unknown): void {
|
|
125
|
-
const result = parseConditions(input);
|
|
126
|
-
expect(result.success).toBe(true);
|
|
127
|
-
if (!result.success) {
|
|
128
|
-
const err = (result as z.ZodSafeParseError<unknown>).error;
|
|
129
|
-
const msg = err.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join("; ");
|
|
130
|
-
throw new Error(`Expected conditions to pass: ${msg}`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function expectConditionsFailure(input: unknown, messageSubstring?: string): z.ZodError {
|
|
135
|
-
const result = parseConditions(input);
|
|
136
|
-
expect(result.success).toBe(false);
|
|
137
|
-
if (result.success) throw new Error("Expected conditions to fail");
|
|
138
|
-
const err = (result as z.ZodSafeParseError<unknown>).error;
|
|
139
|
-
if (messageSubstring) {
|
|
140
|
-
const messages = err.issues
|
|
141
|
-
.map((i) => (typeof i.message === "string" ? i.message : ""))
|
|
142
|
-
.join(" ");
|
|
143
|
-
expect(messages).toContain(messageSubstring);
|
|
144
|
-
}
|
|
145
|
-
return err;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function expectConditionErrorSurfaces(
|
|
149
|
-
input: unknown,
|
|
150
|
-
opts: { pathContains: string[]; messageContains: string },
|
|
151
|
-
): void {
|
|
152
|
-
const err = expectConditionsFailure(input, opts.messageContains);
|
|
153
|
-
const pathStrings = err.issues.map((i) => i.path.join("."));
|
|
154
|
-
const hasMatchingPath = pathStrings.some((p) =>
|
|
155
|
-
opts.pathContains.every((seg) => p.includes(seg)),
|
|
156
|
-
);
|
|
157
|
-
expect(hasMatchingPath).toBe(true);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
describe("conditionSchema.ts :: getConditionsZodSchema", () => {
|
|
161
|
-
describe("attribute path resolution", () => {
|
|
162
|
-
it("accepts direct attributes", () => {
|
|
163
|
-
expectConditionsSuccess({ attribute: "userId", operator: "equals", value: "u1" });
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("accepts nested attributes from declared object properties", () => {
|
|
167
|
-
expectConditionsSuccess({
|
|
168
|
-
attribute: "browser.name",
|
|
169
|
-
operator: "equals",
|
|
170
|
-
value: "chrome",
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it("accepts dynamic nested attributes via additionalProperties", () => {
|
|
175
|
-
expectConditionsSuccess({
|
|
176
|
-
attribute: "labels.locale",
|
|
177
|
-
operator: "equals",
|
|
178
|
-
value: "nl-NL",
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("accepts one-level nested attributes on flat objects", () => {
|
|
183
|
-
expectConditionsSuccess({
|
|
184
|
-
attribute: "traits.favoriteColor",
|
|
185
|
-
operator: "equals",
|
|
186
|
-
value: "blue",
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("rejects unknown attributes", () => {
|
|
191
|
-
expectConditionsFailure(
|
|
192
|
-
{
|
|
193
|
-
attribute: "unknownAttr",
|
|
194
|
-
operator: "equals",
|
|
195
|
-
value: "x",
|
|
196
|
-
},
|
|
197
|
-
"Unknown attribute",
|
|
198
|
-
);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it("rejects paths that are too deep for flat objects", () => {
|
|
202
|
-
expectConditionsFailure(
|
|
203
|
-
{
|
|
204
|
-
attribute: "traits.preferences.theme",
|
|
205
|
-
operator: "equals",
|
|
206
|
-
value: "dark",
|
|
207
|
-
},
|
|
208
|
-
"Unknown attribute",
|
|
209
|
-
);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
describe("operator and value validation", () => {
|
|
214
|
-
it("accepts schema-aware equality checks", () => {
|
|
215
|
-
expectConditionsSuccess({
|
|
216
|
-
attribute: "browser.name",
|
|
217
|
-
operator: "equals",
|
|
218
|
-
value: "firefox",
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
it("rejects equality values outside enum constraints", () => {
|
|
223
|
-
expectConditionsFailure(
|
|
224
|
-
{
|
|
225
|
-
attribute: "browser.name",
|
|
226
|
-
operator: "equals",
|
|
227
|
-
value: "edge",
|
|
228
|
-
},
|
|
229
|
-
'Value does not match the schema of attribute "browser.name"',
|
|
230
|
-
);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it("accepts number equality on numeric attributes", () => {
|
|
234
|
-
expectConditionsSuccess({ attribute: "age", operator: "equals", value: 42 });
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it("accepts null equality checks", () => {
|
|
238
|
-
expectConditionsSuccess({ attribute: "userId", operator: "equals", value: null });
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it("rejects array values with equals", () => {
|
|
242
|
-
expectConditionsFailure(
|
|
243
|
-
{ attribute: "userId", operator: "equals", value: ["a", "b"] },
|
|
244
|
-
"value has to be",
|
|
245
|
-
);
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it("accepts numeric operators on numeric attributes", () => {
|
|
249
|
-
expectConditionsSuccess({
|
|
250
|
-
attribute: "age",
|
|
251
|
-
operator: "greaterThan",
|
|
252
|
-
value: 21,
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it("rejects numeric operators on string attributes", () => {
|
|
257
|
-
expectConditionsFailure(
|
|
258
|
-
{ attribute: "country", operator: "greaterThan", value: 10 },
|
|
259
|
-
"can only be used with integer or double attributes",
|
|
260
|
-
);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it("accepts string operators on string-like attributes", () => {
|
|
264
|
-
expectConditionsSuccess({
|
|
265
|
-
attribute: "email",
|
|
266
|
-
operator: "contains",
|
|
267
|
-
value: "@",
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it("rejects string operators on array attributes", () => {
|
|
272
|
-
expectConditionsFailure(
|
|
273
|
-
{ attribute: "permissions", operator: "contains", value: "admin" },
|
|
274
|
-
"can only be used with string-like attributes",
|
|
275
|
-
);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it("accepts date operators with ISO strings", () => {
|
|
279
|
-
expectConditionsSuccess({
|
|
280
|
-
attribute: "device",
|
|
281
|
-
operator: "before",
|
|
282
|
-
value: "2025-12-31T23:59:59Z",
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it("rejects date operators with invalid strings", () => {
|
|
287
|
-
expectConditionsFailure(
|
|
288
|
-
{ attribute: "device", operator: "after", value: "not-a-date" },
|
|
289
|
-
"ISO 8601",
|
|
290
|
-
);
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it("accepts semver operators on semver attributes", () => {
|
|
294
|
-
expectConditionsSuccess({
|
|
295
|
-
attribute: "browser.version",
|
|
296
|
-
operator: "semverEquals",
|
|
297
|
-
value: "1.0.0",
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
it("accepts semver operators on oneOf attributes when a string branch supports them", () => {
|
|
302
|
-
expectConditionsSuccess({
|
|
303
|
-
attribute: "version",
|
|
304
|
-
operator: "semverGreaterThan",
|
|
305
|
-
value: "5.0.0",
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
it("accepts numeric equality on oneOf attributes when a numeric branch matches", () => {
|
|
310
|
-
expectConditionsSuccess({
|
|
311
|
-
attribute: "version",
|
|
312
|
-
operator: "equals",
|
|
313
|
-
value: 5.5,
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
describe("array-aware operators", () => {
|
|
319
|
-
it("accepts in/notIn on scalar attributes", () => {
|
|
320
|
-
expectConditionsSuccess({
|
|
321
|
-
attribute: "country",
|
|
322
|
-
operator: "in",
|
|
323
|
-
value: ["de", "fr", "nl"],
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
it("rejects non-array values for in/notIn", () => {
|
|
328
|
-
expectConditionsFailure(
|
|
329
|
-
{ attribute: "country", operator: "notIn", value: "de" },
|
|
330
|
-
"value must be an array",
|
|
331
|
-
);
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
it("rejects in/notIn members that violate attribute schema", () => {
|
|
335
|
-
expectConditionsFailure(
|
|
336
|
-
{ attribute: "country", operator: "in", value: ["de", "unknown"] },
|
|
337
|
-
'Value at index 1 does not match the schema of attribute "country"',
|
|
338
|
-
);
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it("accepts includes for arrays with typed string items", () => {
|
|
342
|
-
expectConditionsSuccess({
|
|
343
|
-
attribute: "permissions",
|
|
344
|
-
operator: "includes",
|
|
345
|
-
value: "admin",
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
it("rejects includes values outside item enum constraints", () => {
|
|
350
|
-
expectConditionsFailure(
|
|
351
|
-
{
|
|
352
|
-
attribute: "permissions",
|
|
353
|
-
operator: "includes",
|
|
354
|
-
value: "delete",
|
|
355
|
-
},
|
|
356
|
-
'Value does not match the item schema of attribute "permissions"',
|
|
357
|
-
);
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
it("rejects non-string includes values for string arrays", () => {
|
|
361
|
-
expectConditionsFailure(
|
|
362
|
-
{
|
|
363
|
-
attribute: "permissions",
|
|
364
|
-
operator: "includes",
|
|
365
|
-
value: 42,
|
|
366
|
-
},
|
|
367
|
-
'Value does not match the item schema of attribute "permissions"',
|
|
368
|
-
);
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
describe("regex flags", () => {
|
|
373
|
-
it("accepts regexFlags with matches", () => {
|
|
374
|
-
expectConditionsSuccess({
|
|
375
|
-
attribute: "browser.version",
|
|
376
|
-
operator: "matches",
|
|
377
|
-
value: "1\\.0\\.0",
|
|
378
|
-
regexFlags: "i",
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
it("rejects invalid regexFlags", () => {
|
|
383
|
-
expectConditionsFailure(
|
|
384
|
-
{
|
|
385
|
-
attribute: "browser.version",
|
|
386
|
-
operator: "matches",
|
|
387
|
-
value: "x",
|
|
388
|
-
regexFlags: "invalid",
|
|
389
|
-
},
|
|
390
|
-
"regexFlags",
|
|
391
|
-
);
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
it("rejects duplicate regexFlags", () => {
|
|
395
|
-
expectConditionsFailure(
|
|
396
|
-
{
|
|
397
|
-
attribute: "browser.version",
|
|
398
|
-
operator: "matches",
|
|
399
|
-
value: "x",
|
|
400
|
-
regexFlags: "ii",
|
|
401
|
-
},
|
|
402
|
-
"unique",
|
|
403
|
-
);
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
it("rejects regexFlags when operator is not matches/notMatches", () => {
|
|
407
|
-
expectConditionsFailure(
|
|
408
|
-
{
|
|
409
|
-
attribute: "userId",
|
|
410
|
-
operator: "equals",
|
|
411
|
-
value: "u1",
|
|
412
|
-
regexFlags: "i",
|
|
413
|
-
},
|
|
414
|
-
"not needed",
|
|
415
|
-
);
|
|
416
|
-
});
|
|
417
|
-
});
|
|
418
|
-
|
|
419
|
-
describe("exists/notExists", () => {
|
|
420
|
-
it("accepts exists without value", () => {
|
|
421
|
-
expectConditionsSuccess({
|
|
422
|
-
attribute: "userId",
|
|
423
|
-
operator: "exists",
|
|
424
|
-
});
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
it("rejects exists with value", () => {
|
|
428
|
-
expectConditionsFailure(
|
|
429
|
-
{ attribute: "userId", operator: "exists", value: "x" },
|
|
430
|
-
"value is not needed",
|
|
431
|
-
);
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
describe("structure", () => {
|
|
436
|
-
it("accepts nested and/or/not conditions", () => {
|
|
437
|
-
expectConditionsSuccess({
|
|
438
|
-
or: [
|
|
439
|
-
{
|
|
440
|
-
and: [
|
|
441
|
-
{ attribute: "browser.name", operator: "equals", value: "chrome" },
|
|
442
|
-
{ attribute: "country", operator: "equals", value: "de" },
|
|
443
|
-
],
|
|
444
|
-
},
|
|
445
|
-
{ attribute: "permissions", operator: "includes", value: "admin" },
|
|
446
|
-
],
|
|
447
|
-
});
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
it("rejects empty and/or/not condition arrays", () => {
|
|
451
|
-
expectConditionsFailure({ and: [] });
|
|
452
|
-
expectConditionsFailure({ or: [] });
|
|
453
|
-
expectConditionsFailure({ not: [] });
|
|
454
|
-
});
|
|
455
|
-
|
|
456
|
-
it("rejects invalid nested conditions", () => {
|
|
457
|
-
expectConditionsFailure(
|
|
458
|
-
{
|
|
459
|
-
and: [
|
|
460
|
-
{ attribute: "userId", operator: "equals", value: "u1" },
|
|
461
|
-
{ attribute: "browser.name", operator: "equals", value: "edge" },
|
|
462
|
-
],
|
|
463
|
-
},
|
|
464
|
-
'Value does not match the schema of attribute "browser.name"',
|
|
465
|
-
);
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
it("accepts literal * as conditions", () => {
|
|
469
|
-
expectConditionsSuccess("*");
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
it("accepts arrays of plain conditions", () => {
|
|
473
|
-
expectConditionsSuccess([
|
|
474
|
-
{ attribute: "userId", operator: "equals", value: "u1" },
|
|
475
|
-
{ attribute: "country", operator: "equals", value: "de" },
|
|
476
|
-
]);
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
it("rejects and/or/not objects with extra keys", () => {
|
|
480
|
-
const result = parseConditions({
|
|
481
|
-
and: [{ attribute: "userId", operator: "equals", value: "u1" }],
|
|
482
|
-
extraKey: true,
|
|
483
|
-
});
|
|
484
|
-
expect(result.success).toBe(false);
|
|
485
|
-
});
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
describe("error surfacing", () => {
|
|
489
|
-
it("reports unknown attributes at the attribute path", () => {
|
|
490
|
-
expectConditionErrorSurfaces(
|
|
491
|
-
{ attribute: "typoAttr", operator: "equals", value: "x" },
|
|
492
|
-
{ pathContains: ["attribute"], messageContains: "Unknown attribute" },
|
|
493
|
-
);
|
|
494
|
-
});
|
|
495
|
-
|
|
496
|
-
it("reports schema mismatches at the value path", () => {
|
|
497
|
-
expectConditionErrorSurfaces(
|
|
498
|
-
{ attribute: "browser.name", operator: "equals", value: "edge" },
|
|
499
|
-
{ pathContains: ["value"], messageContains: "Value does not match the schema" },
|
|
500
|
-
);
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
it("reports array item schema mismatches at the value path", () => {
|
|
504
|
-
expectConditionErrorSurfaces(
|
|
505
|
-
{ attribute: "country", operator: "in", value: ["de", "edge"] },
|
|
506
|
-
{ pathContains: ["value"], messageContains: "Value at index 1 does not match" },
|
|
507
|
-
);
|
|
508
|
-
});
|
|
509
|
-
});
|
|
510
|
-
});
|