UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

215 lines (189 loc) 8.99 kB
const Sprint = require('../../../../src/model/classes/sprint.class'); describe('Check [Sprint] class.', () => { const closedToJSON = { id: 120, state: 'closed', name: 'Closed', startDate: '2024-03-07T17:57:09.121Z', endDate: '2024-03-14T17:57:06.000Z', completeDate: '2024-03-27T05:39:12.081Z', createdDate: '2024-03-07T17:44:01.166Z', originBoardId: 1, goal: 'A Goal' }; const closed = { id: 120, state: ' closed ', name: ' Closed ', startDate: new Date('2024-03-07T17:57:09.121Z'), endDate: new Date('2024-03-14T17:57:06.000Z'), completeDate: new Date('2024-03-27T05:39:12.081Z'), createdDate: new Date('2024-03-07T17:44:01.166Z'), originBoardId: 1, goal: ' A Goal ' }; const active = { id: 121, state: 'active', name: 'Active', startDate: new Date('2024-09-28T08:00:17.351Z'), endDate: new Date('2024-10-05T08:00:00.000Z'), createdDate: new Date('2024-09-21T08:57:05.060Z'), originBoardId: 1, goal: 'Active Goal' }; const future = { id: 100, state: 'future', name: 'Future', createdDate: new Date('2024-09-21T08:12:58.234Z'), originBoardId: 1, goal: 'Future Goal' }; const minimalToJSON = { id: 122, state: 'future', name: 'Minimal' }; const minimal = { id: 122, state: 'future', name: 'Minimal' }; const cases = { nominal: [[closed], [active], [future], [minimal]], invalid: [ ['A [id] is mandatory and cannot be falsy.', { name: 'a sprint', state: 'closed' }], ['A [id] MUST be a [integer].', { id: '1', name: 'a sprint', state: 'closed' }], ['The [id] CANNOT be smaller than 0.', { id: -1, name: 'a sprint', state: 'closed' }], ['A [name] is mandatory and cannot be falsy.', { id: 1, state: 'closed' }], ['A [name] MUST be a [string].', { id: 1, name: 2, state: 'closed' }], ['The [name] CANNOT be smaller than 1.', { id: 1, name: ' ', state: 'closed' }], ['A [state] is mandatory and cannot be falsy.', { id: 1, name: 'a sprint' }], ['A [state] MUST be a [string].', { id: 1, name: 'a sprint', state: 2 }], ['The [state] CANNOT be smaller than 1.', { id: 1, name: 'a sprint', state: ' ' }], ['A [start date] MUST implements [Date].', { id: 1, name: 'a sprint', state: 'closed', startDate: 'a' }], ['A [end date] MUST implements [Date].', { id: 1, name: 'a sprint', state: 'closed', endDate: 'a' }], ['A [completed date] MUST implements [Date].', { id: 1, name: 'a sprint', state: 'closed', completeDate: 'a' }], ['A [created date] MUST implements [Date].', { id: 1, name: 'a sprint', state: 'closed', createdDate: 'a' }], ['A [board id] MUST be a [integer].', { id: 1, name: 'a sprint', state: 'closed', originBoardId: 'a' }], ['A [goal] MUST be a [string].', { id: 1, name: 'a sprint', state: 'closed', goal: 2 }] ] }; describe('Check constructor.', () => { it('should reject error when given nothing.', () => { expect(() => new Sprint()).toThrow(); }); it.each(cases.nominal)('should resolve a new instance when init with [%p]', given => { expect(new Sprint(given)).toBeInstanceOf(Sprint); }); it.each(cases.invalid)('should reject [%p] when create from [%p]', (error, given) => { expect(() => new Sprint(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 Sprint(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 Sprint(given).getName()).toBe(given.name.trim()); }); }); describe('Check [state] getter.', () => { it.each(cases.nominal)('should return the given trimmed state when init with [%p]', given => { expect(new Sprint(given).getState()).toBe(given.state ? given.state.trim() : null); }); }); describe('Check [created date] getter.', () => { it.each(cases.nominal)('should return the given created date when init with [%p]', given => { expect(new Sprint(given).getCreatedDate()).toBe(given.createdDate ? given.createdDate : null); }); }); describe('Check [start date] getter.', () => { it.each(cases.nominal)('should return the given start date when init with [%p]', given => { expect(new Sprint(given).getStartDate()).toBe(given.startDate ? given.startDate : null); }); }); describe('Check [end date] getter.', () => { it.each(cases.nominal)('should return the given end date when init with [%p]', given => { expect(new Sprint(given).getEndDate()).toBe(given.endDate ? given.endDate : null); }); }); describe('Check [completed date] getter.', () => { it.each(cases.nominal)('should return the given completed date when init with [%p]', given => { expect(new Sprint(given).getCompleteDate()).toBe(given.completeDate ? given.completeDate : null); }); }); describe('Check [board id] getter.', () => { it.each(cases.nominal)('should return the given board id when init with [%p]', given => { expect(new Sprint(given).getOriginBoardId()).toBe(given.originBoardId ? given.originBoardId : null); }); }); describe('Check [goal] getter.', () => { it.each(cases.nominal)('should return the given trimmed goal when init with [%p]', given => { expect(new Sprint(given).getGoal()).toBe(given.goal ? given.goal.trim() : null); }); }); }); describe('Check utilities.', () => { describe('Check [compare] utility.', () => { it('should return 1 when compare with undefined', () => { expect(new Sprint(closed).compare()).toEqual(1); }); it.each([ [-1, closed, active], [0, closed, closed], [1, active, closed], [1, active, minimal], [0, minimal, minimal] ])('should return [%p] when compare [%p] with [%p]', (expected, first, second) => { expect(new Sprint(first).compare(new Sprint(second))).toEqual(expected); }); }); describe('Check [to string] utility.', () => { it.each(cases.nominal)('should return expected string representation when init with [%p]', given => { expect(`${new Sprint(given)}`).toEqual(`Sprint[${given.name.trim()} #${given.id}]`); }); }); describe('Check [to JSON] utility.', () => { it('should return expected JSON representation when minimal.', () => { expect(new Sprint(minimal).toJSON()).toEqual(minimalToJSON); }); it('should return expected JSON representation when maximal.', () => { expect(new Sprint(closed).toJSON()).toEqual(closedToJSON); }); }); }); describe('Check static utilities.', () => { describe('Check [create] static utility.', () => { it('should reject error when given nothing.', () => { expect(Sprint.create()).rejects.toThrow(); }); it.each(cases.invalid)('should reject [%p] when create from [%p]', (expected, given) => { expect(Sprint.create(given)).rejects.toThrow(expected); }); it.each(cases.nominal)('should resolve new instance when given is [%p].', async given => { expect((await Sprint.create(given)).toJSON()).toEqual(new Sprint(given).toJSON()); }); }); describe('Check [resolve] static utility.', () => { it('should reject when given is falsy.', () => { expect(Sprint.resolve()).rejects.toThrow('A [sprint] is mandatory and cannot be falsy.'); }); it('should reject when given does not implements expected class.', () => { expect(Sprint.resolve(2)).rejects.toThrow('A [sprint] MUST implements [Sprint].'); }); it.each(cases.nominal)('should resolve given when given is initialised with [%p].', given => { const instance = new Sprint(given); expect(Sprint.resolve(instance)).resolves.toBe(instance); }); }); describe('Check [check] static utility.', () => { it('should reject when given is falsy.', () => { expect(() => Sprint.check()).toThrow('A [sprint] is mandatory and cannot be falsy.'); }); it('should reject when given does not implements expected class.', () => { expect(() => Sprint.check(2)).toThrow('A [sprint] MUST implements [Sprint].'); }); it.each(cases.nominal)('should resolve given when given is initialised with [%p].', given => { const instance = new Sprint(given); expect(Sprint.check(instance)).toBe(instance); }); }); }); });