mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Reuse existing mock user method
This commit is contained in:
parent
2ca5e43a65
commit
fb40c09eaf
@ -26,6 +26,7 @@ import {
|
|||||||
} from 'app/features/alerting/unified/mockApi';
|
} from 'app/features/alerting/unified/mockApi';
|
||||||
import { mockAlertmanagerChoiceResponse } from 'app/features/alerting/unified/mocks/alertmanagerApi';
|
import { mockAlertmanagerChoiceResponse } from 'app/features/alerting/unified/mocks/alertmanagerApi';
|
||||||
import * as actions from 'app/features/alerting/unified/state/actions';
|
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 { AlertmanagerChoice } from 'app/plugins/datasource/alertmanager/types';
|
||||||
import { AccessControlAction } from 'app/types';
|
import { AccessControlAction } from 'app/types';
|
||||||
import { PromAlertingRuleState, PromApplication } from 'app/types/unified-alerting-dto';
|
import { PromAlertingRuleState, PromApplication } from 'app/types/unified-alerting-dto';
|
||||||
@ -49,7 +50,6 @@ import {
|
|||||||
somePromRules,
|
somePromRules,
|
||||||
someRulerRules,
|
someRulerRules,
|
||||||
mockFolder,
|
mockFolder,
|
||||||
mockUser,
|
|
||||||
} from './mocks';
|
} from './mocks';
|
||||||
import * as config from './utils/config';
|
import * as config from './utils/config';
|
||||||
import { DataSourceType, GRAFANA_RULES_SOURCE_NAME } from './utils/datasource';
|
import { DataSourceType, GRAFANA_RULES_SOURCE_NAME } from './utils/datasource';
|
||||||
@ -164,7 +164,7 @@ const server = setupServer();
|
|||||||
|
|
||||||
const configureMockServer = () => {
|
const configureMockServer = () => {
|
||||||
mockSearchApi(server).search([]);
|
mockSearchApi(server).search([]);
|
||||||
mockUserApi(server).user(mockUser());
|
mockUserApi(server).user(getMockUser());
|
||||||
mockFolderApi(server).folder(
|
mockFolderApi(server).folder(
|
||||||
'NAMESPACE_UID',
|
'NAMESPACE_UID',
|
||||||
mockFolder({
|
mockFolder({
|
||||||
|
@ -6,6 +6,7 @@ import { setupServer, SetupServer } from 'msw/node';
|
|||||||
import { DataSourceInstanceSettings, PluginMeta } from '@grafana/data';
|
import { DataSourceInstanceSettings, PluginMeta } from '@grafana/data';
|
||||||
import { setBackendSrv } from '@grafana/runtime';
|
import { setBackendSrv } from '@grafana/runtime';
|
||||||
import { AlertRuleUpdated } from 'app/features/alerting/unified/api/alertRuleApi';
|
import { AlertRuleUpdated } from 'app/features/alerting/unified/api/alertRuleApi';
|
||||||
|
import { DashboardDTO, FolderDTO, NotifierDTO, OrgUser } from 'app/types';
|
||||||
import {
|
import {
|
||||||
PromBuildInfoResponse,
|
PromBuildInfoResponse,
|
||||||
PromRulesResponse,
|
PromRulesResponse,
|
||||||
@ -23,7 +24,6 @@ import {
|
|||||||
MatcherOperator,
|
MatcherOperator,
|
||||||
Route,
|
Route,
|
||||||
} from '../../../plugins/datasource/alertmanager/types';
|
} from '../../../plugins/datasource/alertmanager/types';
|
||||||
import { DashboardDTO, FolderDTO, NotifierDTO, UserDTO } from '../../../types';
|
|
||||||
import { DashboardSearchItem } from '../../search/types';
|
import { DashboardSearchItem } from '../../search/types';
|
||||||
|
|
||||||
import { CreateIntegrationDTO, NewOnCallIntegrationDTO, OnCallIntegrationDTO } from './api/onCallApi';
|
import { CreateIntegrationDTO, NewOnCallIntegrationDTO, OnCallIntegrationDTO } from './api/onCallApi';
|
||||||
@ -404,7 +404,7 @@ export function mockSearchApi(server: SetupServer) {
|
|||||||
|
|
||||||
export function mockUserApi(server: SetupServer) {
|
export function mockUserApi(server: SetupServer) {
|
||||||
return {
|
return {
|
||||||
user: (user: UserDTO) => {
|
user: (user: OrgUser) => {
|
||||||
server.use(http.get(`/api/user`, () => HttpResponse.json(user)));
|
server.use(http.get(`/api/user`, () => HttpResponse.json(user)));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -31,15 +31,7 @@ import {
|
|||||||
SilenceState,
|
SilenceState,
|
||||||
} from 'app/plugins/datasource/alertmanager/types';
|
} from 'app/plugins/datasource/alertmanager/types';
|
||||||
import { configureStore } from 'app/store/configureStore';
|
import { configureStore } from 'app/store/configureStore';
|
||||||
import {
|
import { AccessControlAction, DashboardDTO, FolderDTO, NotifiersState, ReceiversState, StoreState } from 'app/types';
|
||||||
AccessControlAction,
|
|
||||||
DashboardDTO,
|
|
||||||
FolderDTO,
|
|
||||||
NotifiersState,
|
|
||||||
ReceiversState,
|
|
||||||
StoreState,
|
|
||||||
UserDTO,
|
|
||||||
} from 'app/types';
|
|
||||||
import {
|
import {
|
||||||
Alert,
|
Alert,
|
||||||
AlertingRule,
|
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[]) => {
|
export const grantUserPermissions = (permissions: AccessControlAction[]) => {
|
||||||
jest
|
jest
|
||||||
.spyOn(contextSrv, 'hasPermission')
|
.spyOn(contextSrv, 'hasPermission')
|
||||||
|
Loading…
Reference in New Issue
Block a user