diff --git a/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js b/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js index 3e8a610..5497d47 100644 --- a/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js +++ b/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js @@ -12,342 +12,352 @@ const { const validator = createValidator(schema, errorMessages); +// we save this for some other shinanigans +const iit = it; -describe('validation', function() { +function validateTemplate(template) { - function validateTemplate(template) { + const valid = validator(template); - const valid = validator(template); + const errors = validator.errors; - const errors = validator.errors; + return { + valid, + errors + }; +} - return { - valid, - errors - }; +function createTest(name, file, it) { + + if (!file) { + file = `../fixtures/${name}.js`; } - function testTemplate(name, file, only = false) { + it(name, async function() { + + // given + const testDefinition = await import(file); - if (!file) { - file = `../fixtures/${name}.js`; - } + const { + errors: expectedErrors, + template + } = testDefinition; - (only ? it.only : it)('should validate template - ' + name, async function() { + // when + const { + errors + } = validateTemplate(template); - // given - const testDefinition = await import(file); + // then + expect(errors).to.eql(expectedErrors); + }); +} - const { - errors: expectedErrors, - template - } = testDefinition; - // when - const { - errors - } = validateTemplate(template); +describe('validation', function() { - // then - expect(errors).to.eql(expectedErrors); - }); + function it(name, file) { + return createTest(name, file, iit); } - // eslint-disable-next-line no-unused-vars - function testOnly(name, file) { - return testTemplate(name, file, true); - } + it.only = function only(name, file) { + return createTest(name, file, iit.only); + }; + + it.skip = function skip(name, file) { + return createTest(name, file, iit.skip); + }; - describe('single template', function() { + describe('should validate single template', function() { - testTemplate('cloud-rest-connector'); + it('cloud-rest-connector'); - testTemplate('missing-type'); + it('missing-type'); - testTemplate('missing-applies-to'); + it('missing-applies-to'); - testTemplate('missing-template-name'); + it('missing-template-name'); - testTemplate('missing-template-id'); + it('missing-template-id'); - testTemplate('missing-properties'); + it('missing-properties'); - testTemplate('missing-binding'); + it('missing-binding'); - testTemplate('applies-to-single'); + it('applies-to-single'); - testTemplate('number-value'); + it('number-value'); - testTemplate('additional-property'); + it('additional-property'); - testTemplate('invalid-binding-type'); + it('invalid-binding-type'); - testTemplate('choices-missing-value'); + it('choices-missing-value'); - testTemplate('choices-missing-name'); + it('choices-missing-name'); - testTemplate('missing-choices'); + it('missing-choices'); - testTemplate('missing-binding-zeebe-output-source'); + it('missing-binding-zeebe-output-source'); - testTemplate('missing-binding-zeebe-input-name'); + it('missing-binding-zeebe-input-name'); - testTemplate('missing-binding-zeebe-header-key'); + it('missing-binding-zeebe-header-key'); - testTemplate('with-version'); + it('with-version'); - testTemplate('invalid-version'); + it('invalid-version'); - testTemplate('constraints'); + it('constraints'); - testTemplate('deprecated-bool'); + it('deprecated-bool'); - testTemplate('deprecated-invalid'); + it('deprecated-invalid'); - testTemplate('deprecated-object'); + it('deprecated-object'); - testTemplate('invalid-constraints'); + it('invalid-constraints'); - testTemplate('invalid-applies-to'); + it('invalid-applies-to'); - testTemplate('entries-visible-boolean'); + it('entries-visible-boolean'); - testTemplate('feel'); + it('feel'); - testTemplate('feel-type-mismatch'); + it('feel-type-mismatch'); - testTemplate('feel-value-mismatch'); + it('feel-value-mismatch'); - testTemplate('language'); + it('language'); - testTemplate('pattern-string'); + it('pattern-string'); - testTemplate('optional-valid'); + it('optional-valid'); - testTemplate('optional-invalid-type'); + it('optional-invalid-type'); - testTemplate('optional-invalid-not-empty'); + it('optional-invalid-not-empty'); - testTemplate('documentation-ref'); + it('documentation-ref'); - testTemplate('invalid-documentation-ref'); + it('invalid-documentation-ref'); - testTemplate('element-type'); + it('element-type'); - testTemplate('element-type-no-value'); + it('element-type-no-value'); - testTemplate('element-type-invalid'); + it('element-type-invalid'); describe('element type - event definition', function() { - testTemplate('element-type-event-definition'); + it('element-type-event-definition'); - testTemplate('element-type-event-definition-invalid'); + it('element-type-event-definition-invalid'); - testTemplate('element-type-event-definition-invalid-element'); + it('element-type-event-definition-invalid-element'); }); describe('property type - binding type', function() { - testTemplate('invalid-property-type'); + it('invalid-property-type'); - testTemplate('invalid-zeebe-input-type'); + it('invalid-zeebe-input-type'); - testTemplate('invalid-zeebe-output-type'); + it('invalid-zeebe-output-type'); - testTemplate('invalid-zeebe-task-header-type'); + it('invalid-zeebe-task-header-type'); - testTemplate('invalid-zeebe-task-definition-type-type'); + it('invalid-zeebe-task-definition-type-type'); - testTemplate('invalid-zeebe-task-definition'); + it('invalid-zeebe-task-definition'); }); describe('zeebe:property', function() { - testTemplate('zeebe-property-type'); + it('zeebe-property-type'); - testTemplate('invalid-zeebe-property-type'); + it('invalid-zeebe-property-type'); }); describe('grouping', function() { - testTemplate('groups'); + it('groups'); - testTemplate('groups-missing-id'); + it('groups-missing-id'); - testTemplate('groups-missing-label'); + it('groups-missing-label'); - testTemplate('groups-wrong-open-state'); + it('groups-wrong-open-state'); }); describe('icons', function() { - testTemplate('icon'); + it('icon'); - testTemplate('icon-https'); + it('icon-https'); - testTemplate('icon-encoded-url'); + it('icon-encoded-url'); - testTemplate('invalid-icon-raw-svg'); + it('invalid-icon-raw-svg'); - testTemplate('invalid-icon-malformed-data-uri'); + it('invalid-icon-malformed-data-uri'); - testTemplate('invalid-icon-missing-contents'); + it('invalid-icon-missing-contents'); }); describe('condition', function() { - testTemplate('condition'); + it('condition'); - testTemplate('condition-missing-property'); + it('condition-missing-property'); - testTemplate('condition-missing-condition-keyword'); + it('condition-missing-condition-keyword'); - testTemplate('condition-wrong-types'); + it('condition-wrong-types'); - testTemplate('condition-default-type'); + it('condition-default-type'); - testTemplate('condition-wrong-type'); + it('condition-wrong-type'); - testTemplate('condition-multiple'); + it('condition-multiple'); - testTemplate('condition-empty-allMatch'); + it('condition-empty-allMatch'); - testTemplate('condition-allMatch-one-condition'); + it('condition-allMatch-one-condition'); - testTemplate('condition-dropdown-choices'); + it('condition-dropdown-choices'); - testTemplate('condition-dropdown-choices-invalid'); + it('condition-dropdown-choices-invalid'); - testTemplate('condition-on-itself'); + it('condition-on-itself'); - testTemplate('condition-on-itself-allMatch'); + it('condition-on-itself-allMatch'); - testTemplate('condition-on-itself-dropdown-choices'); + it('condition-on-itself-dropdown-choices'); }); describe('message property', function() { - testTemplate('message-property-valid'); + it('message-property-valid'); - testTemplate('message-property-invalid'); + it('message-property-invalid'); - testTemplate('message-property-invalid-event-definition'); + it('message-property-invalid-event-definition'); }); describe('message subscription property', function() { - testTemplate('message-subscription-property-valid'); + it('message-subscription-property-valid'); - testTemplate('message-subscription-property-invalid'); + it('message-subscription-property-invalid'); - testTemplate('message-subscription-property-invalid-event-definition'); + it('message-subscription-property-invalid-event-definition'); - testTemplate('message-subscription-property-invalid-element-type'); + it('message-subscription-property-invalid-element-type'); }); describe('generated value', function() { - testTemplate('generated-value-valid'); + it('generated-value-valid'); - testTemplate('generated-value-invalid'); + it('generated-value-invalid'); - testTemplate('generated-value-clash'); + it('generated-value-clash'); }); describe('tooltip', function() { - testTemplate('tooltip'); + it('tooltip'); - testTemplate('tooltip-invalid'); + it('tooltip-invalid'); }); @@ -355,51 +365,51 @@ describe('validation', function() { describe('zeebe:taskDefinition', function() { - testTemplate('zeebe-task-definition'); + it('zeebe-task-definition'); - testTemplate('invalid-zeebe-task-definition'); + it('invalid-zeebe-task-definition'); }); describe('zeebe:calledElement', function() { - testTemplate('called-element'); + it('called-element'); - testTemplate('called-element-applies-to-only'); + it('called-element-applies-to-only'); - testTemplate('called-element-invalid-applies-to-no-element-type'); + it('called-element-invalid-applies-to-no-element-type'); - testTemplate('called-element-invalid-element-type'); + it('called-element-invalid-element-type'); - testTemplate('called-element-invalid-multiple-applies-to-no-element-type'); + it('called-element-invalid-multiple-applies-to-no-element-type'); - testTemplate('called-element-invalid-property'); + it('called-element-invalid-property'); - testTemplate('called-element-missing-property'); + it('called-element-missing-property'); }); describe('placeholder', function() { - testTemplate('placeholder'); + it('placeholder'); - testTemplate('placeholder-invalid-property'); + it('placeholder-invalid-property'); - testTemplate('placeholder-invalid-type'); + it('placeholder-invalid-type'); }); describe('engines', function() { - testTemplate('engines'); + it('engines'); - testTemplate('engines-no-camunda'); + it('engines-no-camunda'); - testTemplate('engines-invalid'); + it('engines-invalid'); - testTemplate('engines-invalid-version'); + it('engines-invalid-version'); }); });