oa-jira
Version:
Octet Agile's JIRA connectivity project.
70 lines (57 loc) • 2.95 kB
JavaScript
const AxiosMock = require('../../../mocks/jira/axios.mock');
const Category = require('../../../../src/model/classes/category.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 [Categories] services', () => {
describe('Check [create] service.', () => {
it('should reject error when given nothing.', () => {
expect(model.categories.create()).rejects.toThrow();
});
it('should delegate to class static utility.', async () => {
const spy = jest.spyOn(Category, 'create').mockResolvedValue('OK');
expect(model.categories.create({ name: 'category' })).resolves.toEqual('OK');
expect(spy).toHaveBeenCalledWith({ name: 'category' });
jest.spyOn(Category, 'create').mockRestore();
});
});
describe('Check [resolve] service.', () => {
it('should delegate to class static utility.', async () => {
const spy = jest.spyOn(Category, 'resolve').mockResolvedValue('OK');
expect(model.categories.resolve('category')).resolves.toEqual('OK');
expect(spy).toHaveBeenCalledWith('category');
jest.spyOn(Category, '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.categories.getById()).rejects.toThrow('A [connection] is mandatory and cannot be falsy.');
});
it('should resolve a category class from jira when no cache given', async () => {
const category = await oaJira.categories.getById({ connection, id: 2 });
expect(category).toBeInstanceOf(Category);
expect(category.getId()).toEqual(2);
expect(mock.getSpy()).toHaveBeenCalled();
});
it('should resolve a category class from jira when nominal', async () => {
await oaJira.categories.getById({ connection, id: 2, cache });
expect(cache.categories.has(2)).toBeTruthy();
expect(mock.getSpy()).toHaveBeenCalledTimes(1);
await oaJira.categories.getById({ connection, id: 2, cache });
expect(mock.getSpy()).toHaveBeenCalledTimes(1);
});
it('should resolve null when not found', async () => {
expect(oaJira.categories.getById({ connection, id: 404, cache })).resolves.toBeNull();
});
it('should reject when fail to retrieve category from jira', async () => {
await expect(oaJira.categories.getById({ connection, id: 500 })).rejects.toThrow(
'Fail to [Get [/rest/api/3/statuscategory/500] (Status 500)]'
);
});
});
});