1import * as AWS from "@/AWS";
2import { Dashboard } from "@/AWS/CloudWatch/Dashboard.ts";
3import * as Provider from "@/Provider";
4import * as Test from "@/Test/Alchemy";
5import * as cloudwatch from "@distilled.cloud/aws/cloudwatch";
6import { expect } from "alchemy-test";
7import * as Effect from "effect/Effect";
8
9const { test } = Test.make({ providers: AWS.providers() });
10
11// Canonical `list()` test (AWS account/region-scoped collection): deploy a
12// real dashboard, resolve the provider from context via `findProvider`, call
13// `list()`, and assert the deployed dashboard appears in the exhaustively-
14// paginated result.
15test.provider(
16 "list enumerates the deployed dashboard",
17 (stack) =>
18 Effect.gen(function* () {
19 yield* stack.destroy();
20
21 const dashboard = yield* stack.deploy(
22 Effect.gen(function* () {
23 return yield* Dashboard("ListDashboard", {
24 name: "alchemy-test-dashboard-list",
25 DashboardBody: {
26 widgets: [
27 {
28 type: "text",
29 x: 0,
30 y: 0,
31 width: 6,
32 height: 3,
33 properties: { markdown: "# list test" },
34 },
35 ],
36 },
37 });
38 }),
39 );
40
41 const provider = yield* Provider.findProvider(Dashboard);
42 const all = yield* provider.list();
43
44 expect(all.some((d) => d.dashboardName === dashboard.dashboardName)).toBe(
45 true,
46 );
47
48 yield* stack.destroy();
49
50 // Out-of-band assert-gone: getDashboard returns the typed
51 // DashboardNotFoundError once the dashboard is deleted.
52 const gone = yield* cloudwatch
53 .getDashboard({ DashboardName: dashboard.dashboardName })
54 .pipe(
55 Effect.map(() => false),
56 Effect.catchTag("DashboardNotFoundError", () => Effect.succeed(true)),
57 );
58 expect(gone).toBe(true);
59 }),
60 { tags: ["provider:aws", "provider:aws:cloudwatch", "live"] },
61);