UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

192 lines (165 loc) 8.37 kB
const Category = require('../../../../src/model/classes/category.class'); const IssueData = require('../../../../src/model/classes/issue.data.class'); const Project = require('../../../../src/model/classes/project.class'); const Resolution = require('../../../../src/model/classes/resolution.class'); const Sprint = require('../../../../src/model/classes/sprint.class'); const Status = require('../../../../src/model/classes/status.class'); const Type = require('../../../../src/model/classes/type.class'); const Version = require('../../../../src/model/classes/version.class'); describe('Check [Issue Data] class.', () => { const updated = new Date('2022-06-02T10:02:02.002Z'); const type = new Type({ id: '1', name: 'n' }); const category = new Category({ id: 1, key: 'k', name: 'category' }); const status = new Status({ id: '1', name: 'n', category }); const project = new Project({ id: '1', name: 'n', key: 'k' }); const resolution = new Resolution({ id: '1', name: 'n' }); const sprint = new Sprint({ id: 1, state: 'f', name: 'n' }); const version = new Version({ id: '10004', name: 'v1' }); const minimal = { summary: 's', updated, type, status, project }; const maximal = { summary: ' s ', updated, type, status, project, resolution, sprint, versions: [version], complexity: 5 }; const cases = { nominal: [[minimal], [maximal]], invalid: [ ['A [summary] is mandatory and cannot be falsy.', { updated, type, status, project }], ['A [summary] MUST be a [string].', { summary: 2, updated, type, status, project }], ['The [summary] CANNOT be smaller than 1.', { summary: ' ', updated, type, status, project }], ['A [updated] is mandatory and cannot be falsy.', { summary: 's', type, status, project }], ['A [updated] MUST implements [Date].', { summary: 's', updated: 'e', type, status, project }], ['A [type] is mandatory and cannot be falsy.', { summary: 's', updated, status, project }], ['A [type] MUST implements [Type].', { summary: 's', updated, type: 2, status, project }], ['A [status] is mandatory and cannot be falsy.', { summary: 's', updated, type, project }], ['A [status] MUST implements [Status].', { summary: 's', updated, type, status: 1, project }], ['A [project] is mandatory and cannot be falsy.', { summary: 's', updated, type, status }], ['A [project] MUST implements [Project].', { summary: 's', updated, type, status, project: 1 }], ['A [complexity] MUST be a [integer].', { summary: 's', updated, type, status, project, complexity: 'XL' }], ['A [resolution] MUST implements [Resolution].', { summary: 's', updated, type, status, project, resolution: 2 }], ['A [sprint] MUST implements [Sprint].', { summary: 's', updated, type, status, project, sprint: 2 }], ['A [version] MUST implements [Version].', { summary: 's', updated, type, status, project, versions: [2] }] ] }; describe('Check constructor.', () => { it('should reject error when given nothing.', () => { expect(() => new IssueData()).toThrow(); }); it.each(cases.nominal)('should resolve a new instance when init with [%p]', given => { expect(new IssueData(given)).toBeInstanceOf(IssueData); }); it.each(cases.invalid)('should reject [%p] when create from [%p]', (error, given) => { expect(() => new IssueData(given)).toThrow(error); }); }); describe('Check getters.', () => { describe('Check [summary] getter.', () => { it.each(cases.nominal)('should return the given summary when init with [%p]', given => { expect(new IssueData(given).getSummary()).toBe(given.summary.trim()); }); }); describe('Check [updated] getter.', () => { it.each(cases.nominal)('should return the given summary when init with [%p]', given => { expect(new IssueData(given).getUpdated()).toBe(given.updated); }); }); describe('Check [type] getter.', () => { it.each(cases.nominal)('should return the given type when init with [%p]', given => { expect(new IssueData(given).getType()).toBe(given.type); }); }); describe('Check [project] getter.', () => { it.each(cases.nominal)('should return the given project when init with [%p]', given => { expect(new IssueData(given).getProject()).toBe(given.project); }); }); describe('Check [status] getter.', () => { it.each(cases.nominal)('should return the given status when init with [%p]', given => { expect(new IssueData(given).getStatus()).toBe(given.status); }); }); describe('Check [complexity] getter.', () => { it.each(cases.nominal)('should return the given complexity when init with [%p]', given => { expect(new IssueData(given).getComplexity()).toBe(given.complexity ? given.complexity : null); }); }); describe('Check [resolution] getter.', () => { it.each(cases.nominal)('should return the given resolution when init with [%p]', given => { expect(new IssueData(given).getResolution()).toBe(given.resolution ? given.resolution : null); }); }); describe('Check [sprint] getter.', () => { it.each(cases.nominal)('should return the given sprint when init with [%p]', given => { expect(new IssueData(given).getSprint()).toBe(given.sprint ? given.sprint : null); }); }); describe('Check [versions] getter.', () => { it('should return the given versions when init with at least one version', () => { expect(new IssueData(maximal).getVersions()[0]).toBe(version); }); it('should return empty array when init with no version', () => { expect(new IssueData(minimal).getVersions()).toEqual([]); }); }); }); describe('Check utilities.', () => { describe('Check [to string] utility.', () => { it.each(cases.nominal)('should return expected string representation when init with [%p]', given => { expect(`${new IssueData(given)}`).toEqual(`Data[${given.summary.trim()} - ${given.updated.toISOString()}]`); }); }); describe('Check [to JSON] utility.', () => { it('should return expected JSON representation when minimal', () => { expect(new IssueData(minimal).toJSON()).toEqual({ summary: 's', type: type.toJSON(), status: status.toJSON(), project: project.toJSON() }); }); it('should return expected JSON representation when maximal', () => { expect(new IssueData(maximal).toJSON()).toEqual({ summary: 's', complexity: 5, type: type.toJSON(), status: status.toJSON(), project: project.toJSON(), resolution: resolution.toJSON(), sprint: sprint.toJSON(), versions: [version.toJSON()] }); }); }); }); describe('Check static utilities.', () => { describe('Check [create] static utility.', () => { it('should reject error when given nothing.', () => { expect(IssueData.create()).rejects.toThrow(); }); it.each(cases.invalid)('should reject [%p] when create from [%p]', (expected, given) => { expect(IssueData.create(given)).rejects.toThrow(expected); }); it.each(cases.nominal)('should resolve new instance when given is [%p].', async given => { expect((await IssueData.create(given)).toJSON()).toEqual(new IssueData(given).toJSON()); }); }); describe('Check [check] static utility.', () => { it('should throw when given is falsy.', () => { expect(() => IssueData.check()).toThrow('A [issue data] is mandatory and cannot be falsy.'); }); it('should throw when given does not implements expected class.', () => { expect(() => IssueData.check(2)).toThrow('A [issue data] MUST implements [IssueData].'); }); it.each(cases.nominal)('should return given when given is initialised with [%p].', given => { const instance = new IssueData(given); expect(IssueData.check(instance)).toBe(instance); }); }); }); });