diff --git a/src/lib/validate-app-settings.js b/src/lib/validate-app-settings.js index fc0382753..52fc98920 100644 --- a/src/lib/validate-app-settings.js +++ b/src/lib/validate-app-settings.js @@ -42,7 +42,7 @@ const ScheduleSchema = joi.array().items( name: joi.string().required(), summary: joi.string().allow(''), description: joi.string().allow(''), - start_from: joi.string(), + start_from: joi.alternatives().try(joi.string(), joi.array()), start_mid_group: joi.boolean(), translation_key: joi.string(), messages: joi.array().items( diff --git a/test/lib/validate-app-settings.spec.js b/test/lib/validate-app-settings.spec.js index 52d4e3bcf..e830fb383 100644 --- a/test/lib/validate-app-settings.spec.js +++ b/test/lib/validate-app-settings.spec.js @@ -30,7 +30,7 @@ describe('validate-app-settings', () => { patient_id: { position: 0, flags: { input_digits_only: true }, - length: [ 5, 13 ], + length: [5, 13], type: 'string', required: true } @@ -84,4 +84,66 @@ describe('validate-app-settings', () => { }); + describe('validateSchedulesSchema', () => { + const isValid = (schedulesObject) => { + const result = validateAppSettings.validateScheduleSchema(schedulesObject); + expect(result.valid).to.be.true; + }; + + const isNotValid = (schedulesObject, errorMessage) => { + const result = validateAppSettings.validateScheduleSchema(schedulesObject); + expect(result.valid).to.be.false; + expect(result.error.details.length).to.equal(1); + expect(result.error.details[0].message).to.equal(errorMessage); + }; + + it('returns valid for starter schedule.', () => { + isValid([{ + name: 'schedule name', + messages: [{ + translation_key: 'a.b', + group: '1', + offset: '0' + }] + }]); + }); + + it('start_from as string is valid.', () => { + isValid([{ + name: 'schedule name', + start_from: 'dob', + messages: [{ + translation_key: 'a.b', + group: '1', + offset: '0' + }] + }]); + }); + + it('start_from as an array is valid.', () => { + isValid([{ + name: 'schedule name', + start_from: ['dob', 'lmp_date'], + messages: [{ + translation_key: 'a.b', + group: '1', + offset: '0' + }] + }]); + }); + + it('start_from as a number is invalid.', () => { + isNotValid([{ + name: 'schedule name', + start_from: 1, + messages: [{ + translation_key: 'a.b', + group: '1', + offset: '0' + }] + }], '"[0].start_from" must be one of [string, array]'); + }); + + }); + });