/** * TestPage — exercises RBAC and CRUD against the RecordRoom. * * Used by Playwright e2e tests to verify real data flow. * Displays current role, creates/reads/updates/deletes items. */ import { useState } from 'react' import { useQuery } from 'deepspace' import { useMutations } from 'deepspace' import { useUser } from 'deepspace' import { useRecordContext } from 'deepspace' import { useAuth } from 'deepspace' interface ItemData { title: string description: string status: string createdBy: string } export default function TestPage() { const { isSignedIn } = useAuth() const { user } = useUser() const { roomRole } = useRecordContext() const { records: items, status } = useQuery('test-items') const isLoading = status === 'loading' const { createConfirmed, putConfirmed, removeConfirmed } = useMutations('test-items') const [lastResult, setLastResult] = useState('') const [lastError, setLastError] = useState('') const clearStatus = () => { setLastResult(''); setLastError('') } const tryCreate = async () => { clearStatus() try { const id = await createConfirmed({ title: 'Test Item', description: 'Created by test', status: 'draft', createdBy: user?.id ?? 'anonymous' }) setLastResult(`created:${id}`) } catch (e: unknown) { setLastError(e instanceof Error ? e.message : String(e)) } } const tryCreatePublished = async () => { clearStatus() try { const id = await createConfirmed({ title: 'Public Item', description: 'Visible to anonymous', status: 'published', createdBy: user?.id ?? 'anonymous' }) setLastResult(`created:${id}`) } catch (e: unknown) { setLastError(e instanceof Error ? e.message : String(e)) } } const tryUpdate = async (recordId: string) => { clearStatus() try { await putConfirmed(recordId, { title: 'Updated Title', description: 'Updated by test', status: 'draft', createdBy: user?.id ?? 'anonymous' }) setLastResult(`updated:${recordId}`) } catch (e: unknown) { setLastError(e instanceof Error ? e.message : String(e)) } } const tryDelete = async (recordId: string) => { clearStatus() try { await removeConfirmed(recordId) setLastResult(`deleted:${recordId}`) } catch (e: unknown) { setLastError(e instanceof Error ? e.message : String(e)) } } return (

Connection Status

Signed in: {String(isSignedIn)}
User ID: {user?.id ?? 'none'}
Role: {roomRole ?? 'connecting'}
User Name: {user?.name ?? 'Anonymous'}

Actions

{lastResult && (
{lastResult}
)} {lastError && (
{lastError}
)}

Items {isLoading ? '(loading...)' : `(${items?.length ?? 0})`}

{items?.map((item) => (
{item.data.title} ({item.data.status}) by {item.data.createdBy}
))} {!isLoading && (!items || items.length === 0) && (
No items
)}
) }