oa-jira
Version:
Octet Agile's JIRA connectivity project.
300 lines (260 loc) • 12.1 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 Issue = require('../../../../src/model/classes/issue.class');
const IssueData = require('../../../../src/model/classes/issue.data.class');
const IssueSnapshots = require('../../../../src/model/classes/issue.snapshots.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');
const Sprint = require('../../../../src/model/classes/sprint.class');
const Resolution = require('../../../../src/model/classes/resolution.class');
const Version = require('../../../../src/model/classes/version.class');
describe('Check [Issue] class.', () => {
const sprint = new Sprint({ id: 1, name: 'n', state: 'closed' });
const sprint2 = 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: sprint, target: sprint2 });
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 complexity = 5;
const resolution = new Resolution({ id: '1', name: 'n' });
const versions = [new Version({ id: '1', name: 'n' })];
const updated = new Date('2022-06-08T15:32:02.002Z');
const soloData = new IssueData({
summary: 'solo',
updated: solo,
type,
status,
project,
complexity,
sprint,
resolution,
versions,
updated
});
const middleData = new IssueData({
summary: 'middle',
updated: middle,
type,
status,
project,
complexity,
sprint,
resolution,
versions,
updated
});
const previousData = new IssueData({
summary: 'previous',
updated: previous,
type,
status,
project,
complexity,
sprint,
resolution,
versions,
updated
});
const nextData = new IssueData({
summary: 'next',
updated: next,
type,
status,
project,
complexity,
sprint: sprint2,
resolution,
versions,
updated
});
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 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 emptySnapshots = new IssueSnapshots(soloCase);
const fulfillSnapshots = new IssueSnapshots(multiCase);
const created = new Date('2022-06-02T10:02:02.002Z');
const resolutiondate = new Date('2022-06-08T15:32:02.002Z');
const minimal = { key: 'key', created, snapshots: emptySnapshots };
const maximal = { key: ' key ', created, resolutiondate, snapshots: fulfillSnapshots };
const cases = {
nominal: [[minimal], [maximal]],
invalid: [
['A [key] is mandatory and cannot be falsy.', { created: new Date(), snapshots: new IssueSnapshots({}) }],
['A [key] MUST be a [string].', { key: 2, created: new Date(), snapshots: new IssueSnapshots({}) }],
['The [key] CANNOT be smaller than 1.', { key: ' ', created: new Date(), snapshots: new IssueSnapshots({}) }],
['A [created] is mandatory and cannot be falsy.', { key: 'key', snapshots: new IssueSnapshots({}) }],
['A [created] MUST implements [Date].', { key: 'key', created: 'a', snapshots: new IssueSnapshots({}) }],
['A [snapshots] MUST implements [Snapshots].', { key: 'key', created: new Date(), snapshots: 2 }]
]
};
describe('Check constructor.', () => {
it('should reject error when given nothing.', () => {
expect(() => new Issue()).toThrow();
});
it.each(cases.nominal)('should resolve a new instance when init with [%p]', given => {
expect(new Issue(given)).toBeInstanceOf(Issue);
});
it.each(cases.invalid)('should reject [%p] when create from [%p]', (error, given) => {
expect(() => new Issue(given)).toThrow(error);
});
});
describe('Check getters.', () => {
describe('Check [key] getter.', () => {
it.each(cases.nominal)('should return the given trimmed key when init with [%p]', given => {
expect(new Issue(given).getKey()).toEqual(given.key.trim());
});
});
describe('Check [created] getter.', () => {
it.each(cases.nominal)('should return the given created when init with [%p]', given => {
expect(new Issue(given).getCreated()).toEqual(given.created);
});
});
describe('Check [resolution date] getter.', () => {
it.each(cases.nominal)('should return the given resolution date when init with [%p]', given => {
expect(new Issue(given).getResolutionDate()).toBe(given.resolutiondate ? given.resolutiondate : null);
});
});
describe('Check [summary] getter.', () => {
it.each(cases.nominal)('should return the summary of the last snapshot when init with [%p]', given => {
expect(new Issue(given).getSummary()).toBe(given.snapshots.getLast().getData().getSummary());
});
});
describe('Check [type] getter.', () => {
it.each(cases.nominal)('should return the type of the last snapshot when init with [%p]', given => {
expect(new Issue(given).getType()).toBe(given.snapshots.getLast().getData().getType());
});
});
describe('Check [complexity] getter.', () => {
it.each(cases.nominal)('should return the complexity of the last snapshot when init with [%p]', given => {
expect(new Issue(given).getComplexity()).toBe(given.snapshots.getLast().getData().getComplexity());
});
});
describe('Check [sprint] getter.', () => {
it.each(cases.nominal)('should return the sprint of the last snapshot when init with [%p]', given => {
expect(new Issue(given).getSprint()).toBe(given.snapshots.getLast().getData().getSprint());
});
});
describe('Check [sprints] getter.', () => {
it('should resolve the sprints in maximal case', () => {
expect(new Issue(maximal).getSprints()).resolves.toEqual([sprint, sprint2]);
});
});
describe('Check [resolution] getter.', () => {
it.each(cases.nominal)('should return the resolution of the last snapshot when init with [%p]', given => {
expect(new Issue(given).getResolution()).toBe(given.snapshots.getLast().getData().getResolution());
});
});
describe('Check [project] getter.', () => {
it.each(cases.nominal)('should return the project of the last snapshot when init with [%p]', given => {
expect(new Issue(given).getProject()).toBe(given.snapshots.getLast().getData().getProject());
});
});
describe('Check [status] getter.', () => {
it.each(cases.nominal)('should return the status of the last snapshot when init with [%p]', given => {
expect(new Issue(given).getStatus()).toBe(given.snapshots.getLast().getData().getStatus());
});
});
describe('Check [versions] getter.', () => {
it.each(cases.nominal)('should return the versions of the last snapshot when init with [%p]', given => {
expect(new Issue(given).getVersions()).toBe(new Issue(given).getLast().getData().getVersions());
});
});
describe('Check [updated date] getter.', () => {
it.each(cases.nominal)('should return the updated date of the last snapshot when init with [%p]', given => {
expect(new Issue(given).getUpdated()).toBe(new Issue(given).getLast().getData().getUpdated());
});
});
describe('Check [snapshots] getter.', () => {
it.each(cases.nominal)('should return the given snapshots when init with [%p]', given => {
expect(new Issue(given).getSnapshots()).toBe(given.snapshots);
});
});
describe('Check [get first] getter.', () => {
it.each(cases.nominal)('should return the first snapshot when init with [%p]', given => {
expect(new Issue(given).getFirst()).toBe(given.snapshots.getFirst());
});
});
describe('Check [get last] getter.', () => {
it.each(cases.nominal)('should return the first snapshot when init with [%p]', given => {
expect(new Issue(given).getLast()).toBe(given.snapshots.getLast());
});
});
});
describe('Check static utilities.', () => {
describe('Check [create] static utility.', () => {
it('should reject error when given nothing.', () => {
expect(Issue.create()).rejects.toThrow();
});
it.each(cases.invalid)('should reject [%p] when create from [%p]', (expected, given) => {
expect(Issue.create(given)).rejects.toThrow(expected);
});
it.each(cases.nominal)('should resolve new instance when given is [%p].', async given => {
expect((await Issue.create(given)).toJSON()).toEqual(new Issue(given).toJSON());
});
});
describe('Check [resolve] static utility.', () => {
it('should reject when given is falsy.', () => {
expect(Issue.resolve()).rejects.toThrow('A [issue] is mandatory and cannot be falsy.');
});
it('should reject when given does not implements expected class.', () => {
expect(Issue.resolve(2)).rejects.toThrow('A [issue] MUST implements [Issue].');
});
it.each(cases.nominal)('should resolve given when given is initialised with [%p].', given => {
const instance = new Issue(given);
expect(Issue.resolve(instance)).resolves.toBe(instance);
});
});
});
});