Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/vps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@effect/opentelemetry": "4.0.0-beta.93",
"@effect/platform": "0.96.2",
"@effect/platform-bun": "4.0.0-beta.93",
"@gbfm/api": "workspace:*",
"@gbfm/core": "workspace:*",
"@gbfm/email": "workspace:*",
"@hono/zod-openapi": "1.3.0",
Expand Down
53 changes: 53 additions & 0 deletions apps/vps/src/health.blackbox.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { HealthLiveResponse, HealthReadyResponse } from '@gbfm/api/health'
import { decodeResponseBody } from '@gbfm/api/testing'
import { beforeAll, describe, expect, it } from 'vitest'
import type { AppType } from '@/app'

// Asserts only the wire contract (status, JSON body against @gbfm/api schemas) so these same assertions can run unchanged once health is ported to HttpApiBuilder (step 3a).
let app: AppType

beforeAll(async () => {
const mod = await import('@/app')
app = mod.default
})

describe('Health endpoints', () => {
it('GET /health/live returns 200 with liveness JSON', async () => {
const res = await app.request('/health/live')

expect(res.status).toBe(200)
await expect(decodeResponseBody(HealthLiveResponse, res)).resolves.toEqual({ ok: true })
})

it('GET /health/ready returns 200 with readiness JSON when the database is reachable', async () => {
const res = await app.request('/health/ready')

expect(res.status).toBe(200)
await expect(decodeResponseBody(HealthReadyResponse, res)).resolves.toEqual({
dbConnected: true
})
})

it('GET /health returns the same readiness result as /health/ready', async () => {
const res = await app.request('/health')

expect(res.status).toBe(200)
await expect(decodeResponseBody(HealthReadyResponse, res)).resolves.toEqual({
dbConnected: true
})
})

it('repeated readiness calls within the cache window keep returning 200', async () => {
const first = await app.request('/health/ready')
const second = await app.request('/health/ready')

expect(first.status).toBe(200)
expect(second.status).toBe(200)
})

it('responds 404 to unsupported methods on health paths', async () => {
const res = await app.request('/health/live', { method: 'POST' })

expect(res.status).toBe(404)
})
})
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"type": "module",
"exports": {
"./health": "./src/health.ts",
"./errors": "./src/errors.ts"
"./errors": "./src/errors.ts",
"./testing": "./src/testing.ts"
},
"scripts": {
"typecheck": "tsgo --noEmit",
Expand Down
11 changes: 11 additions & 0 deletions packages/api/src/testing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Schema } from 'effect'
import { Effect, SchemaParser } from 'effect'

// Lets a blackbox test decode a live Response against the same schema an HttpApiEndpoint declares, independent of which server produced it.
export const decodeResponseBody = async <S extends Schema.Codec<unknown, unknown, never>>(
schema: S,
response: Response
): Promise<S['Type']> => {
const body: unknown = await response.json()
return Effect.runPromise(SchemaParser.decodeUnknownEffect(schema)(body))
}