test(v0.10.7): Add MSW handlers for co-listening sessions
This commit is contained in:
parent
871a0f2a05
commit
3fac96e149
2 changed files with 59 additions and 0 deletions
56
apps/web/src/mocks/handlers-colistening.ts
Normal file
56
apps/web/src/mocks/handlers-colistening.ts
Normal file
|
|
@ -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' });
|
||||
}),
|
||||
];
|
||||
|
|
@ -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 }) => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue