@codefresh-io/yaml-validator
Version:
An NPM module/CLI for validating the Codefresh YAML
94 lines (82 loc) • 3.21 kB
JavaScript
/* eslint-env node, mocha */
/* eslint-disable no-unused-expressions,no-template-curly-in-string */
;
const chai = require('chai');
const BaseSchema = require('../schema/1.0/base-schema');
const { expect } = chai;
function expectValid(schema, value) {
const result = schema.validate(value);
expect(result.error).to.be.null;
}
function expectInvalid(schema, value) {
const result = schema.validate(value);
expect(result.error).not.to.be.null;
}
describe('schemas validation check', () => {
describe('ssh param', () => {
const schema = BaseSchema._getSshSchema();
describe('valid', () => {
it('should be valid when string "default"', () => {
expectValid(schema, 'default');
});
it('should be valid when array of strings', () => {
expectValid(schema, ['test_1', 'test_2']);
});
it('should be valid when object', () => {
expectValid(schema, { test: 'test' });
});
});
describe('invalid', () => {
it('should be only string with value "default" when string passed', () => {
expectInvalid(schema, 'asdf');
expectInvalid(schema, 'test');
});
it('should be invalid when empty array ', () => {
expectInvalid(schema, []);
});
it('should be invalid when empty object', () => {
expectInvalid(schema, {});
});
it('should be only array of strings', () => {
expectInvalid(schema, [1]);
expectInvalid(schema, [true]);
expectInvalid(schema, [{}]);
expectInvalid(schema, [[]]);
});
it('should be only object of strings', () => {
expectInvalid(schema, { test: 1 });
expectInvalid(schema, { test: true });
expectInvalid(schema, { test: [] });
expectInvalid(schema, { test: {} });
});
});
});
describe('secrets param', () => {
const schema = BaseSchema._getSecretsSchema();
describe('valid', () => {
it('should be valid when array of strings', () => {
expectValid(schema, ['test_1', 'test_2']);
});
it('should be valid when array of objects with "id" and "src" keys', () => {
expectValid(schema, [{
id: 'test',
src: 'test',
}]);
});
});
describe('invalid', () => {
it('should be only array of string or objects', () => {
expectInvalid(schema, [1]);
expectInvalid(schema, [true]);
expectInvalid(schema, [[]]);
});
it('should be invalid when empty array', () => {
expectInvalid(schema, []);
});
it('should be invalid when objects do not have required fields', () => {
expectInvalid(schema, [{ src: 'test' }]);
expectInvalid(schema, [{ id: 'test' }]);
});
});
});
});