Skip to content
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: AJV $data reference in const property in schema treated as default/const value. #4431

Merged
merged 7 commits into from
Jan 8, 2025
Prev Previous commit
Next Next commit
written a test for consIsAjvDataReference.
  • Loading branch information
abdalla-rko committed Jan 4, 2025
commit efe76cf0b0e2ad576723b9948497547f5072abc9
53 changes: 53 additions & 0 deletions packages/utils/test/constIsAjvDataReference.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { RJSFSchema } from 'src';
import constIsAjvDataReference from '../src/constIsAjvDataReference';

describe('constIsAjvDataReference()', () => {
describe('check if schema contains $data reference', () => {
it('should return true when the const property contains a $data reference', () => {
const schema: RJSFSchema = {
type: 'string',
const: {
$data: '/email',
},
title: 'Confirm e-mail',
format: 'email',
};
expect(constIsAjvDataReference(schema)).toEqual(true);
});

it('should return false when the const property does not contain a $data reference', () => {
const schema: RJSFSchema = {
type: 'string',
const: 'hello world',
};
expect(constIsAjvDataReference(schema)).toEqual(false);
});

it('Should return false when the const property is not present in the schema', () => {
const schema: RJSFSchema = {
type: 'string',
};
expect(constIsAjvDataReference(schema)).toEqual(false);
});

it('Should return false when the $data reference is at the object level.', () => {
const schema: RJSFSchema = {
type: 'object',
properties: {
$data: {
type: 'string',
},
},
const: {
$data: 'Hello World!',
},
};
expect(constIsAjvDataReference(schema)).toEqual(false);
});

it('should return false when the schema is invalid', () => {
const schema = 'hello world' as unknown as RJSFSchema;
expect(constIsAjvDataReference(schema)).toEqual(false);
});
});
});