test(server): use Layer.mock for partial Account service stub (#26472)

This commit is contained in:
Kit Langton
2026-05-09 00:05:05 -04:00
committed by GitHub
parent cbdb2d9825
commit 7f3e51453b
2 changed files with 21 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
import { afterEach, describe, expect, mock, test } from "bun:test"
import { Effect, Layer, Option } from "effect"
import { Effect, Layer } from "effect"
// Account.orgsByAccount() can fail with AccountServiceError when the
// upstream Anthropic Console API is unreachable. The HTTP API used to
@@ -17,22 +17,10 @@ import { Effect, Layer, Option } from "effect"
const ORIG = await import("../../src/account/account")
const failingAccountLayer = Layer.succeed(
ORIG.Service,
ORIG.Service.of({
active: () => Effect.succeed(Option.none()),
activeOrg: () => Effect.succeed(Option.none()),
list: () => Effect.succeed([]),
orgsByAccount: () => Effect.fail(new ORIG.AccountServiceError({ message: "simulated upstream failure" })),
remove: () => Effect.void,
use: () => Effect.void,
orgs: () => Effect.succeed([]),
config: () => Effect.succeed(Option.none()),
token: () => Effect.succeed(Option.none()),
login: () => Effect.fail(new ORIG.AccountServiceError({ message: "unused" })),
poll: () => Effect.fail(new ORIG.AccountServiceError({ message: "unused" })),
}),
)
const failingAccountLayer = Layer.mock(ORIG.Service, {
orgsByAccount: () =>
Effect.fail(new ORIG.AccountServiceError({ message: "simulated upstream failure" })),
})
const mocked = {
...ORIG,