2019-03-27 16:14:16 +08:00
|
|
|
import angular from 'angular';
|
2018-07-27 19:29:57 +08:00
|
|
|
import { BackendSrv } from 'app/core/services/backend_srv';
|
2019-03-27 16:14:16 +08:00
|
|
|
import { ContextSrv } from '../services/context_srv';
|
2018-07-27 19:29:57 +08:00
|
|
|
jest.mock('app/core/store');
|
|
|
|
|
|
2018-09-05 13:47:30 +08:00
|
|
|
describe('backend_srv', () => {
|
2019-08-01 20:38:34 +08:00
|
|
|
const _httpBackend = (options: any) => {
|
2018-07-27 20:22:48 +08:00
|
|
|
if (options.url === 'gateway-error') {
|
2018-07-27 19:29:57 +08:00
|
|
|
return Promise.reject({ status: 502 });
|
|
|
|
|
}
|
|
|
|
|
return Promise.resolve({});
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-27 16:14:16 +08:00
|
|
|
const _backendSrv = new BackendSrv(
|
|
|
|
|
_httpBackend,
|
|
|
|
|
{} as angular.IQService,
|
|
|
|
|
{} as angular.ITimeoutService,
|
|
|
|
|
{} as ContextSrv
|
|
|
|
|
);
|
2018-07-27 19:29:57 +08:00
|
|
|
|
2018-07-27 20:22:48 +08:00
|
|
|
describe('when handling errors', () => {
|
|
|
|
|
it('should return the http status code', async () => {
|
2018-07-27 21:51:56 +08:00
|
|
|
try {
|
|
|
|
|
await _backendSrv.datasourceRequest({
|
|
|
|
|
url: 'gateway-error',
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
expect(err.status).toBe(502);
|
|
|
|
|
}
|
2018-07-27 19:29:57 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|