| 1 | import * as Cloudflare from "@/Cloudflare"; |
| 2 | import * as Provider from "@/Provider"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: Cloudflare.providers() }); |
| 9 | |
| 10 | const 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. |
| 19 | test.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 | ); |