Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

world-generation.spec.ts

85 lines2.6 KB

1import { test, expect } from './fixtures'
2​
3test.describe('generateWorld activity', () => {
4 test('mints a Reactor session token through reactorWorld', async ({
5 request,
6 }) => {
7 const res = await request.post('/api/world', {
8 data: { prompt: 'A neon cyberpunk city at night' },
9 })
10 expect(res.ok()).toBe(true)
11​
12 const body = (await res.json()) as {
13 ok: boolean
14 token?: string
15 model?: string
16 prompt?: string
17 status?: string
18 expiresAt?: number
19 error?: string
20 }
21​
22 expect(body.error ?? null).toBeNull()
23 expect(body.ok).toBe(true)
24 expect(body.token).toBe('jwt-e2e')
25 expect(body.model).toBe('reactor/visko-orbis-stable')
26 expect(body.prompt).toBe('A neon cyberpunk city at night')
27 expect(body.status).toBe('ready')
28 expect(body.expiresAt).toBe(1_800_000_000 * 1000)
29 })
30​
31 test('returns 500 when the token endpoint fails', async ({ request }) => {
32 const res = await request.post('/api/world', {
33 data: { prompt: 'A neon cyberpunk city at night', fail: true },
34 })
35 expect(res.status()).toBe(500)
36 const body = (await res.json()) as { ok: boolean; error?: string }
37 expect(body.ok).toBe(false)
38 expect(body.error).toMatch(/Reactor token request failed \(402/)
39 })
40​
41 test('returns a Marble viewer URL through worldlabsWorld', async ({
42 request,
43 }) => {
44 const res = await request.post('/api/world', {
45 data: {
46 prompt: 'A mystical forest with glowing mushrooms',
47 provider: 'worldlabs',
48 },
49 })
50 const body = (await res.json()) as {
51 ok: boolean
52 url?: string
53 worldId?: string
54 operationId?: string
55 model?: string
56 prompt?: string
57 status?: string
58 error?: string
59 }
60​
61 expect(body.error ?? null).toBeNull()
62 expect(res.ok()).toBe(true)
63 expect(body.ok).toBe(true)
64 expect(body.url).toBe('https://marble.worldlabs.ai/world/world-e2e')
65 expect(body.worldId).toBe('world-e2e')
66 expect(body.operationId).toBe('op-e2e')
67 expect(body.model).toBe('marble-1.1')
68 expect(body.prompt).toBe('A mystical forest with glowing mushrooms')
69 expect(body.status).toBe('ready')
70 })
71​
72 test('returns 500 when World Labs generate fails', async ({ request }) => {
73 const res = await request.post('/api/world', {
74 data: {
75 prompt: 'A mystical forest with glowing mushrooms',
76 provider: 'worldlabs',
77 fail: true,
78 },
79 })
80 expect(res.status()).toBe(500)
81 const body = (await res.json()) as { ok: boolean; error?: string }
82 expect(body.ok).toBe(false)
83 expect(body.error).toMatch(/World Labs generate request failed \(402/)
84 })
85})