mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Update dependency msw to v2 * close * minor fixes * fetch import changes * fix some alerting tests * fix another alerting test * fix systemjs tests * don't return undefined in json mocks * don't return undefined in json response * add type --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import 'whatwg-fetch';
|
|
import { http, HttpResponse } from 'msw';
|
|
import { SetupServer } from 'msw/node';
|
|
|
|
import {
|
|
AlertmanagerChoice,
|
|
AlertManagerCortexConfig,
|
|
ExternalAlertmanagersResponse,
|
|
} from '../../../../plugins/datasource/alertmanager/types';
|
|
import { AlertmanagersChoiceResponse } from '../api/alertmanagerApi';
|
|
import { getDatasourceAPIUid } from '../utils/datasource';
|
|
|
|
export const defaultAlertmanagerChoiceResponse: AlertmanagersChoiceResponse = {
|
|
alertmanagersChoice: AlertmanagerChoice.Internal,
|
|
numExternalAlertmanagers: 0,
|
|
};
|
|
export function mockAlertmanagerChoiceResponse(server: SetupServer, response: AlertmanagersChoiceResponse) {
|
|
server.use(http.get('/api/v1/ngalert', () => HttpResponse.json(response)));
|
|
}
|
|
|
|
export const emptyExternalAlertmanagersResponse: ExternalAlertmanagersResponse = {
|
|
data: {
|
|
droppedAlertManagers: [],
|
|
activeAlertManagers: [],
|
|
},
|
|
};
|
|
export function mockAlertmanagersResponse(server: SetupServer, response: ExternalAlertmanagersResponse) {
|
|
server.use(http.get('/api/v1/ngalert/alertmanagers', () => HttpResponse.json(response)));
|
|
}
|
|
|
|
export function mockAlertmanagerConfigResponse(
|
|
server: SetupServer,
|
|
alertManagerSourceName: string,
|
|
response: AlertManagerCortexConfig
|
|
) {
|
|
server.use(
|
|
http.get(`/api/alertmanager/${getDatasourceAPIUid(alertManagerSourceName)}/config/api/v1/alerts`, () =>
|
|
HttpResponse.json(response)
|
|
)
|
|
);
|
|
}
|