UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

139 lines (114 loc) 5.93 kB
const Board = require('../../../../src/model/classes/board.class'); const BoardColumn = require('../../../../src/model/classes/board.column.class'); describe('Check [Board] class.', () => { const minColumn = new BoardColumn({ name: 'n', order: 1 }); const maxColumn = new BoardColumn({ name: ' n ', order: 2, min: 1, max: 10, statusIds: [' 10000 ', ' 10001 '] }); const minimal = { id: 1, name: 'n', projectId: '2' }; const maximal = { id: 1, name: ' n ', projectId: ' 2 ', columns: [minColumn, maxColumn] }; const cases = { nominal: [[minimal], [maximal]], invalid: [ ['A [id] is mandatory and cannot be falsy.', { name: 'n', projectId: '2' }], ['A [id] MUST be a [integer].', { id: '1', name: 'n', projectId: '2' }], ['The [id] CANNOT be smaller than 0.', { id: -1, name: 'n', projectId: '2' }], ['A [name] is mandatory and cannot be falsy.', { id: 1, projectId: '2' }], ['A [name] MUST be a [string].', { id: 1, name: 2, projectId: '2' }], ['The [name] CANNOT be smaller than 1.', { id: 1, name: ' ', projectId: '2' }], ['A [project id] is mandatory and cannot be falsy.', { id: 1, name: 'n' }], ['A [project id] MUST be a [string].', { id: 1, name: 'n', projectId: 2 }], ['The [project id] CANNOT be smaller than 1.', { id: 1, name: 'n', projectId: ' ' }], ['A [column] is mandatory and cannot be falsy.', { id: 1, name: 'n', projectId: '2', columns: [null] }], ['A [column] MUST implements [BoardColumn].', { id: 1, name: 'n', projectId: '2', columns: [2] }] ] }; const minJSON = { id: 1, name: 'n', projectId: '2' }; const maxJSON = { id: 1, name: 'n', projectId: '2', columns: { 1: minColumn.toJSON(), 2: maxColumn.toJSON() } }; describe('Check constructor.', () => { it('should reject error when given nothing.', () => { expect(() => new Board()).toThrow(); }); it.each(cases.nominal)('should resolve a new instance when init with [%p]', given => { expect(new Board(given)).toBeInstanceOf(Board); }); it.each(cases.invalid)('should reject [%p] when create from [%p]', (error, given) => { expect(() => new Board(given)).toThrow(error); }); }); describe('Check getters.', () => { describe('Check [id] getter.', () => { it.each(cases.nominal)('should return the given id when init with [%p]', given => { expect(new Board(given).getId()).toBe(given.id); }); }); describe('Check [name] getter.', () => { it.each(cases.nominal)('should return the given trimmed name when init with [%p]', given => { expect(new Board(given).getName()).toBe(given.name.trim()); }); }); describe('Check [project id] getter.', () => { it.each(cases.nominal)('should return the given min when init with [%p]', given => { expect(new Board(given).getProjectId()).toBe(given.projectId.trim()); }); }); describe('Check [columns] getter.', () => { it('should return the empty array when no ids given', () => { expect(new Board(minimal).getColumns()).toEqual([]); }); it('should return the array of ids when no ids are given', () => { expect(new Board(maximal).getColumns()).toEqual([minColumn, maxColumn]); }); }); }); describe('Check utilities.', () => { describe('Check [to string] utility.', () => { it.each(cases.nominal)('should return expected string representation when init with [%p]', given => { expect(`${new Board(given)}`).toEqual(`Board[${given.name.trim()} #${given.id}]`); }); }); describe('Check [to JSON] utility.', () => { it('should return expected JSON representation when minimal', () => { expect(new Board(minimal).toJSON()).toEqual(minJSON); }); it('should return expected JSON representation when maximal', () => { expect(new Board(maximal).toJSON()).toEqual(maxJSON); }); }); }); describe('Check static utilities.', () => { describe('Check [create] static utility.', () => { it('should reject error when given nothing.', () => { expect(Board.create()).rejects.toThrow(); }); it.each(cases.invalid)('should reject [%p] when create from [%p]', (expected, given) => { expect(Board.create(given)).rejects.toThrow(expected); }); it.each(cases.nominal)('should resolve new instance when given is [%p].', async given => { expect((await Board.create(given)).toJSON()).toEqual(new Board(given).toJSON()); }); }); describe('Check [check] static utility.', () => { it('should throw when given is falsy.', () => { expect(() => Board.check()).toThrow('A [board] is mandatory and cannot be falsy.'); }); it('should reject when given does not implements expected class.', () => { expect(() => Board.check(2)).toThrow('A [board] MUST implements [Board].'); }); it.each(cases.nominal)('should return given when given is initialised with [%p].', given => { const instance = new Board(given); expect(Board.check(instance)).toBe(instance); }); }); describe('Check [resolve] static utility.', () => { it('should rejects when given is falsy.', () => { expect(Board.resolve()).rejects.toThrow('A [board] is mandatory and cannot be falsy.'); }); it('should rejects when given does not implements expected class.', () => { expect(Board.resolve(2)).rejects.toThrow('A [board] MUST implements [Board].'); }); it.each(cases.nominal)('should resolve given when given is initialised with [%p].', given => { const instance = new Board(given); expect(Board.resolve(instance)).resolves.toBe(instance); }); }); }); });