grafana/public/app/features/datasources/api.test.ts
Ashley Harrison f8d89eff56
Chore: fix type errors in tests (#63270)
* fix any's in tests

* fix more any's in tests

* more test type fixes

* fixing any's in tests part 3

* more test type fixes

* fixing test any's p5

* some tidy up

* fix template_srv
2023-02-14 16:46:42 +01:00

38 lines
1.0 KiB
TypeScript

import { of } from 'rxjs';
import { BackendSrvRequest, FetchResponse } from '@grafana/runtime';
import { getBackendSrv } from 'app/core/services/backend_srv';
import { getDataSourceByIdOrUid } from './api';
jest.mock('app/core/services/backend_srv');
jest.mock('@grafana/runtime', () => ({
...jest.requireActual('@grafana/runtime'),
getBackendSrv: jest.fn(),
}));
const mockResponse = (response: Partial<FetchResponse>) => {
(getBackendSrv as jest.Mock).mockReturnValueOnce({
fetch: (options: BackendSrvRequest) => {
return of(response as FetchResponse);
},
});
};
describe('Datasources / API', () => {
describe('getDataSourceByIdOrUid()', () => {
it('should resolve to the datasource object in case it is fetched using a UID', async () => {
const response = {
ok: true,
data: {
id: 111,
uid: 'abcdefg',
},
};
mockResponse(response);
expect(await getDataSourceByIdOrUid(response.data.uid)).toBe(response.data);
});
});
});