2018-07-27 06:29:57 -05:00
|
|
|
import { BackendSrv } from 'app/core/services/backend_srv';
|
|
|
|
jest.mock('app/core/store');
|
|
|
|
|
2018-09-05 00:47:30 -05:00
|
|
|
describe('backend_srv', () => {
|
2018-08-26 10:14:40 -05:00
|
|
|
const _httpBackend = options => {
|
2018-07-27 07:22:48 -05:00
|
|
|
if (options.url === 'gateway-error') {
|
2018-07-27 06:29:57 -05:00
|
|
|
return Promise.reject({ status: 502 });
|
|
|
|
}
|
|
|
|
return Promise.resolve({});
|
|
|
|
};
|
|
|
|
|
2018-08-26 10:14:40 -05:00
|
|
|
const _backendSrv = new BackendSrv(_httpBackend, {}, {}, {}, {});
|
2018-07-27 06:29:57 -05:00
|
|
|
|
2018-07-27 07:22:48 -05:00
|
|
|
describe('when handling errors', () => {
|
|
|
|
it('should return the http status code', async () => {
|
2018-07-27 08:51:56 -05:00
|
|
|
try {
|
|
|
|
await _backendSrv.datasourceRequest({
|
|
|
|
url: 'gateway-error',
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
expect(err.status).toBe(502);
|
|
|
|
}
|
2018-07-27 06:29:57 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|