19 lines
769 B
TypeScript
19 lines
769 B
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { createDashboardRequest } from '../../apps/dashboard/src/api/request.js';
|
|
|
|
describe('dashboard API requests', () => {
|
|
it('redirects to sign-in when the session is no longer authorized', async () => {
|
|
const fetchImplementation = vi.fn<typeof fetch>().mockResolvedValue(new Response(
|
|
JSON.stringify({ error: 'Dashboard authentication required' }),
|
|
{ status: 401, headers: { 'Content-Type': 'application/json' } },
|
|
));
|
|
const redirectToLogin = vi.fn();
|
|
const request = createDashboardRequest(fetchImplementation, redirectToLogin);
|
|
|
|
const response = await request('/api/stats');
|
|
|
|
expect(response.status).toBe(401);
|
|
expect(redirectToLogin).toHaveBeenCalledOnce();
|
|
});
|
|
});
|