UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

134 lines (113 loc) 6.36 kB
const Category = require('../../../../src/model/classes/category.class'); const Change = require('../../../../src/model/classes/change.class'); const Changes = require('../../../../src/model/classes/changes.class'); const IssueData = require('../../../../src/model/classes/issue.data.class'); const IssueSnapshot = require('../../../../src/model/classes/issue.snapshot.class'); const Project = require('../../../../src/model/classes/project.class'); const Status = require('../../../../src/model/classes/status.class'); const Type = require('../../../../src/model/classes/type.class'); describe('Check [Issue Snapshot] class.', () => { const changeComplexity = new Change({ name: ' complexity ', source: 'source', target: 'target' }); const changeSummary = new Change({ name: ' summary ', target: 'target' }); const changeUpdated = new Change({ name: ' updated ', source: 'source' }); const changes = new Changes({ changes: [changeComplexity, changeSummary, changeUpdated] }); const previous = new Date('2022-06-01T10:02:02.002Z'); const middle = new Date('2022-06-02T10:02:02.002Z'); const next = new Date('2022-06-03T10:02:02.002Z'); const solo = new Date('2022-06-04T10: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 soloData = new IssueData({ summary: 'solo', updated: solo, type, status, project }); const middleData = new IssueData({ summary: 'middle', updated: middle, type, status, project }); const previousData = new IssueData({ summary: 'previous', updated: previous, type, status, project }); const nextData = new IssueData({ summary: 'next', updated: next, type, status, project }); const dataSet = {}; dataSet[solo.toISOString()] = soloData; dataSet[previous.toISOString()] = previousData; dataSet[middle.toISOString()] = middleData; dataSet[next.toISOString()] = nextData; const mockSnapshotsMiddle = { get: time => dataSet[time] }; const soloCase = { time: solo, previous: undefined, next: undefined, data: soloData, changes }; const previousCase = { time: previous, previous: undefined, next: middle, data: previousData, changes }; const middleCase = { time: middle, previous: previous, next: next, data: middleData, changes }; const nextCase = { time: next, previous: middle, next: undefined, data: nextData, changes }; const soloJson = { time: solo.toISOString(), data: soloData.toJSON(), changes: changes.toJSON() }; const middleJson = { time: middle.toISOString(), data: middleData.toJSON(), changes: changes.toJSON(), previous: previous.toISOString(), next: next.toISOString() }; const cases = { nominal: [[soloCase], [previousCase], [middleCase], [nextCase]], invalid: [ ['A [time] is mandatory and cannot be falsy.', { previous: undefined, next: undefined, data: soloData, changes }], ['A [time] MUST implements [Date].', { time: 2, previous: undefined, next: undefined, data: soloData, changes }], ['A [changes] is mandatory and cannot be falsy.', { time: solo, data: soloData }], ['A [changes] MUST implements [Changes].', { time: solo, data: soloData, changes: 2 }], ['A [issue data] is mandatory and cannot be falsy.', { time: solo, changes }], ['A [issue data] MUST implements [IssueData].', { time: solo, data: 2, changes }], ['A [previous] MUST implements [Date].', { time: solo, previous: 2, data: soloData, changes }], ['A [next] MUST implements [Date].', { time: solo, next: 2, data: soloData, changes }] ] }; describe('Check constructor.', () => { it('should reject error when given nothing.', () => { expect(() => new IssueSnapshot()).toThrow(); }); it.each(cases.nominal)('should resolve a new instance when init with [%p]', given => { expect(new IssueSnapshot(mockSnapshotsMiddle, given)).toBeInstanceOf(IssueSnapshot); }); it.each(cases.invalid)('should reject [%p] when create from [%p]', (error, given) => { expect(() => new IssueSnapshot(mockSnapshotsMiddle, given)).toThrow(error); }); }); describe('Check getters.', () => { describe('Check [previous] getter.', () => { it.each(cases.nominal)('should return the given previous when init with [%p]', given => { expect(new IssueSnapshot(mockSnapshotsMiddle, given).getPrevious()).toBe( given.previous ? dataSet[given.previous.toISOString()] : null ); }); }); describe('Check [time] getter.', () => { it.each(cases.nominal)('should return the given previous when init with [%p]', given => { expect(new IssueSnapshot(mockSnapshotsMiddle, given).getTime()).toBe(given.time); }); }); describe('Check [next] getter.', () => { it.each(cases.nominal)('should return the given next when init with [%p]', given => { expect(new IssueSnapshot(mockSnapshotsMiddle, given).getNext()).toBe( given.next ? dataSet[given.next.toISOString()] : null ); }); }); describe('Check [changes] getter.', () => { it.each(cases.nominal)('should return the given changes when init with [%p]', given => { expect(new IssueSnapshot(mockSnapshotsMiddle, given).getChanges().toJSON()).toEqual(changes.toJSON()); }); }); describe('Check [data] getter.', () => { it.each(cases.nominal)('should return the given data when init with [%p]', given => { expect(new IssueSnapshot(mockSnapshotsMiddle, given).getData().toJSON()).toEqual(given.data.toJSON()); }); }); }); describe('Check utilities.', () => { describe('Check [to JSON] utility.', () => { it('should return expected JSON representation when init with solo case', () => { expect(new IssueSnapshot(mockSnapshotsMiddle, soloCase).toJSON()).toEqual(soloJson); }); it('should return expected JSON representation when init with middle case', () => { expect(new IssueSnapshot(mockSnapshotsMiddle, middleCase).toJSON()).toEqual(middleJson); }); }); }); });