1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/test/frontend/__setup__/server.js

46 lines
1.5 KiB
JavaScript
Raw Normal View History

import { setupServer } from 'msw/node';
import { rest } from 'msw';
import groups from '../__fixtures__/groups';
import plans from '../__fixtures__/plans';
import planCategories from '../__fixtures__/plan_categories';
import { partners } from '../__fixtures__/users';
2022-11-28 16:06:56 +01:00
import { settings } from '../__fixtures__/settings';
2022-11-28 17:01:17 +01:00
export const server = setupServer(
rest.get('/api/groups', (req, res, ctx) => {
return res(ctx.json(groups));
}),
rest.get('/api/plan_categories', (req, res, ctx) => {
return res(ctx.json(planCategories));
}),
rest.get('/api/users', (req, res, ctx) => {
return res(ctx.json(partners));
}),
rest.get('/api/plans', (req, res, ctx) => {
return res(ctx.json(plans));
}),
rest.post('/api/users', (req, res, ctx) => {
/* eslint-disable camelcase */
const { user: { first_name, last_name, email } } = req.body;
return res(ctx.status(201), ctx.json({
id: Math.ceil(Math.random() * 100),
email,
profile_attributes: { first_name, last_name }
}));
/* eslint-enable camelcase */
}),
rest.get('/api/settings/:name', (req, res, ctx) => {
2022-11-28 17:01:17 +01:00
const setting = settings.find(s => s.name === req.params.name);
return res(ctx.json({ setting }));
}),
rest.get('/api/settings', (req, res, ctx) => {
const { names } = req.params;
2022-11-28 17:01:17 +01:00
const foundSettings = settings.filter(name => names.replace(/[[\]']/g, '').split(',').includes(name));
return res(ctx.json(foundSettings));
})
);
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());