1import * as Cloudflare from "@/Cloudflare";
2import * as Provider from "@/Provider";
3import * as Test from "@/Test/Alchemy";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import { MinimumLogLevel } from "effect/References";
7
8const { test } = Test.make({ providers: Cloudflare.providers() });
9
10const logLevel = Effect.provideService(
11 MinimumLogLevel,
12 process.env.DEBUG ? "Debug" : "Info",
13);
14
15// Canonical `list()` test (account-scoped collection): deploy a real D1
16// database, resolve the provider from context via the typed
17// `Provider.findProvider`, call `list()`, and assert the deployed database
18// appears in the exhaustively-paginated result.
19test.provider(
20 "list enumerates the deployed database",
21 (stack) =>
22 Effect.gen(function* () {
23 yield* stack.destroy();
24
25 const database = yield* stack.deploy(
26 Effect.gen(function* () {
27 return yield* Cloudflare.D1.Database("ListDatabase");
28 }),
29 );
30
31 const provider = yield* Provider.findProvider(Cloudflare.D1.Database);
32 const all = yield* provider.list();
33
34 expect(all.some((db) => db.databaseId === database.databaseId)).toBe(
35 true,
36 );
37
38 yield* stack.destroy();
39 }).pipe(logLevel),
40 { tags: ["provider:cloudflare", "provider:cloudflare:d1", "live"] },
41);