fix(app): handle nullable detail consumers
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { AgentWorkspaceShell } from '../../src/components/agent-workspace/agent-workspace-shell';
|
||||
|
||||
const { mockUseMutation, mockUseQuery } = vi.hoisted(() => ({
|
||||
mockUseMutation: vi.fn(() => vi.fn()),
|
||||
mockUseQuery: vi.fn(() => null),
|
||||
}));
|
||||
|
||||
vi.mock('convex/react', () => ({
|
||||
useMutation: mockUseMutation,
|
||||
useQuery: mockUseQuery,
|
||||
}));
|
||||
|
||||
vi.mock('sonner', () => ({
|
||||
toast: {
|
||||
error: vi.fn(),
|
||||
success: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('AgentWorkspaceShell', () => {
|
||||
it('renders a missing state when the job query returns null', () => {
|
||||
render(<AgentWorkspaceShell jobId={'job-1' as never} />);
|
||||
|
||||
expect(
|
||||
screen.getByText('This workspace was not found.'),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { POST } from '../../src/app/api/threads/[threadId]/message/route';
|
||||
|
||||
const { mockAuthToken, mockFetchMutation, mockFetchQuery, mockProxyWorker } =
|
||||
vi.hoisted(() => ({
|
||||
mockAuthToken: vi.fn(),
|
||||
mockFetchMutation: vi.fn(),
|
||||
mockFetchQuery: vi.fn(),
|
||||
mockProxyWorker: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@convex-dev/auth/nextjs/server', () => ({
|
||||
convexAuthNextjsToken: mockAuthToken,
|
||||
}));
|
||||
|
||||
vi.mock('convex/nextjs', () => ({
|
||||
fetchMutation: mockFetchMutation,
|
||||
fetchQuery: mockFetchQuery,
|
||||
}));
|
||||
|
||||
vi.mock('@/lib/agent-worker-proxy', () => ({
|
||||
proxyWorker: mockProxyWorker,
|
||||
}));
|
||||
|
||||
describe('thread message route', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
mockAuthToken.mockResolvedValue('token');
|
||||
});
|
||||
|
||||
it('returns 404 when the thread detail query returns null', async () => {
|
||||
mockFetchQuery.mockResolvedValue(null);
|
||||
|
||||
const response = await POST(
|
||||
new Request('http://localhost/api/threads/thread-1/message', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ content: 'Hello' }),
|
||||
}),
|
||||
{ params: Promise.resolve({ threadId: 'thread-1' }) },
|
||||
);
|
||||
|
||||
expect(response.status).toBe(404);
|
||||
await expect(response.json()).resolves.toEqual({
|
||||
error: 'Thread not found.',
|
||||
});
|
||||
expect(mockFetchMutation).not.toHaveBeenCalled();
|
||||
expect(mockProxyWorker).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user