UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

77 lines (63 loc) 3.23 kB
const AxiosMock = require('../../../mocks/jira/axios.mock'); const model = require('../../../../src/model'); const oaJira = require('../../../../'); const Status = require('../../../../src/model/classes/status.class'); const Connection = require('../../../../src/connection/classes/connection.class'); const Cache = require('../../../../src/cache/classes/cache.class'); describe('Check [Statuses] services', () => { const connection = new Connection({ mode: 'Bearer', baseUrl: 'localhost', token: 'TOKEN' }); const cache = new Cache(); beforeEach(() => cache.reset()); describe('Check [create] service.', () => { it('should reject error when given nothing.', () => { expect(model.statuses.create()).rejects.toThrow(); }); it('should delegate to class static utility.', async () => { const spy = jest.spyOn(Status, 'create').mockResolvedValue('OK'); expect(model.statuses.create({ name: 'type' })).resolves.toEqual('OK'); expect(spy).toHaveBeenCalledWith({ name: 'type' }); jest.spyOn(Status, 'create').mockRestore(); }); }); describe('Check [resolve] service.', () => { it('should delegate to class static utility.', async () => { const spy = jest.spyOn(Status, 'resolve').mockResolvedValue('OK'); expect(model.statuses.resolve('type')).resolves.toEqual('OK'); expect(spy).toHaveBeenCalledWith('type'); jest.spyOn(Status, 'resolve').mockRestore(); }); }); describe('Check [get by id] service', () => { const mock = AxiosMock.init(); afterEach(() => mock.reset()); it('should reject when given nothing', async () => { expect(oaJira.statuses.getById()).rejects.toThrow('A [connection] is mandatory and cannot be falsy.'); }); it('should resolve a status class from jira when no cache given', async () => { const status = await oaJira.statuses.getById({ connection, id: '10000' }); expect(status).toBeInstanceOf(Status); expect(status.getId()).toEqual('10000'); expect(mock.getSpy()).toHaveBeenCalledTimes(1); }); it('should resolve a status class from jira when cache is given', async () => { expect(mock.getSpy()).toHaveBeenCalledTimes(0); await oaJira.statuses.getById({ connection, id: '10000', cache }); expect(cache.statuses.has('10000')).toBeTruthy(); expect(cache.categories.has(2)).toBeTruthy(); expect(mock.getSpy()).toHaveBeenCalledTimes(1); await oaJira.statuses.getById({ connection, id: '10000', cache }); expect(mock.getSpy()).toHaveBeenCalledTimes(1); }); it('should resolve null when not found', () => { expect(oaJira.statuses.getById({ connection, id: '404', cache })).resolves.toBeNull(); }); it('should reject when fail to retrieve status from jira', () => { expect(oaJira.statuses.getById({ connection, id: '500' })).rejects.toThrow( 'Fail to [Get [/rest/api/3/status/500] (Status 500)]' ); }); it('should reject when category is not valid', () => { expect(oaJira.statuses.getById({ connection, id: '16661' })).rejects.toThrow('A [id] MUST be a [integer].'); }); }); });