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.
portainer/app/react-tools/test-mocks.ts

62 lines
1.5 KiB

import _ from 'lodash';
import { Team } from '@/portainer/teams/types';
import { Role, User, UserId } from '@/portainer/users/types';
export function createMockUsers(
count: number,
roles: Role | Role[] | ((id: UserId) => Role) = () => _.random(1, 3)
): User[] {
return _.range(1, count + 1).map((value) => ({
Id: value,
Username: `user${value}`,
Role: getRoles(roles, value),
UserTheme: '',
RoleName: '',
AuthenticationMethod: '',
Checked: false,
EndpointAuthorizations: {},
PortainerAuthorizations: {},
}));
}
function getRoles(
roles: Role | Role[] | ((id: UserId) => Role),
id: UserId
): Role {
if (typeof roles === 'function') {
return roles(id);
}
if (typeof roles === 'number') {
return roles;
}
return roles[id];
}
export function createMockTeams(count: number): Team[] {
return _.range(1, count + 1).map((value) => ({
Id: value,
Name: `team${value}`,
}));
}
export function createMockSubscriptions(count: number) {
const subscriptions = _.range(1, count + 1).map((x) => ({
id: `/subscriptions/subscription-${x}`,
subscriptionId: `subscription-${x}`,
}));
return { value: subscriptions };
}
export function createMockResourceGroups(subscription: string, count: number) {
const resourceGroups = _.range(1, count + 1).map((x) => ({
id: `/subscriptions/${subscription}/resourceGroups/resourceGroup-${x}`,
name: `resourcegroup-${x}`,
}));
return { value: resourceGroups };
}