UNPKG

oa-jira

Version:

Octet Agile's JIRA connectivity project.

85 lines (71 loc) 3.68 kB
const AxiosMock = require('../../../mocks/jira/axios.mock'); const Board = require('../../../../src/model/classes/board.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 [Board] services', () => { describe('Check [create] service.', () => { it('should reject error when given nothing.', () => { expect(model.boards.create()).rejects.toThrow(); }); it('should delegate to class static utility.', async () => { const spy = jest.spyOn(Board, 'create').mockResolvedValue('OK'); expect(model.boards.create({ name: 'board' })).resolves.toEqual('OK'); expect(spy).toHaveBeenCalledWith({ name: 'board' }); jest.spyOn(Board, 'create').mockRestore(); }); }); describe('Check [resolve] service.', () => { it('should delegate to class static utility.', async () => { const spy = jest.spyOn(Board, 'resolve').mockResolvedValue('OK'); expect(model.boards.resolve('board')).resolves.toEqual('OK'); expect(spy).toHaveBeenCalledWith('board'); jest.spyOn(Board, 'resolve').mockRestore(); }); }); describe('Check [get by id] service', () => { const connection = new Connection({ mode: 'Bearer', baseUrl: 'localhost', token: 'TOKEN' }); const cache = new Cache(); const mock = AxiosMock.init(); afterEach(() => mock.reset()); it('should reject when given nothing', async () => { expect(oaJira.boards.getById()).rejects.toThrow('A [connection] is mandatory and cannot be falsy.'); }); it('should resolve a board class from jira when no cache given', async () => { const board1 = await oaJira.boards.getById({ connection, id: 1 }); expect(board1).toBeInstanceOf(Board); expect(board1.getId()).toEqual(1); expect(mock.getSpy()).toHaveBeenCalledTimes(1); const board2 = await oaJira.boards.getById({ connection, id: 2 }); expect(board2).toBeInstanceOf(Board); expect(board2.getId()).toEqual(2); expect(mock.getSpy()).toHaveBeenCalledTimes(2); const board3 = await oaJira.boards.getById({ connection, id: 3 }); expect(board3).toBeInstanceOf(Board); expect(board3.getId()).toEqual(3); expect(mock.getSpy()).toHaveBeenCalledTimes(3); }); it('should resolve a board class from jira when cache is given', async () => { const board1 = await oaJira.boards.getById({ connection, cache, id: 1 }); expect(board1).toBeInstanceOf(Board); expect(board1.getId()).toEqual(1); expect(mock.getSpy()).toHaveBeenCalledTimes(1); const board2 = await oaJira.boards.getById({ connection, cache, id: 1 }); expect(board2).toBeInstanceOf(Board); expect(board2.getId()).toEqual(1); expect(mock.getSpy()).toHaveBeenCalledTimes(1); }); it('should resolve null when not found', async () => { expect(oaJira.boards.getById({ connection, id: 404, cache })).resolves.toBeNull(); }); it('should reject when board retrieved from jira is toxic', async () => { await expect(oaJira.boards.getById({ connection, id: 501 })).rejects.toThrow('A [status id] MUST be a [string].'); }); it('should reject when fail to retrieve board from jira', async () => { await expect(oaJira.boards.getById({ connection, id: 500 })).rejects.toThrow( 'Fail to [Get [/rest/agile/1.0/board/500/configuration] (Status 500)]' ); }); }); });