|
| 1 | +import { http, delay } from 'msw' |
| 2 | +import { inertiaJson } from '@mocks/inertia' |
| 3 | +import type { MenuItem } from '@shared/types/inertiaSharedData' |
| 4 | + |
| 5 | +const menu: MenuItem[] = [ |
| 6 | + { label: 'Мое обучение' }, |
| 7 | + { label: 'Покупки и подписки', |
| 8 | + link: '/account/purchase' }, |
| 9 | + { label: 'Вебинары', |
| 10 | + link: '/account/webinars' }, |
| 11 | + { label: 'База знаний' }, |
| 12 | + { label: 'Интервью' }, |
| 13 | + { label: 'Грейдирование' }, |
| 14 | + { label: 'Программы обучения' }, |
| 15 | +] |
| 16 | + |
| 17 | +const makeHandler = ({ component, url}: { component: string, url: string }) => |
| 18 | + http.get(url, async ({ request }) => { |
| 19 | + console.log('MSW handler hit:', request.method, request.url) |
| 20 | + await delay() |
| 21 | + return inertiaJson({ |
| 22 | + component, |
| 23 | + props: { |
| 24 | + errors: {}, |
| 25 | + menu, |
| 26 | + }, |
| 27 | + url, |
| 28 | + version: 'msw-dev', |
| 29 | + }) |
| 30 | + }) |
| 31 | + |
| 32 | +const routes = [ |
| 33 | + { |
| 34 | + component: 'Account/Purchase/Index', |
| 35 | + url: '/account', |
| 36 | + }, |
| 37 | + { |
| 38 | + component: 'Account/Purchase/Index', |
| 39 | + url: '/account/purchase', |
| 40 | + }, |
| 41 | + { |
| 42 | + component: 'Account/Webinars/Index', |
| 43 | + url: '/account/webinars', |
| 44 | + }, |
| 45 | +] as const |
| 46 | + |
| 47 | +export const handlers = routes.map(makeHandler) |
0 commit comments