-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug fix - nested restrictions #236
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { SchemaField, type SchemaStringField } from '@overture-stack/lectern-dictionary'; | ||
import { fieldStringNoRestriction } from '../noRestrictions/fieldStringNoRestriction'; | ||
import { validateFixture } from '../../../testUtils/validateFixture'; | ||
|
||
export const fieldStringConditionalExistsWithouthThenElse = { | ||
name: 'conditional-field', | ||
valueType: 'string', | ||
description: 'Required if `fieldStringNoRestriction` field exists, otherwise must be empty', | ||
restrictions: { | ||
if: { | ||
conditions: [ | ||
{ | ||
fields: [fieldStringNoRestriction.name], | ||
match: { | ||
exists: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
} as const satisfies SchemaStringField; | ||
|
||
validateFixture( | ||
fieldStringConditionalExistsWithouthThenElse, | ||
SchemaField, | ||
'fieldStringConditionalExistsWithouthThenElse is not a valid SchemaField', | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,8 @@ import { fieldBooleanArrayRequired } from '../fixtures/fields/simpleRestrictions | |
import { fieldStringCodeList } from '../fixtures/fields/simpleRestrictions/string/fieldStringCodeList'; | ||
import { codeListString } from '../fixtures/restrictions/codeListsFixtures'; | ||
import { fieldStringArrayCodeList } from '../fixtures/fields/simpleRestrictions/string/fieldStringArrayCodeList'; | ||
import { fieldStringConditionalExists } from '../fixtures/fields/conditionalRestrictions/fieldStringConditionalExists'; | ||
import { fieldStringConditionalExistsWithouthThenElse } from '../fixtures/fields/conditionalRestrictions/fieldStringConditionalExistsWithouthThenElse'; | ||
|
||
describe('Parse Values - parseFieldValue', () => { | ||
describe('Single Value Fields', () => { | ||
|
@@ -165,6 +167,34 @@ describe('Parse Values - parseFieldValue', () => { | |
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringNoRestriction).success).true; | ||
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringNoRestriction).data).equals('!@#$%^&* ()_+'); | ||
}); | ||
it('Successfuly parses strings, with conditional restrictions', () => { | ||
const value = 'any random string value!!!'; | ||
const result = parseFieldValue(value, fieldStringConditionalExists); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. testing parsing any string using a Schema Field Definition having |
||
expect(result.success).true; | ||
expect(result.data).equal(value); | ||
|
||
expect(parseFieldValue(' 123', fieldStringConditionalExists).success).true; | ||
expect(parseFieldValue(' 123', fieldStringConditionalExists).data).equals('123'); | ||
expect(parseFieldValue('false ', fieldStringConditionalExists).success).true; | ||
expect(parseFieldValue('false ', fieldStringConditionalExists).data).equals('false'); | ||
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringConditionalExists).success).true; | ||
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringConditionalExists).data).equals('!@#$%^&* ()_+'); | ||
}); | ||
it('Successfuly parses strings, with conditional restrictions without then or else', () => { | ||
const value = 'any random string value!!!'; | ||
const result = parseFieldValue(value, fieldStringConditionalExistsWithouthThenElse); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing parsing any string using a Schema Field Definition having an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the expected behaviour that an if without then/else just never applies restrictions? Should we consider adding validation to lectern dictionaries to require an if to have a then or else (at least one of the two)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If not then/else is found in the schema definition the expected behaviour is do not apply the restriction. Based on test resolveFieldRestrictions.spec.ts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm open to add a validation to require at least one between then/else. Although it could be added in a separate PR |
||
expect(result.success).true; | ||
expect(result.data).equal(value); | ||
|
||
expect(parseFieldValue(' 123', fieldStringConditionalExistsWithouthThenElse).success).true; | ||
expect(parseFieldValue(' 123', fieldStringConditionalExistsWithouthThenElse).data).equals('123'); | ||
expect(parseFieldValue('false ', fieldStringConditionalExistsWithouthThenElse).success).true; | ||
expect(parseFieldValue('false ', fieldStringConditionalExistsWithouthThenElse).data).equals('false'); | ||
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringConditionalExistsWithouthThenElse).success).true; | ||
expect(parseFieldValue(' !@#$%^&* ()_+ ', fieldStringConditionalExistsWithouthThenElse).data).equals( | ||
'!@#$%^&* ()_+', | ||
); | ||
}); | ||
it('Updates string to match formatting of codeList value', () => { | ||
const value = 'banana'; | ||
const result = parseFieldValue(value, fieldStringCodeList); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in file name: Withouth