The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/datasources/api.test.ts

37 lines
1.0 KiB

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') as unknown as object),
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);
});
});
});