Skip to content

Commit 827ba1b

Browse files
committed
chore: add more tests for missing vars
1 parent 81402ed commit 827ba1b

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/tests/jsonLogic.fixtures.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,29 @@ export const schemaWithMissingRule = {
9494
required: [],
9595
};
9696

97+
export const schemaWithUnknownVariableInValidations = {
98+
properties: {},
99+
'x-jsf-logic': {
100+
validations: {
101+
a_equals_ten: {
102+
errorMessage: 'Must equal 10',
103+
rule: { '===': [{ var: 'field_a' }, 10] },
104+
},
105+
},
106+
},
107+
};
108+
109+
export const schemaWithUnknownVariableInComputedValues = {
110+
properties: {},
111+
'x-jsf-logic': {
112+
computedValues: {
113+
a_times_ten: {
114+
rule: { '*': [{ var: 'field_a' }, 10] },
115+
},
116+
},
117+
},
118+
};
119+
97120
export const schemaWithMissingComputedValue = {
98121
properties: {
99122
field_a: {

src/tests/jsonLogic.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
schemaWithNativeAndJSONLogicChecks,
1616
schemaWithNonRequiredField,
1717
schemaWithTwoRules,
18+
schemaWithUnknownVariableInComputedValues,
19+
schemaWithUnknownVariableInValidations,
1820
} from './jsonLogic.fixtures';
1921
import { mockConsole, restoreConsoleAndEnsureItWasNotCalled } from './testUtils';
2022

@@ -102,6 +104,16 @@ describe('jsonLogic: cross-values validations', () => {
102104
schemaWithMissingRule,
103105
'[json-schema-form] json-logic error: Validation "a_greater_than_ten" has missing rule.',
104106
],
107+
[
108+
'x-jsf-validations: throw when theres a value that does not exist in a rule',
109+
schemaWithUnknownVariableInValidations,
110+
'"field_a" in rule "a_equals_ten" does not exist as a JSON schema property.',
111+
],
112+
[
113+
'x-jsf-validations: throw when theres a value that does not exist in a rule',
114+
schemaWithUnknownVariableInComputedValues,
115+
'"field_a" in rule "a_times_ten" does not exist as a JSON schema property.',
116+
],
105117
[
106118
'x-jsf-logic.computedValues: throw when theres a missing computed value',
107119
schemaWithMissingComputedValue,

0 commit comments

Comments
 (0)