0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00
verdaccio/packages/plugins/ui-theme/jest/server-handlers.ts

28 lines
689 B
TypeScript
Raw Normal View History

import { rest } from 'msw';
const packagesPayload = require('./api/packages.json');
export const handlers = [
rest.get('http://localhost:9000/-/verdaccio/data/packages', (req, res, ctx) => {
return res(ctx.json(packagesPayload));
}),
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',
})
);
}
),
];