UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

121 lines (101 loc) 5.27 kB
const Category = require('../../../../src/model/classes/category.class'); const Status = require('../../../../src/model/classes/status.class'); describe('Check [Status] class.', () => { const category = new Category({ id: 1, key: 'k', name: 'category' }); const maximal = { id: ' 1 ', name: ' n ', description: ' d ', iconUrl: ' i ', category }; const minimal = { id: '1', name: 'n', category }; const maximalToJSON = { id: '1', name: 'n', description: 'd', iconUrl: 'i', category: category.toJSON() }; const minimalToJSON = { id: '1', name: 'n', category: category.toJSON() }; const cases = { nominal: [[maximal], [minimal]], invalid: [ ['A [id] is mandatory and cannot be falsy.', { name: 'name', category }], ['A [id] MUST be a [string].', { id: 1, name: 'name', category }], ['The [id] CANNOT be smaller than 1.', { id: ' ', name: 'name', category }], ['A [name] is mandatory and cannot be falsy.', { id: '10000', category }], ['A [name] MUST be a [string].', { id: '10000', name: 2, category }], ['The [name] CANNOT be smaller than 1.', { id: '10000', name: ' ', category }], ['A [description] MUST be a [string].', { id: '1', name: 'name', description: 2, category }], ['A [icon Url] MUST be a [string].', { id: '1', name: 'name', iconUrl: 2, category }], ['A [category] is mandatory and cannot be falsy.', { id: '10000', name: 'name' }] ] }; describe('Check constructor.', () => { it('should reject error when given nothing.', () => { expect(() => new Status()).toThrow(); }); it.each(cases.nominal)('should resolve a new instance when init with [%p]', given => { expect(new Status(given)).toBeInstanceOf(Status); }); it.each(cases.invalid)('should reject [%p] when create from [%p]', (error, given) => { expect(() => new Status(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 Status(given).getId()).toEqual(given.id.trim()); }); }); describe('Check [name] getter.', () => { it.each(cases.nominal)('should return the given trimmed name when init with [%p]', given => { expect(new Status(given).getName()).toEqual(given.name.trim()); }); }); describe('Check [description] getter.', () => { it.each(cases.nominal)('should return the given trimmed description when init with [%p]', given => { expect(new Status(given).getDescription()).toEqual(given.description ? given.description.trim() : null); }); }); describe('Check [icon Url] getter.', () => { it.each(cases.nominal)('should return the given trimmed icon url when init with [%p]', given => { expect(new Status(given).getIconUrl()).toEqual(given.iconUrl ? given.iconUrl.trim() : null); }); }); describe('Check [category] getter.', () => { it.each(cases.nominal)('should return the given category when init with [%p]', given => { expect(new Status(given).getCategory().toJSON()).toEqual(given.category.toJSON()); }); }); }); describe('Check utilities.', () => { describe('Check [to string] utility.', () => { it.each(cases.nominal)('should return expected string representation when init with [%p]', given => { expect(`${new Status(given)}`).toEqual(`Status[${given.name.trim()} #${given.id.trim()}]`); }); }); describe('Check [to JSON] utility.', () => { it('should return expected JSON representation when minimal', () => { expect(new Status(minimal).toJSON()).toEqual(minimalToJSON); }); it('should return expected JSON representation when maximal', () => { expect(new Status(maximal).toJSON()).toEqual(maximalToJSON); }); }); }); describe('Check static utilities.', () => { describe('Check [create] static utility.', () => { it('should reject error when given nothing.', () => { expect(Status.create()).rejects.toThrow(); }); it.each(cases.invalid)('should reject [%p] when create from [%p]', (expected, given) => { expect(Status.create(given)).rejects.toThrow(expected); }); it.each(cases.nominal)('should resolve new instance when given is [%p].', async given => { expect((await Status.create(given)).toJSON()).toEqual(new Status(given).toJSON()); }); }); describe('Check [resolve] static utility.', () => { it('should reject when given is falsy.', () => { expect(Status.resolve()).rejects.toThrow('A [status] is mandatory and cannot be falsy.'); }); it('should reject when given does not implements expected class.', () => { expect(Status.resolve(2)).rejects.toThrow('A [status] MUST implements [Status].'); }); it.each(cases.nominal)('should resolve given when given is initialised with [%p].', given => { const instance = new Status(given); expect(Status.resolve(instance)).resolves.toBe(instance); }); }); }); });