Basic test
This commit is contained in:
parent
88889fe443
commit
5bef2090d0
|
@ -87,7 +87,8 @@ export const handler: Handlers<User | null> = {
|
|||
// TODO: json or query params
|
||||
const accept = req.headers.get('accept')
|
||||
if (accept === 'text/event-stream') {
|
||||
const stream = kv.watch([['last_user_updated']]).getReader()
|
||||
const stream = kv.watch<readonly unknown[]>([['last_user_updated']])
|
||||
.getReader()
|
||||
const body = new ReadableStream({
|
||||
async start(controller) {
|
||||
console.log(
|
||||
|
@ -100,12 +101,15 @@ export const handler: Handlers<User | null> = {
|
|||
return
|
||||
}
|
||||
|
||||
if (typeof entry.value !== 'string') {
|
||||
let v: string
|
||||
if (typeof entry.value === 'string') {
|
||||
v = z.object({ value: z.string() }).parse(entry).value
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
|
||||
const user = await db.users.findFirst({
|
||||
where: { id: entry.value },
|
||||
where: { id: v },
|
||||
})
|
||||
const chunk = `data: ${JSON.stringify(user)}\n\n`
|
||||
controller.enqueue(new TextEncoder().encode(chunk))
|
||||
|
|
23
tests/main_test.ts
Normal file
23
tests/main_test.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { createHandler, ServeHandlerInfo } from '$fresh/server.ts'
|
||||
import manifest from '@homeman/fresh.gen.ts'
|
||||
import config from '@homeman/fresh.config.ts'
|
||||
import { assert, assertEquals } from '$std/assert/mod.ts'
|
||||
|
||||
const hostname = '127.0.0.1'
|
||||
const port = 53496
|
||||
|
||||
const CONN_INFO: ServeHandlerInfo = {
|
||||
remoteAddr: { hostname, port, transport: 'tcp' },
|
||||
}
|
||||
|
||||
Deno.test('HTTP assert test.', async (t) => {
|
||||
const handler = await createHandler(manifest, config)
|
||||
|
||||
await t.step('#1 GET /', async () => {
|
||||
const resp = await handler(new Request(`http://${hostname}/`), CONN_INFO)
|
||||
const body = await resp.text()
|
||||
assertEquals(resp.status, 200)
|
||||
assert(body.includes('Fam'))
|
||||
assert(body.includes('Flan'))
|
||||
})
|
||||
})
|
Loading…
Reference in a new issue