| 1 | import * as AWS from "@/AWS"; |
| 2 | import { EventBus } from "@/AWS/EventBridge/EventBus.ts"; |
| 3 | import * as Provider from "@/Provider"; |
| 4 | import * as Test from "@/Test/Alchemy"; |
| 5 | import * as eventbridge from "@distilled.cloud/aws/eventbridge"; |
| 6 | import { expect } from "alchemy-test"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: AWS.providers() }); |
| 11 | |
| 12 | /** Typed wait-until-gone: poll describeEventBus until ResourceNotFoundException. */ |
| 13 | const assertBusGone = Effect.fn(function* (name: string) { |
| 14 | const gone = yield* eventbridge.describeEventBus({ Name: name }).pipe( |
| 15 | Effect.map(() => false), |
| 16 | Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(true)), |
| 17 | Effect.repeat({ |
| 18 | schedule: Schedule.spaced("2 seconds"), |
| 19 | until: (isGone): boolean => isGone, |
| 20 | times: 10, |
| 21 | }), |
| 22 | ); |
| 23 | expect(gone).toBe(true); |
| 24 | }); |
| 25 | |
| 26 | // Canonical `list()` test (AWS account/region-scoped collection): deploy a real |
| 27 | // event bus, resolve the provider from context via the typed `findProvider`, |
| 28 | // call `list()`, and assert the deployed bus appears in the |
| 29 | // exhaustively-paginated result. |
| 30 | test.provider( |
| 31 | "list enumerates the deployed event bus", |
| 32 | (stack) => |
| 33 | Effect.gen(function* () { |
| 34 | yield* stack.destroy(); |
| 35 | |
| 36 | const bus = yield* stack.deploy( |
| 37 | Effect.gen(function* () { |
| 38 | return yield* EventBus("ListEventBus", { |
| 39 | name: "alchemy-test-eventbus-list", |
| 40 | }); |
| 41 | }), |
| 42 | ); |
| 43 | |
| 44 | const provider = yield* Provider.findProvider(EventBus); |
| 45 | const all = yield* provider.list(); |
| 46 | |
| 47 | expect(all.some((b) => b.eventBusName === bus.eventBusName)).toBe(true); |
| 48 | // The AWS-managed `default` bus must be excluded. |
| 49 | expect(all.some((b) => b.eventBusName === "default")).toBe(false); |
| 50 | |
| 51 | yield* stack.destroy(); |
| 52 | |
| 53 | yield* assertBusGone("alchemy-test-eventbus-list"); |
| 54 | }), |
| 55 | { |
| 56 | tags: ["provider:aws", "provider:aws:eventbridge", "live"], |
| 57 | timeout: 120_000, |
| 58 | }, |
| 59 | ); |