feat(#37-41): Add domains, ideas, relationships, agents, widgets schema
Schema additions for issues #37-41: New models: - Domain (#37): Life domains (work, marriage, homelab, etc.) - Idea (#38): Brain dumps with pgvector embeddings - Relationship (#39): Generic entity linking (blocks, depends_on) - Agent (#40): ClawdBot agent tracking with metrics - AgentSession (#40): Conversation session tracking - WidgetDefinition (#41): HUD widget registry - UserLayout (#41): Per-user dashboard configuration Updated models: - Task, Event, Project: Added domainId foreign key - User, Workspace: Added new relations New enums: - IdeaStatus: CAPTURED, PROCESSING, ACTIONABLE, ARCHIVED, DISCARDED - RelationshipType: BLOCKS, BLOCKED_BY, DEPENDS_ON, etc. - AgentStatus: IDLE, WORKING, WAITING, ERROR, TERMINATED - EntityType: Added IDEA, DOMAIN Migration: 20260129182803_add_domains_ideas_agents_widgets
This commit is contained in:
95
apps/web/src/app/(auth)/callback/page.test.tsx
Normal file
95
apps/web/src/app/(auth)/callback/page.test.tsx
Normal file
@@ -0,0 +1,95 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import CallbackPage from "./page";
|
||||
|
||||
// Mock next/navigation
|
||||
const mockPush = vi.fn();
|
||||
const mockSearchParams = new Map<string, string>();
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: () => ({
|
||||
push: mockPush,
|
||||
}),
|
||||
useSearchParams: () => ({
|
||||
get: (key: string) => mockSearchParams.get(key),
|
||||
}),
|
||||
}));
|
||||
|
||||
// Mock auth context
|
||||
vi.mock("@/lib/auth/auth-context", () => ({
|
||||
useAuth: vi.fn(() => ({
|
||||
refreshSession: vi.fn(),
|
||||
})),
|
||||
}));
|
||||
|
||||
const { useAuth } = await import("@/lib/auth/auth-context");
|
||||
|
||||
describe("CallbackPage", () => {
|
||||
beforeEach(() => {
|
||||
mockPush.mockClear();
|
||||
mockSearchParams.clear();
|
||||
vi.mocked(useAuth).mockReturnValue({
|
||||
refreshSession: vi.fn(),
|
||||
user: null,
|
||||
isLoading: false,
|
||||
isAuthenticated: false,
|
||||
signOut: vi.fn(),
|
||||
});
|
||||
});
|
||||
|
||||
it("should render processing message", () => {
|
||||
render(<CallbackPage />);
|
||||
expect(
|
||||
screen.getByText(/completing authentication/i)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should redirect to tasks page on success", async () => {
|
||||
const mockRefreshSession = vi.fn().mockResolvedValue(undefined);
|
||||
vi.mocked(useAuth).mockReturnValue({
|
||||
refreshSession: mockRefreshSession,
|
||||
user: null,
|
||||
isLoading: false,
|
||||
isAuthenticated: false,
|
||||
signOut: vi.fn(),
|
||||
});
|
||||
|
||||
render(<CallbackPage />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockRefreshSession).toHaveBeenCalled();
|
||||
expect(mockPush).toHaveBeenCalledWith("/tasks");
|
||||
});
|
||||
});
|
||||
|
||||
it("should redirect to login on error parameter", async () => {
|
||||
mockSearchParams.set("error", "access_denied");
|
||||
mockSearchParams.set("error_description", "User cancelled");
|
||||
|
||||
render(<CallbackPage />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockPush).toHaveBeenCalledWith("/login?error=access_denied");
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle refresh session errors gracefully", async () => {
|
||||
const mockRefreshSession = vi
|
||||
.fn()
|
||||
.mockRejectedValue(new Error("Session error"));
|
||||
vi.mocked(useAuth).mockReturnValue({
|
||||
refreshSession: mockRefreshSession,
|
||||
user: null,
|
||||
isLoading: false,
|
||||
isAuthenticated: false,
|
||||
signOut: vi.fn(),
|
||||
});
|
||||
|
||||
render(<CallbackPage />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockRefreshSession).toHaveBeenCalled();
|
||||
expect(mockPush).toHaveBeenCalledWith("/login?error=session_failed");
|
||||
});
|
||||
});
|
||||
});
|
||||
59
apps/web/src/app/(auth)/callback/page.tsx
Normal file
59
apps/web/src/app/(auth)/callback/page.tsx
Normal file
@@ -0,0 +1,59 @@
|
||||
"use client";
|
||||
|
||||
import { Suspense, useEffect } from "react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { useAuth } from "@/lib/auth/auth-context";
|
||||
|
||||
function CallbackContent() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const { refreshSession } = useAuth();
|
||||
|
||||
useEffect(() => {
|
||||
async function handleCallback() {
|
||||
// Check for OAuth errors
|
||||
const error = searchParams.get("error");
|
||||
if (error) {
|
||||
console.error("OAuth error:", error, searchParams.get("error_description"));
|
||||
router.push(`/login?error=${error}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Refresh the session to load the authenticated user
|
||||
try {
|
||||
await refreshSession();
|
||||
router.push("/tasks");
|
||||
} catch (error) {
|
||||
console.error("Session refresh failed:", error);
|
||||
router.push("/login?error=session_failed");
|
||||
}
|
||||
}
|
||||
|
||||
handleCallback();
|
||||
}, [router, searchParams, refreshSession]);
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen flex-col items-center justify-center p-8">
|
||||
<div className="text-center">
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-900 mx-auto mb-4"></div>
|
||||
<h1 className="text-2xl font-semibold mb-2">Completing authentication...</h1>
|
||||
<p className="text-gray-600">You will be redirected shortly.</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function CallbackPage() {
|
||||
return (
|
||||
<Suspense fallback={
|
||||
<div className="flex min-h-screen flex-col items-center justify-center p-8">
|
||||
<div className="text-center">
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-gray-900 mx-auto mb-4"></div>
|
||||
<h1 className="text-2xl font-semibold mb-2">Loading...</h1>
|
||||
</div>
|
||||
</div>
|
||||
}>
|
||||
<CallbackContent />
|
||||
</Suspense>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user