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

chat.test.e2e.ts

39 lines1.2 KB

1import assert from 'node:assert/strict'
2import { describe, it } from 'node:test'
3import { createRouter } from 'remix/router'
4​
5import chatController from './actions/chat/controller.ts'
6import { routes } from './routes.ts'
7​
8// ponytail: map only the chat controller. The app router loads Chat, and
9// @tanstack/ai-remix source has extensionless imports Node cannot resolve.
10const router = createRouter()
11router.map(routes.chat, chatController)
12​
13const chatUrl = 'http://localhost' + routes.chat.stream.href()
14​
15function postChat(body: string) {
16 return router.fetch(
17 new Request(chatUrl, {
18 method: 'POST',
19 headers: { 'content-type': 'application/json' },
20 body,
21 }),
22 )
24​
25describe('chat', () => {
26 it('returns 400 when the POST body is not JSON', async () => {
27 const response = await postChat('not-json')
28 assert.equal(response.status, 400)
29 assert.equal(await response.text(), 'Bad request')
30 })
31​
32 it('returns 400 when JSON is not a chat request', async () => {
33 const response = await postChat(
34 JSON.stringify({ messages: [{ role: 'user', content: 'hi' }] }),
35 )
36 assert.equal(response.status, 400)
37 assert.match(await response.text(), /RunAgentInput/)
38 })
39})