oa-jira
Version:
Octet Agile's JIRA connectivity project.
56 lines (47 loc) • 2.77 kB
JavaScript
const utils = require('../../../../src/jira/utils/axios.utils');
const AxiosMock = require('../../../mocks/jira/axios.mock');
const axios = require('axios');
describe('Check [axios] utilities', () => {
describe('Check [get] utility', () => {
it('should resolve response data when response status is 200', async () => {
const spyGet = jest.spyOn(axios, 'get').mockResolvedValue({ data: 'OK' });
expect(utils.get('url', { config: true })).resolves.toEqual('OK');
expect(spyGet).toHaveBeenCalledWith('url', { config: true });
});
it('should resolve response data when response status is 200', async () => {
const mock = new AxiosMock().appendGet200('url', 'OK');
expect(utils.get('url', { config: true })).resolves.toEqual('OK');
expect(mock.getSpy()).toHaveBeenCalledWith('url', { config: true });
});
it('should resolve undefined when response status is 404', async () => {
const mock = new AxiosMock().appendGet404('url');
expect(utils.get('url', { config: true })).resolves.toBeUndefined();
expect(mock.getSpy()).toHaveBeenCalledWith('url', { config: true });
});
it('should resolve undefined when resolves nothing', async () => {
const mock = new AxiosMock();
expect(utils.get('url', { config: true })).resolves.toBeUndefined();
expect(mock.getSpy()).toHaveBeenCalledWith('url', { config: true });
});
it('should resolve undefined when resolves nothing', async () => {
const spyGet = jest.spyOn(axios, 'get').mockResolvedValue();
expect(utils.get('url', { config: true })).resolves.toBeUndefined();
expect(spyGet).toHaveBeenCalledWith('url', { config: true });
});
it('should reject fail error when response status is 500', async () => {
const spyGet = jest.spyOn(axios, 'get').mockRejectedValue({ response: { status: 500 } });
expect(utils.get('url', { config: true })).rejects.toThrow('Fail to [Get [url] (Status 500)]');
expect(spyGet).toHaveBeenCalledWith('url', { config: true });
});
it('should reject fail error when an unexpected error is rejected', async () => {
const spyGet = jest.spyOn(axios, 'get').mockRejectedValue('KABOOM');
expect(utils.get('url', { config: true })).rejects.toEqual('KABOOM');
expect(spyGet).toHaveBeenCalledWith('url', { config: true });
});
it('should reject fail error when an unexpected error is rejected', async () => {
const mock = new AxiosMock().appendGet500('url', 'aie');
expect(utils.get('url', { config: true })).rejects.toThrow('Fail to [Get [url] (Status 500)].');
expect(mock.getSpy()).toHaveBeenCalledWith('url', { config: true });
});
});
});