2022-11-24 18:03:50 +01:00
|
|
|
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-24 18:03:50 +01:00
|
|
|
|
2022-11-28 17:01:17 +01:00
|
|
|
export const server = setupServer(
|
2022-11-24 18:03:50 +01:00
|
|
|
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 }));
|
2022-11-24 18:03:50 +01:00
|
|
|
}),
|
|
|
|
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));
|
2022-11-24 18:03:50 +01:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
beforeAll(() => server.listen());
|
|
|
|
afterEach(() => server.resetHandlers());
|
|
|
|
afterAll(() => server.close());
|