Reuse existing mock user method

This commit is contained in:
Tom Ratcliffe 2024-03-28 15:21:00 +00:00 committed by Tom Ratcliffe
parent 2ca5e43a65
commit fb40c09eaf
3 changed files with 5 additions and 25 deletions

View File

@ -26,6 +26,7 @@ import {
} from 'app/features/alerting/unified/mockApi';
import { mockAlertmanagerChoiceResponse } from 'app/features/alerting/unified/mocks/alertmanagerApi';
import * as actions from 'app/features/alerting/unified/state/actions';
import { getMockUser } from 'app/features/users/__mocks__/userMocks';
import { AlertmanagerChoice } from 'app/plugins/datasource/alertmanager/types';
import { AccessControlAction } from 'app/types';
import { PromAlertingRuleState, PromApplication } from 'app/types/unified-alerting-dto';
@ -49,7 +50,6 @@ import {
somePromRules,
someRulerRules,
mockFolder,
mockUser,
} from './mocks';
import * as config from './utils/config';
import { DataSourceType, GRAFANA_RULES_SOURCE_NAME } from './utils/datasource';
@ -164,7 +164,7 @@ const server = setupServer();
const configureMockServer = () => {
mockSearchApi(server).search([]);
mockUserApi(server).user(mockUser());
mockUserApi(server).user(getMockUser());
mockFolderApi(server).folder(
'NAMESPACE_UID',
mockFolder({

View File

@ -6,6 +6,7 @@ import { setupServer, SetupServer } from 'msw/node';
import { DataSourceInstanceSettings, PluginMeta } from '@grafana/data';
import { setBackendSrv } from '@grafana/runtime';
import { AlertRuleUpdated } from 'app/features/alerting/unified/api/alertRuleApi';
import { DashboardDTO, FolderDTO, NotifierDTO, OrgUser } from 'app/types';
import {
PromBuildInfoResponse,
PromRulesResponse,
@ -23,7 +24,6 @@ import {
MatcherOperator,
Route,
} from '../../../plugins/datasource/alertmanager/types';
import { DashboardDTO, FolderDTO, NotifierDTO, UserDTO } from '../../../types';
import { DashboardSearchItem } from '../../search/types';
import { CreateIntegrationDTO, NewOnCallIntegrationDTO, OnCallIntegrationDTO } from './api/onCallApi';
@ -404,7 +404,7 @@ export function mockSearchApi(server: SetupServer) {
export function mockUserApi(server: SetupServer) {
return {
user: (user: UserDTO) => {
user: (user: OrgUser) => {
server.use(http.get(`/api/user`, () => HttpResponse.json(user)));
},
};

View File

@ -31,15 +31,7 @@ import {
SilenceState,
} from 'app/plugins/datasource/alertmanager/types';
import { configureStore } from 'app/store/configureStore';
import {
AccessControlAction,
DashboardDTO,
FolderDTO,
NotifiersState,
ReceiversState,
StoreState,
UserDTO,
} from 'app/types';
import { AccessControlAction, DashboardDTO, FolderDTO, NotifiersState, ReceiversState, StoreState } from 'app/types';
import {
Alert,
AlertingRule,
@ -619,18 +611,6 @@ export const mockFolder = (partial?: Partial<FolderDTO>): FolderDTO => {
};
};
export const mockUser = (partial?: Partial<UserDTO>): UserDTO => {
return {
id: 1,
login: 'admin',
email: 'admin@grafana.com',
name: 'Admin',
isGrafanaAdmin: true,
isDisabled: false,
...partial,
};
};
export const grantUserPermissions = (permissions: AccessControlAction[]) => {
jest
.spyOn(contextSrv, 'hasPermission')