UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

73 lines (60 loc) 3.19 kB
const AxiosMock = require('../../../mocks/jira/axios.mock'); const Resolution = require('../../../../src/model/classes/resolution.class'); const model = require('../../../../src/model'); const oaJira = require('../../../../'); const Connection = require('../../../../src/connection/classes/connection.class'); const Cache = require('../../../../src/cache/classes/cache.class'); describe('Check [Resolutions] 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.resolutions.create()).rejects.toThrow(); }); it('should delegate to class static utility.', async () => { const spy = jest.spyOn(Resolution, 'create').mockResolvedValue('OK'); expect(model.resolutions.create({ name: 'resolution' })).resolves.toEqual('OK'); expect(spy).toHaveBeenCalledWith({ name: 'resolution' }); jest.spyOn(Resolution, 'create').mockRestore(); }); }); describe('Check [resolve] service.', () => { it('should delegate to class static utility.', async () => { const spy = jest.spyOn(Resolution, 'resolve').mockResolvedValue('OK'); expect(model.resolutions.resolve('resolution')).resolves.toEqual('OK'); expect(spy).toHaveBeenCalledWith('resolution'); jest.spyOn(Resolution, 'resolve').mockRestore(); }); }); describe('Check [get by id] service', () => { const mock = AxiosMock.init(); afterEach(() => mock.reset()); it('should reject when given nothing', async () => { expect(oaJira.resolutions.getById()).rejects.toThrow('A [connection] is mandatory and cannot be falsy.'); }); it('should resolve a resolution class from jira when no cache given', async () => { const resolution = await oaJira.resolutions.getById({ connection, id: '10000' }); expect(resolution).toBeInstanceOf(Resolution); expect(resolution.getId()).toEqual('10000'); expect(mock.getSpy()).toHaveBeenCalledTimes(1); }); it('should resolve a resolution class from jira when nominal', async () => { await model.resolutions.getById({ connection, id: '10000', cache }); expect(cache.resolutions.has('10000')).toBeTruthy(); expect(mock.getSpy()).toHaveBeenCalledTimes(1); const resolution = await oaJira.resolutions.getById({ connection, id: '10000', cache }); expect(mock.getSpy()).toHaveBeenCalledTimes(1); expect(resolution).toBeInstanceOf(Resolution); expect(resolution.getId()).toEqual('10000'); }); it('should resolve null when not found', async () => { expect(oaJira.resolutions.getById({ connection, id: '404', cache })).resolves.toBeNull(); }); it('should reject when fail to retrieve resolution from jira', async () => { await expect(oaJira.resolutions.getById({ connection, id: '500' })).rejects.toThrow( 'Fail to [Get [/rest/api/3/resolution/500] (Status 500)]' ); }); }); });