t3-code-android-nightly/.repos/effect-smol/packages/effect/test/http/HttpServerRespondable.test.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

22 lines
967 B
TypeScript

import { describe, it } from "@effect/vitest"
import { strictEqual } from "@effect/vitest/utils"
import { Effect, Schema } from "effect"
import { HttpServerRespondable, HttpServerResponse } from "effect/http"
describe("HttpServerRespondable", () => {
it.effect("maps SchemaError to a 400 response", () =>
Effect.gen(function*() {
const error = yield* Effect.flip(Schema.decodeUnknownEffect(Schema.String)(123))
strictEqual(Schema.isSchemaError(error), true)
const fallback = HttpServerResponse.empty({ status: 500 })
const response = yield* HttpServerRespondable.toResponseOrElse(error, fallback)
strictEqual(response.status, 400)
}))
it.effect("falls back for other errors", () =>
Effect.gen(function*() {
const fallback = HttpServerResponse.empty({ status: 500 })
const response = yield* HttpServerRespondable.toResponseOrElse(new Error("boom"), fallback)
strictEqual(response, fallback)
}))
})