oa-jira
Version:
Octet Agile's JIRA connectivity project.
143 lines (118 loc) • 6.05 kB
JavaScript
const BoardColumn = require('../../../../src/model/classes/board.column.class');
describe('Check [Board Column] class.', () => {
const minimal = { name: 'n', order: 1 };
const maximal = { name: ' n ', order: 2, min: 1, max: 10, statusIds: [' 10000 ', ' 10001 '] };
const cases = {
nominal: [[minimal], [maximal]],
invalid: [
['A [name] is mandatory and cannot be falsy.', { order: 1 }],
['A [name] MUST be a [string].', { name: 2, order: 1 }],
['The [name] CANNOT be smaller than 1.', { name: ' ', order: 1 }],
['A [order] is mandatory and cannot be falsy.', { name: 'n' }],
['A [order] MUST be a [integer].', { name: 'n', order: '1' }],
['A [min] MUST be a [integer].', { name: 'n', order: 1, min: 'a' }],
['A [max] MUST be a [integer].', { name: 'n', order: 1, max: 'b' }],
['A [status id] is mandatory and cannot be falsy.', { name: 'n', order: 1, statusIds: [undefined] }],
['A [status id] MUST be a [string].', { name: 'n', order: 1, statusIds: [10000] }],
['The [status id] CANNOT be smaller than 1.', { name: 'n', order: 1, statusIds: [' '] }]
]
};
const minJSON = { name: 'n', order: 1 };
const maxJSON = { name: 'n', order: 2, min: 1, max: 10, statusIds: ['10000', '10001'] };
describe('Check constructor.', () => {
it('should reject error when given nothing.', () => {
expect(() => new BoardColumn()).toThrow();
});
it.each(cases.nominal)('should resolve a new instance when init with [%p]', given => {
expect(new BoardColumn(given)).toBeInstanceOf(BoardColumn);
});
it.each(cases.invalid)('should reject [%p] when create from [%p]', (error, given) => {
expect(() => new BoardColumn(given)).toThrow(error);
});
});
describe('Check getters.', () => {
describe('Check [name] getter.', () => {
it.each(cases.nominal)('should return the given trimmed name when init with [%p]', given => {
expect(new BoardColumn(given).getName()).toBe(given.name.trim());
});
});
describe('Check [order] getter.', () => {
it.each(cases.nominal)('should return the given id when init with [%p]', given => {
expect(new BoardColumn(given).getOrder()).toBe(given.order);
});
});
describe('Check [min] getter.', () => {
it.each(cases.nominal)('should return the given min when init with [%p]', given => {
expect(new BoardColumn(given).getMin()).toBe(given.min ? given.min : null);
});
});
describe('Check [max] getter.', () => {
it.each(cases.nominal)('should return the given max when init with [%p]', given => {
expect(new BoardColumn(given).getMax()).toBe(given.max ? given.max : null);
});
});
describe('Check [status ids] getter.', () => {
it('should return the empty array when no ids given', () => {
expect(new BoardColumn(minimal).getStatusIds()).toEqual([]);
});
it('should return the array of ids when no ids are given', () => {
expect(new BoardColumn(maximal).getStatusIds()).toEqual(['10000', '10001']);
});
});
});
describe('Check utilities.', () => {
describe('Check [to string] utility.', () => {
it.each(cases.nominal)('should return expected string representation when init with [%p]', given => {
expect(`${new BoardColumn(given)}`).toEqual(`Column[${given.name.trim()} #${given.order}]`);
});
});
describe('Check [to JSON] utility.', () => {
it('should return expected JSON representation when minimal', () => {
expect(new BoardColumn(minimal).toJSON()).toEqual(minJSON);
});
it('should return expected JSON representation when maximal', () => {
expect(new BoardColumn(maximal).toJSON()).toEqual(maxJSON);
});
});
});
describe('Check static utilities.', () => {
describe('Check [create] static utility.', () => {
it('should reject error when given nothing.', () => {
expect(BoardColumn.create()).rejects.toThrow();
});
it.each(cases.invalid)('should reject [%p] when create from [%p]', (expected, given) => {
expect(BoardColumn.create(given)).rejects.toThrow(expected);
});
it.each(cases.nominal)('should resolve new instance when given is [%p].', async given => {
expect((await BoardColumn.create(given)).toJSON()).toEqual(new BoardColumn(given).toJSON());
});
});
describe('Check [check] static utility.', () => {
it('should throw when given is falsy.', () => {
expect(() => BoardColumn.check()).toThrow('A [column] is mandatory and cannot be falsy.');
});
it('should reject when given does not implements expected class.', () => {
expect(() => BoardColumn.check(2)).toThrow('A [column] MUST implements [BoardColumn].');
});
it.each(cases.nominal)('should resolve given when given is initialised with [%p].', given => {
const instance = new BoardColumn(given);
expect(BoardColumn.check(instance)).toBe(instance);
});
});
describe('Check [check bulk] static utility.', () => {
it('should throw when given is missing.', () => {
expect(() => BoardColumn.checkBulk()).toThrow('A [bulk of columns] MUST be a [array].');
});
it('should throw when given is not an array.', () => {
expect(() => BoardColumn.checkBulk('Kaboom !')).toThrow('A [bulk of columns] MUST be a [array].');
});
it('should throw when given is an array wich contains invalid.', () => {
expect(() => BoardColumn.checkBulk([2])).toThrow('A [column] MUST implements [BoardColumn].');
});
it('should return given when given is an array of changes.', () => {
const columns = [new BoardColumn(minimal), new BoardColumn(maximal)];
expect(BoardColumn.checkBulk(columns)).toEqual(columns);
});
});
});
});