MotorSignal-App/website/tests/website-session-proxy.test.ts

25 lines
1.2 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest';
import { NextRequest } from 'next/server';
import { POST } from '../app/api/account/sessions/route';
import { DELETE } from '../app/api/account/sessions/[sessionId]/route';
vi.mock('next/headers', () => ({ cookies: async () => ({ get: () => ({ value: 'isolated-session' }) }) }));
afterEach(() => vi.unstubAllGlobals());
describe('device session proxy preserves successful no-content revocations', () => {
it('returns 204 with no body when revoking one session', async () => {
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(null, { status: 204 })));
const response = await DELETE(new NextRequest('http://localhost/api/account/sessions/owned-session'), {
params: Promise.resolve({ sessionId: 'owned-session' }),
});
expect(response.status).toBe(204);
expect(await response.text()).toBe('');
});
it('returns 204 with no body when revoking all sessions', async () => {
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(null, { status: 204 })));
const response = await POST(new NextRequest('http://localhost/api/account/sessions', { method: 'POST' }));
expect(response.status).toBe(204);
expect(await response.text()).toBe('');
});
});