2023-01-23 13:03:11 +00:00
|
|
|
import { DefaultBodyType, PathParams, rest } from 'msw';
|
2022-01-05 16:28:56 +00:00
|
|
|
|
2022-03-08 12:14:23 +00:00
|
|
|
import {
|
|
|
|
Edition,
|
|
|
|
LicenseInfo,
|
|
|
|
LicenseType,
|
|
|
|
} from '@/portainer/license-management/types';
|
2022-11-13 08:10:18 +00:00
|
|
|
import { EnvironmentGroup } from '@/react/portainer/environments/environment-groups/types';
|
2022-03-08 12:14:23 +00:00
|
|
|
import { Tag } from '@/portainer/tags/types';
|
2022-12-11 06:58:22 +00:00
|
|
|
import { StatusResponse } from '@/react/portainer/system/useSystemStatus';
|
2022-06-23 07:25:56 +00:00
|
|
|
import { createMockTeams } from '@/react-tools/test-mocks';
|
2022-09-21 06:14:29 +00:00
|
|
|
import { PublicSettingsResponse } from '@/react/portainer/settings/types';
|
2022-09-02 15:30:34 +00:00
|
|
|
import { UserId } from '@/portainer/users/types';
|
2022-01-05 16:28:56 +00:00
|
|
|
|
2022-02-01 17:38:45 +00:00
|
|
|
import { azureHandlers } from './setup-handlers/azure';
|
2022-06-23 07:25:56 +00:00
|
|
|
import { dockerHandlers } from './setup-handlers/docker';
|
|
|
|
import { userHandlers } from './setup-handlers/users';
|
2022-02-01 17:38:45 +00:00
|
|
|
|
2022-05-29 06:14:14 +00:00
|
|
|
const tags: Tag[] = [
|
|
|
|
{ ID: 1, Name: 'tag1' },
|
|
|
|
{ ID: 2, Name: 'tag2' },
|
|
|
|
];
|
|
|
|
|
2022-03-08 12:14:23 +00:00
|
|
|
const licenseInfo: LicenseInfo = {
|
|
|
|
nodes: 1000,
|
|
|
|
type: LicenseType.Subscription,
|
|
|
|
company: 'company',
|
|
|
|
createdAt: 0,
|
|
|
|
email: 'email@company.com',
|
|
|
|
expiresAt: Number.MAX_SAFE_INTEGER,
|
|
|
|
productEdition: Edition.EE,
|
|
|
|
valid: true,
|
2022-11-22 12:16:34 +00:00
|
|
|
enforcedAt: 0,
|
|
|
|
enforced: false,
|
2022-03-08 12:14:23 +00:00
|
|
|
};
|
|
|
|
|
2022-01-05 16:28:56 +00:00
|
|
|
export const handlers = [
|
|
|
|
rest.get('/api/teams', async (req, res, ctx) =>
|
|
|
|
res(ctx.json(createMockTeams(10)))
|
|
|
|
),
|
2022-06-23 07:25:56 +00:00
|
|
|
|
2022-09-02 15:30:34 +00:00
|
|
|
rest.post<{ name: string }>('/api/teams', (req, res, ctx) =>
|
|
|
|
res(ctx.status(204))
|
|
|
|
),
|
|
|
|
rest.post<{ userId: UserId }>('/api/team_memberships', (req, res, ctx) =>
|
|
|
|
res(ctx.status(204))
|
|
|
|
),
|
2022-02-01 17:38:45 +00:00
|
|
|
...azureHandlers,
|
2022-06-23 07:25:56 +00:00
|
|
|
...dockerHandlers,
|
|
|
|
...userHandlers,
|
2022-03-08 12:14:23 +00:00
|
|
|
rest.get('/api/licenses/info', (req, res, ctx) => res(ctx.json(licenseInfo))),
|
|
|
|
rest.get('/api/status/nodes', (req, res, ctx) => res(ctx.json({ nodes: 3 }))),
|
|
|
|
rest.get('/api/backup/s3/status', (req, res, ctx) =>
|
|
|
|
res(ctx.json({ Failed: false }))
|
|
|
|
),
|
|
|
|
rest.get('/api/endpoint_groups', (req, res, ctx) => res(ctx.json([]))),
|
|
|
|
rest.get('/api/endpoint_groups/:groupId', (req, res, ctx) => {
|
|
|
|
if (req.params.groupId instanceof Array) {
|
|
|
|
throw new Error('should be string');
|
|
|
|
}
|
|
|
|
const id = parseInt(req.params.groupId, 10);
|
|
|
|
const group: Partial<EnvironmentGroup> = {
|
|
|
|
Id: id,
|
|
|
|
Name: `group${id}`,
|
|
|
|
};
|
|
|
|
return res(ctx.json(group));
|
|
|
|
}),
|
2022-05-29 06:14:14 +00:00
|
|
|
rest.get('/api/tags', (req, res, ctx) => res(ctx.json(tags))),
|
|
|
|
rest.post<{ name: string }>('/api/tags', (req, res, ctx) => {
|
|
|
|
const tagName = req.body.name;
|
|
|
|
const tag = { ID: tags.length + 1, Name: tagName };
|
|
|
|
tags.push(tag);
|
|
|
|
return res(ctx.json(tag));
|
2022-03-08 12:14:23 +00:00
|
|
|
}),
|
2023-01-23 13:03:11 +00:00
|
|
|
rest.get<DefaultBodyType, PathParams, Partial<PublicSettingsResponse>>(
|
2022-06-23 07:25:56 +00:00
|
|
|
'/api/settings/public',
|
2023-01-10 19:30:49 +00:00
|
|
|
(req, res, ctx) =>
|
|
|
|
res(
|
|
|
|
ctx.json({
|
|
|
|
Edge: {
|
|
|
|
AsyncMode: false,
|
|
|
|
CheckinInterval: 60,
|
|
|
|
CommandInterval: 60,
|
|
|
|
PingInterval: 60,
|
|
|
|
SnapshotInterval: 60,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
2022-06-23 07:25:56 +00:00
|
|
|
),
|
2023-01-23 13:03:11 +00:00
|
|
|
rest.get<DefaultBodyType, PathParams, Partial<StatusResponse>>(
|
2022-06-23 07:25:56 +00:00
|
|
|
'/api/status',
|
|
|
|
(req, res, ctx) => res(ctx.json({}))
|
|
|
|
),
|
2022-01-05 16:28:56 +00:00
|
|
|
];
|