| 1 | import * as AWS from "@/AWS"; |
| 2 | import { Rule } from "@/AWS/EventBridge/Rule.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 describeRule until ResourceNotFoundException. */ |
| 13 | const assertRuleGone = Effect.fn(function* (name: string) { |
| 14 | const gone = yield* eventbridge.describeRule({ 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 across all |
| 27 | // event buses): deploy a real rule, resolve the provider from context via the |
| 28 | // typed `findProvider`, call `list()`, and assert the deployed rule appears in |
| 29 | // the exhaustively-paginated result. |
| 30 | test.provider( |
| 31 | "list enumerates the deployed rule", |
| 32 | (stack) => |
| 33 | Effect.gen(function* () { |
| 34 | yield* stack.destroy(); |
| 35 | |
| 36 | const rule = yield* stack.deploy( |
| 37 | Effect.gen(function* () { |
| 38 | return yield* Rule("ListRule", { |
| 39 | name: "alchemy-test-rule-list", |
| 40 | scheduleExpression: "rate(5 minutes)", |
| 41 | }); |
| 42 | }), |
| 43 | ); |
| 44 | |
| 45 | const provider = yield* Provider.findProvider(Rule); |
| 46 | const all = yield* provider.list(); |
| 47 | |
| 48 | expect(all.some((r) => r.ruleName === rule.ruleName)).toBe(true); |
| 49 | expect( |
| 50 | all.some( |
| 51 | (r) => |
| 52 | r.ruleName === rule.ruleName && |
| 53 | r.eventBusName === rule.eventBusName, |
| 54 | ), |
| 55 | ).toBe(true); |
| 56 | |
| 57 | yield* stack.destroy(); |
| 58 | |
| 59 | yield* assertRuleGone("alchemy-test-rule-list"); |
| 60 | }), |
| 61 | { |
| 62 | tags: ["provider:aws", "provider:aws:eventbridge", "live"], |
| 63 | timeout: 120_000, |
| 64 | }, |
| 65 | ); |