53 lines
2.1 KiB
TypeScript
53 lines
2.1 KiB
TypeScript
// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
|
|
// What this app hands the mount (apps/web/src/server/router.ts): its readiness per profile, its title
|
|
// and its live stream. The mount itself is `@conusai-kit/host/http` and its tests.
|
|
|
|
import { appBrand, PROFILE } from "@app/config"
|
|
import { beforeEach, describe, expect, it, vi } from "vitest"
|
|
|
|
const app = vi.hoisted(() => ({
|
|
runtime: {} as Record<string, unknown>,
|
|
ready: { ready: false, checks: { store: false, reader: false, migrations: false, platform: false } },
|
|
}))
|
|
|
|
vi.mock("../apps/web/src/server/app", () => ({
|
|
convexCapabilityStatus: async () => ({ ready: true }),
|
|
postgresHost: () => ({ readiness: async () => app.ready }),
|
|
webRuntime: () => app.runtime,
|
|
}))
|
|
vi.mock("../apps/web/src/server/request", () => ({
|
|
requestContext: async () => ({ principal: null, caller: {}, correlationId: "correlation" }),
|
|
}))
|
|
vi.mock("../apps/web/src/server/live", () => ({ serveLive: async () => new Response("the live stream") }))
|
|
|
|
const handled = async (path: string, init?: RequestInit): Promise<Response> => {
|
|
const { handle } = await import("../apps/web/src/server/router")
|
|
return handle(new Request(`https://app.example.test${path}`, init))
|
|
}
|
|
|
|
beforeEach(() => {
|
|
app.runtime = {
|
|
env: { deployment: { CONUSAI_API_URL: "http://127.0.0.1:9/api" } },
|
|
observe: { log: { warn: () => undefined } },
|
|
registry: { kit: "0.1.0", procedures: new Map() },
|
|
}
|
|
})
|
|
|
|
describe("this app's mount", () => {
|
|
it("serves its OpenAPI document under the app brand's name", async () => {
|
|
const document = (await (await handled("/api/openapi.json")).json()) as { info: { title: string } }
|
|
expect(document.info.title).toBe(`${appBrand.name} API`)
|
|
})
|
|
|
|
it("hands the live stream to the app's own server", async () => {
|
|
const answer = await handled("/api/v1/orgs/acme/live", { method: "POST" })
|
|
expect(await answer.text()).toBe("the live stream")
|
|
})
|
|
|
|
it.runIf(PROFILE === "postgres")("answers /api/ready from the host, 503 while it is not ready", async () => {
|
|
const answer = await handled("/api/ready")
|
|
expect(answer.status).toBe(503)
|
|
expect(await answer.json()).toEqual(app.ready)
|
|
})
|
|
})
|