oa-jira
Version:
Octet Agile's JIRA connectivity project.
131 lines (119 loc) • 6.23 kB
JavaScript
const axios = require('axios');
const oaJira = require('../../../../');
const services = require('../../../../src/jira/services/jira.services');
const constants = require('../../../../src/jira/constants/jira.constants');
const Connection = require('../../../../src/connection/classes/connection.class');
describe('Check [jira] services', () => {
const connection = new Connection({ mode: 'Bearer', baseUrl: 'localhost', token: 'TOKEN' });
describe('Check [get Board By Id] service', () => {
it('should resolve response data when nominal', () => {
const spyGet = jest.spyOn(axios, 'get').mockResolvedValue({ data: 'board' });
expect(services.getBoardById(connection, 4)).resolves.toEqual('board');
expect(spyGet).toHaveBeenCalledWith(`/rest/agile/1.0/board/4/configuration`, {
baseURL: connection.getBaseUrl(),
headers: { Authorization: connection.buildAuthorization(), ...constants.headers }
});
});
});
describe('Check [get Category By Id] service', () => {
it('should resolve response data when nominal', () => {
const spyGet = jest.spyOn(axios, 'get').mockResolvedValue({ data: 'category' });
expect(services.getCategoryById(connection, 2)).resolves.toEqual('category');
expect(spyGet).toHaveBeenCalledWith(`/rest/api/3/statuscategory/2`, {
baseURL: connection.getBaseUrl(),
headers: { Authorization: connection.buildAuthorization(), ...constants.headers }
});
});
});
describe('Check [get Issue By Key] service', () => {
it('should resolve response data when nominal', () => {
const spyGet = jest.spyOn(axios, 'get').mockResolvedValue({ data: 'issue' });
expect(services.getIssueByKey(connection, 'KEY-001')).resolves.toEqual('issue');
expect(spyGet).toHaveBeenCalledWith(`/rest/api/3/issue/KEY-001`, {
baseURL: connection.getBaseUrl(),
headers: { Authorization: connection.buildAuthorization(), ...constants.headers },
params: { ...constants.params.issues }
});
});
});
describe('Check [get Issues By Board Id] service', () => {
it.each([
[2, 4, 2, 4],
[0, 100, 'a', 'b'],
[0, 100, null, null],
[0, 100, -1, 0],
[4, 100, 4, 1001]
])(
'should resolve response data with start set to [%p] and maxResults to [%p] when given offset is [%p] and size is [%p].',
(startAt, maxResults, offset, size) => {
const spyGet = jest.spyOn(axios, 'get').mockResolvedValue({ data: 'issues' });
expect(services.getIssuesByBoardId(connection, 42, offset, size)).resolves.toEqual('issues');
expect(spyGet).toHaveBeenCalledWith(`/rest/agile/1.0/board/42/issue`, {
baseURL: connection.getBaseUrl(),
headers: { Authorization: connection.buildAuthorization(), ...constants.headers },
params: { ...constants.params.issues, startAt, maxResults, jql: 'ORDER BY created ASC' }
});
}
);
});
describe('Check [get Project By Id] service', () => {
it('should resolve response data when nominal', async () => {
const spyGet = jest.spyOn(axios, 'get').mockResolvedValue({ data: 'project' });
expect(services.getProjectById(connection, '10120')).resolves.toEqual('project');
expect(spyGet).toHaveBeenCalledWith(`/rest/api/3/project/10120`, {
baseURL: connection.getBaseUrl(),
headers: { Authorization: connection.buildAuthorization(), ...constants.headers }
});
});
});
describe('Check [get Resolution By Id] service', () => {
it('should resolve response data when nominal', async () => {
const spyGet = jest.spyOn(axios, 'get').mockResolvedValue({ data: 'resolution' });
expect(services.getResolutionById(connection, '12020')).resolves.toEqual('resolution');
expect(spyGet).toHaveBeenCalledWith(`/rest/api/3/resolution/12020`, {
baseURL: connection.getBaseUrl(),
headers: { Authorization: connection.buildAuthorization(), ...constants.headers }
});
});
});
describe('Check [get Sprint By Id] service', () => {
it('should resolve response data when nominal', async () => {
const spyGet = jest.spyOn(axios, 'get').mockResolvedValue({ data: 'status' });
expect(services.getSprintById(connection, 119)).resolves.toEqual('status');
expect(spyGet).toHaveBeenCalledWith(`/rest/agile/1.0/sprint/119`, {
baseURL: connection.getBaseUrl(),
headers: { Authorization: connection.buildAuthorization(), ...constants.headers }
});
});
});
describe('Check [get Status By Id] service', () => {
it('should resolve response data when nominal', async () => {
const spyGet = jest.spyOn(axios, 'get').mockResolvedValue({ data: 'status' });
expect(services.getStatusById(connection, '2')).resolves.toEqual('status');
expect(spyGet).toHaveBeenCalledWith(`/rest/api/3/status/2`, {
baseURL: connection.getBaseUrl(),
headers: { Authorization: connection.buildAuthorization(), ...constants.headers }
});
});
});
describe('Check [get Type By Id] service', () => {
it('should resolve response data when nominal', async () => {
const spyGet = jest.spyOn(axios, 'get').mockResolvedValue({ data: 'type' });
expect(services.getTypeById(connection, '10000')).resolves.toEqual('type');
expect(spyGet).toHaveBeenCalledWith(`/rest/api/3/issuetype/10000`, {
baseURL: connection.getBaseUrl(),
headers: { Authorization: connection.buildAuthorization(), ...constants.headers }
});
});
});
describe('Check [get Version By Id] service', () => {
it('should resolve response data when nominal', async () => {
const spyGet = jest.spyOn(axios, 'get').mockResolvedValue({ data: 'type' });
expect(services.getVersionById(connection, '10008')).resolves.toEqual('type');
expect(spyGet).toHaveBeenCalledWith(`/rest/api/3/version/10008`, {
baseURL: connection.getBaseUrl(),
headers: { Authorization: connection.buildAuthorization(), ...constants.headers }
});
});
});
});