oa-jira
Version:
Octet Agile's JIRA connectivity project.
213 lines (182 loc) • 9.13 kB
JavaScript
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 IssueSnapshots = require('../../../../src/model/classes/issue.snapshots.class');
const Project = require('../../../../src/model/classes/project.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');
describe('Check [Issue Snapshot] class.', () => {
const sprint122 = new Sprint({ id: 122, state: 'future', name: 'Minimal' });
const sprint120 = new Sprint({
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 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 changeSprint = new Change({ name: ' sprint ', source: sprint122, target: sprint120 });
const changes = new Changes({ changes: [changeComplexity, changeSummary, changeUpdated, changeSprint] });
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 previousISO = previous.toISOString();
const middleISO = middle.toISOString();
const nextISO = next.toISOString();
const soloISO = solo.toISOString();
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, sprint: sprint120 });
const middleData = new IssueData({ summary: 'middle', updated: middle, type, status, project, sprint: sprint120 });
const previousData = new IssueData({
summary: 'previous',
updated: previous,
type,
status,
project,
sprint: sprint122
});
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 emptyCase = {};
const soloCase = { snapshotsData: {} };
soloCase.snapshotsData[soloISO] = { time: solo, data: soloData, changes };
const multiCase = { snapshotsData: {} };
multiCase.snapshotsData[previousISO] = { time: previous, next: middle, data: previousData, changes };
multiCase.snapshotsData[middleISO] = { time: middle, previous, next, data: middleData, changes };
multiCase.snapshotsData[nextISO] = { time: next, previous: middle, data: nextData, changes };
const invalidCase = { snapshotsData: {} };
invalidCase.snapshotsData[soloISO] = { data: soloData, changes };
const emptyJson = { snapshots: {} };
const soloJson = { snapshots: {}, first: soloISO, last: soloISO };
soloJson.snapshots[soloISO] = { time: soloISO, data: soloData.toJSON(), changes: changes.toJSON() };
const multiJson = { snapshots: {}, first: previousISO, last: nextISO };
multiJson.snapshots[previousISO] = {
time: previousISO,
next: middleISO,
data: previousData.toJSON(),
changes: changes.toJSON()
};
multiJson.snapshots[middleISO] = {
time: middleISO,
previous: previousISO,
next: nextISO,
data: middleData.toJSON(),
changes: changes.toJSON()
};
multiJson.snapshots[nextISO] = {
time: nextISO,
previous: middleISO,
data: nextData.toJSON(),
changes: changes.toJSON()
};
const cases = {
nominal: [[emptyCase], [soloCase], [multiCase]],
invalid: [['A [time] is mandatory and cannot be falsy.', invalidCase]]
};
describe('Check constructor.', () => {
it('should resolve empty snapshots when given nothing.', () => {
expect(new IssueSnapshots()).toBeInstanceOf(IssueSnapshots);
});
it.each(cases.nominal)('should resolve a new instance when init with [%p]', given => {
expect(new IssueSnapshots(given)).toBeInstanceOf(IssueSnapshots);
});
it.each(cases.invalid)('should reject [%p] when create from [%p]', (error, given) => {
expect(() => new IssueSnapshots(given)).toThrow(error);
});
});
describe('Check getters.', () => {
describe('Check [get by time] getter.', () => {
it('should return the snapshot associated to its time', () => {
expect(new IssueSnapshots(multiCase).get(middleISO)).toBeInstanceOf(IssueSnapshot);
expect(new IssueSnapshots(multiCase).get(middleISO).getTime()).toEqual(middle);
});
it('should return undefined if not found', () => {
expect(new IssueSnapshots(multiCase).get('toto')).toBeUndefined();
});
});
describe('Check [get first] getter.', () => {
it('should return the snapshot associated to its time', () => {
expect(new IssueSnapshots(multiCase).getFirst()).toBeInstanceOf(IssueSnapshot);
expect(new IssueSnapshots(multiCase).getFirst().getTime()).toEqual(previous);
});
it('should return null if no first exists', () => {
expect(new IssueSnapshots(emptyCase).getFirst()).toBeNull();
});
});
describe('Check [get last] getter.', () => {
it('should return the snapshot associated to its time', () => {
expect(new IssueSnapshots(multiCase).getLast()).toBeInstanceOf(IssueSnapshot);
expect(new IssueSnapshots(multiCase).getLast().getTime()).toEqual(next);
});
it('should return null if no first exists', () => {
expect(new IssueSnapshots(emptyCase).getLast()).toBeNull();
});
});
describe('Check [get sprints] getter.', () => {
it('should resolve an empty arry in empty case', () => {
expect(new IssueSnapshots(emptyCase).getSprints()).resolves.toEqual([]);
});
it('should resolve the sprint associated in solo case', () => {
expect(new IssueSnapshots(soloCase).getSprints()).resolves.toEqual([sprint120]);
});
it('should resolve the sprints associated in multicase', () => {
expect(new IssueSnapshots(multiCase).getSprints()).resolves.toEqual([sprint120, sprint122]);
});
});
});
describe('Check utilities.', () => {
describe('Check [to JSON] utility.', () => {
it('should return expected JSON representation when init with empty case', () => {
expect(new IssueSnapshots(emptyCase).toJSON()).toEqual(emptyJson);
});
it('should return expected JSON representation when init with solo case', () => {
expect(new IssueSnapshots(soloCase).toJSON()).toEqual(soloJson);
});
it('should return expected JSON representation when init with multi case', () => {
expect(new IssueSnapshots(multiCase).toJSON()).toEqual(multiJson);
});
});
});
describe('Check static utilities.', () => {
describe('Check [create] static utility.', () => {
it('should resolve empty snapshots when given nothing.', () => {
expect(IssueSnapshots.create()).resolves.toBeInstanceOf(IssueSnapshots);
});
it.each(cases.nominal)('should resolve a new instance when init with [%p]', given => {
expect(IssueSnapshots.create(given)).resolves.toBeInstanceOf(IssueSnapshots);
});
it.each(cases.invalid)('should reject [%p] when create from [%p]', (error, given) => {
expect(IssueSnapshots.create(given)).rejects.toThrow(error);
});
});
describe('Check [check] static utility.', () => {
it('should throw when given is falsy.', () => {
expect(() => IssueSnapshots.check()).toThrow('A [snapshots] is mandatory and cannot be falsy.');
});
it('should throw when given does not implements expected class.', () => {
expect(() => IssueSnapshots.check(2)).toThrow('A [snapshots] MUST implements [Snapshots].');
});
it.each(cases.nominal)('should return given when given is initialised with [%p].', given => {
const instance = new IssueSnapshots(given);
expect(IssueSnapshots.check(instance)).toBe(instance);
});
});
});
});