From 3fac96e149633f5e4504651bb6496dfe608b4568 Mon Sep 17 00:00:00 2001 From: senke Date: Tue, 10 Mar 2026 13:35:44 +0100 Subject: [PATCH] test(v0.10.7): Add MSW handlers for co-listening sessions --- apps/web/src/mocks/handlers-colistening.ts | 56 ++++++++++++++++++++++ apps/web/src/mocks/handlers.ts | 3 ++ 2 files changed, 59 insertions(+) create mode 100644 apps/web/src/mocks/handlers-colistening.ts diff --git a/apps/web/src/mocks/handlers-colistening.ts b/apps/web/src/mocks/handlers-colistening.ts new file mode 100644 index 000000000..117fce45e --- /dev/null +++ b/apps/web/src/mocks/handlers-colistening.ts @@ -0,0 +1,56 @@ +/** + * MSW handlers for Co-listening (v0.10.7 F481) + * POST /co-listening/sessions, GET /co-listening/sessions/:id, DELETE /co-listening/sessions/:id + */ + +import { http, HttpResponse } from 'msw'; + +const mockSessions = new Map< + string, + { id: string; host_id: string; track_id: string; created_at: string; expires_at: string } +>(); + +export const handlersColistening = [ + http.post('*/api/v1/co-listening/sessions', async ({ request }) => { + const body = (await request.json()) as { track_id: string }; + const trackId = body?.track_id; + if (!trackId) { + return HttpResponse.json( + { error: { code: 'validation_error', message: 'track_id is required' } }, + { status: 400 } + ); + } + const id = `cl-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`; + const now = new Date().toISOString(); + const expiresAt = new Date(Date.now() + 4 * 60 * 60 * 1000).toISOString(); + const session = { + id, + host_id: 'user-mock-1', + track_id: trackId, + created_at: now, + expires_at: expiresAt, + }; + mockSessions.set(id, session); + return HttpResponse.json({ + session, + }); + }), + + http.get('*/api/v1/co-listening/sessions/:id', ({ params }) => { + const session = mockSessions.get(params.id as string); + if (!session) { + return HttpResponse.json( + { error: { code: 'not_found', message: 'session not found' } }, + { status: 404 } + ); + } + return HttpResponse.json({ + session, + }); + }), + + http.delete('*/api/v1/co-listening/sessions/:id', ({ params }) => { + mockSessions.delete(params.id as string); + return HttpResponse.json({ message: 'session ended' }); + }), +]; diff --git a/apps/web/src/mocks/handlers.ts b/apps/web/src/mocks/handlers.ts index e47adf484..b9dad3859 100644 --- a/apps/web/src/mocks/handlers.ts +++ b/apps/web/src/mocks/handlers.ts @@ -12,6 +12,7 @@ * - handlers-playlists: playlists * - handlers-misc: search, notifications, users profile, chat, streaming, inventory, live * - handlers-cloud: cloud storage, folders, files, quota + * - handlers-colistening: co-listening sessions (v0.10.7 F481) */ import { http, HttpResponse } from 'msw'; @@ -27,6 +28,7 @@ import { handlersDiscover } from './handlers-discover'; import { handlersCloud } from './handlers-cloud'; import { handlersStreaming } from './handlers-streaming'; import { handlersLive } from './handlers-live'; +import { handlersColistening } from './handlers-colistening'; export const handlers = [ ...handlersCommon, @@ -41,6 +43,7 @@ export const handlers = [ ...handlersCloud, ...handlersStreaming, ...handlersLive, + ...handlersColistening, // Catch-all for API to prevent network leaks (Phase 1: Stabilization) http.all('*/api/v1/*', ({ request }) => {