UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

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