2021-09-25 10:35:03 -05:00
|
|
|
import { rest } from 'msw';
|
|
|
|
|
|
|
|
const packagesPayload = require('./api/packages.json');
|
|
|
|
|
|
|
|
export const handlers = [
|
2022-01-15 14:12:28 -05:00
|
|
|
rest.get('http://localhost:9000/-/verdaccio/data/packages', (req, res, ctx) => {
|
2021-09-25 10:35:03 -05:00
|
|
|
return res(ctx.json(packagesPayload));
|
|
|
|
}),
|
2022-11-12 16:05:08 -05:00
|
|
|
|
|
|
|
rest.post<{ username: string; password: string }, { token: string; username: string }>(
|
|
|
|
'http://localhost:9000/-/verdaccio/sec/login',
|
|
|
|
// @ts-ignore
|
|
|
|
async (req, res, ctx) => {
|
|
|
|
const body = await req.json();
|
|
|
|
if (body.username === 'fail') {
|
|
|
|
return ctx.status(401);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res(
|
|
|
|
ctx.json({
|
|
|
|
username: body.username,
|
|
|
|
token: 'valid token',
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
),
|
2021-09-25 10:35:03 -05:00
|
|
|
];
|