Skip to content

Commit

Permalink
Add test cases for complex type validation. Refs #392
Browse files Browse the repository at this point in the history
  • Loading branch information
ruscoder committed Dec 3, 2024
1 parent ce28c0d commit f9073a3
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 90 deletions.
166 changes: 166 additions & 0 deletions src/utils/__tests__/questionnaire/complex-type-validation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import { Questionnaire, QuestionnaireResponseItemAnswer } from '@beda.software/aidbox-types';

import { questionnaireToValidationSchema } from 'src/utils';

type QuestionnaireData = {
questionnaire: Questionnaire;
answer: Record<string, QuestionnaireResponseItemAnswer[] | undefined>;
success: boolean;
};

const QUESTIONNAIRES_TEST_DATA: QuestionnaireData[] = [
{
questionnaire: {
resourceType: 'Questionnaire',
id: 'reference-required',
title: 'Reference required',
status: 'active',
item: [
{
linkId: 'reference-required-filled',
type: 'reference',
text: 'Reference required',
repeats: true,
required: true,
},
],
},
answer: {
'reference-required-filled': [
{
value: {
Reference: {
resourceType: 'Patient',
id: '1',
display: 'Patient 1',
},
},
},
],
},
success: true,
},
{
questionnaire: {
resourceType: 'Questionnaire',
id: 'reference-required',
title: 'Reference required',
status: 'active',
item: [
{
linkId: 'reference-required-filled',
type: 'reference',
text: 'Reference required',
repeats: false,
required: true,
},
],
},
answer: {
'reference-required-filled': undefined,
},
success: false,
},
{
questionnaire: {
resourceType: 'Questionnaire',
id: 'reference-required',
title: 'Reference required',
status: 'active',
item: [
{
linkId: 'reference-required-filled',
type: 'reference',
text: 'Reference required',
repeats: true,
required: true,
},
],
},
answer: {
'reference-required-filled': [],
},
success: false,
},
{
questionnaire: {
resourceType: 'Questionnaire',
id: 'reference-optional',
title: 'Reference optional',
status: 'active',
item: [
{
linkId: 'reference-optional-filled',
type: 'reference',
text: 'Reference optional',
repeats: true,
required: false,
},
],
},
answer: {
'reference-optional-filled': [],
},
success: true,
},
{
questionnaire: {
resourceType: 'Questionnaire',
id: 'reference-required',
title: 'Reference required',
status: 'active',
item: [
{
linkId: 'reference-required-filled',
type: 'reference',
text: 'Reference required',
repeats: false,
required: false,
},
],
},
answer: {
'reference-required-filled': undefined,
},
success: true,
},
{
questionnaire: {
resourceType: 'Questionnaire',
id: 'reference-required',
title: 'Reference required',
status: 'active',
item: [
{
linkId: 'reference-required-filled',
type: 'reference',
text: 'Reference required',
repeats: false,
required: false,
},
],
},
answer: {
'reference-required-filled': [
{
value: {
Reference: {
resourceType: 'Patient',
id: '1',
display: 'Patient 1',
},
},
},
],
},
success: true,
},
];

describe('Complex type validation', () => {
test.each(QUESTIONNAIRES_TEST_DATA)('should return the correct result', async (questionnaireData) => {
const validationSchema = questionnaireToValidationSchema(questionnaireData.questionnaire);
const isValid = await validationSchema.isValid(questionnaireData.answer);
expect(isValid).toBe(questionnaireData.success);
});
});
90 changes: 0 additions & 90 deletions src/utils/__tests__/questionnaire/reference.test.ts

This file was deleted.

0 comments on commit f9073a3

Please sign in to comment.