Skip to content
Snippets Groups Projects
Unverified Commit 24bb4727 authored by Adam Setch's avatar Adam Setch Committed by GitHub
Browse files

feat(issues): add jira http util (#21056)

parent 91fd1757
No related branches found
No related tags found
No related merge requests found
import * as httpMock from '../../../test/http-mock';
import { JiraHttp, setBaseUrl } from './jira';
describe('util/http/jira', () => {
const api = new JiraHttp();
it('throws error if setBaseUrl not called', async () => {
await expect(api.postJson('some-path')).rejects.toThrow(
new TypeError('Invalid URL')
);
});
it('accepts custom baseUrl', async () => {
const siteUrl = 'https://some-site.atlassian.com';
httpMock.scope(siteUrl).post('/some-path').reply(200, {});
setBaseUrl(siteUrl);
expect(await api.postJson('some-path')).toEqual({
authorization: false,
body: {},
headers: {
'content-type': 'application/json',
},
statusCode: 200,
});
});
});
import type { HttpOptions, HttpResponse, InternalHttpOptions } from './types';
import { Http } from '.';
let baseUrl: string;
export const setBaseUrl = (url: string): void => {
baseUrl = url;
};
export class JiraHttp extends Http {
constructor(type = 'jira', options?: HttpOptions) {
super(type, options);
}
protected override request<T>(
url: string | URL,
options?: InternalHttpOptions
): Promise<HttpResponse<T>> {
const opts = { baseUrl, ...options };
return super.request<T>(url, opts);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment