workerd.test.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import { expect } from "bun:test"
  2. import { Effect } from "effect"
  3. import { makeDurableObjectStorage } from "../../core/test/fixture/durable-object-storage"
  4. import { it } from "../../core/test/lib/effect"
  5. import { ServerWorkerd } from "../src/workerd"
  6. // Covers the profile's replacement graph composing and the database booting
  7. // through the injected Durable Object storage.
  8. it.live("boots the workerd profile over durable object storage", () =>
  9. Effect.gen(function* () {
  10. const handler = yield* ServerWorkerd.create({
  11. storage: makeDurableObjectStorage(),
  12. password: "secret",
  13. app: { version: "workerd-test" },
  14. config: { content: "{}" },
  15. })
  16. const unauthorized = yield* Effect.promise(() => handler(new Request("http://opencode.local/api/health")))
  17. expect(unauthorized.status).toBe(401)
  18. const health = yield* Effect.promise(() =>
  19. handler(
  20. new Request("http://opencode.local/api/health", {
  21. headers: { authorization: `Basic ${btoa("opencode:secret")}` },
  22. }),
  23. ),
  24. )
  25. expect(health.status).toBe(200)
  26. const body: unknown = yield* Effect.promise(() => health.json())
  27. expect(body).toMatchObject({ healthy: true, version: "workerd-test" })
  28. }).pipe(Effect.scoped),
  29. )