Skip to content

Commit

Permalink
test(uberconfig): add tests for validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiphe committed Mar 5, 2016
1 parent c6c16f2 commit 92f031d
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions test/plugins/uberconfig/validationsSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';

const validations = require('../../../lib/plugins/uberconfig/validations');

function applyValidations(toolbox) {
validations.forEach((validation) => {
validation(toolbox);
});
}

describe('validations', () => {
let validToolbox = null;

beforeEach(() => {
validToolbox = {
meta: {
name: 'foo',
bugs: 'none',
},
};
});

it('are an array of functions', () => {
expect(validations instanceof Array).toBe(true);
expect(typeof validations[0]).toBe('function');
});

it('pass with valid toolbox', () => {
expect(() => applyValidations(validToolbox)).not.toThrow();
});

it('fail when toolbox does not have a meta property', () => {
delete validToolbox.meta;
expect(() => applyValidations(validToolbox)).toThrow();
});

it('fail when toolbox does not have a meta.name property', () => {
delete validToolbox.meta.name;
expect(() => applyValidations(validToolbox)).toThrow();
});

it('fail when toolbox does not have a meta.bugs property', () => {
delete validToolbox.meta.bugs;
expect(() => applyValidations(validToolbox)).toThrow();
});

it('fail when toolbox meta.bugs property is not a string', () => {
validToolbox.meta.bugs = {};
expect(() => applyValidations(validToolbox)).toThrow();
});

it('fail when toolbox meta.bugs.url property is not a string', () => {
validToolbox.meta.bugs = { url: 70 };
expect(() => applyValidations(validToolbox)).toThrow();
});

it('pass when toolbox meta.bugs.url property is a string', () => {
validToolbox.meta.bugs = { url: 'here' };
expect(() => applyValidations(validToolbox)).not.toThrow();
});
});

0 comments on commit 92f031d

Please sign in to comment.