mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* 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
38 lines
1.0 KiB
TypeScript
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);
|
|
});
|
|
});
|
|
});
|