| 1 | import * as Axiom from "@/Axiom"; |
| 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: Axiom.providers() }); |
| 9 | |
| 10 | const logLevel = Effect.provideService( |
| 11 | MinimumLogLevel, |
| 12 | process.env.DEBUG ? "Debug" : "Info", |
| 13 | ); |
| 14 | |
| 15 | // Axiom credentials are resolved via the AuthProvider (env method reads |
| 16 | // AXIOM_TOKEN / AXIOM_API_KEY). When neither is present the suite can't talk |
| 17 | // to the real API, so skipIf-gate the live list test. On an entitled run the |
| 18 | // failure mode without creds is an `AuthError`: |
| 19 | // "Axiom env credentials not found. Set AXIOM_TOKEN (or AXIOM_API_KEY)." |
| 20 | const hasAxiomCreds = !!(process.env.AXIOM_TOKEN || process.env.AXIOM_API_KEY); |
| 21 | |
| 22 | // Deterministic notifier name so re-runs reconcile the same notifier rather |
| 23 | // than piling up duplicates. |
| 24 | const NOTIFIER_NAME = "alchemy-test-notifier-list"; |
| 25 | |
| 26 | test.provider.skipIf(!hasAxiomCreds)( |
| 27 | "list enumerates the deployed notifier", |
| 28 | (stack) => |
| 29 | Effect.gen(function* () { |
| 30 | yield* stack.destroy(); |
| 31 | |
| 32 | const deployed = yield* stack.deploy( |
| 33 | Effect.gen(function* () { |
| 34 | return yield* Axiom.Notifier("ListNotifier", { |
| 35 | name: NOTIFIER_NAME, |
| 36 | properties: { |
| 37 | email: { emails: ["sre@example.com"] }, |
| 38 | }, |
| 39 | }); |
| 40 | }), |
| 41 | ); |
| 42 | |
| 43 | const provider = yield* Provider.findProvider(Axiom.Notifier); |
| 44 | const all = yield* provider.list(); |
| 45 | |
| 46 | // `getNotifiers` returns the full account-wide list in one shot; the |
| 47 | // freshly created notifier must be present, hydrated into the exact |
| 48 | // `read` shape (so `.id` / `.name` are directly usable by `delete`). |
| 49 | const found = all.find((n) => n.id === deployed.id); |
| 50 | expect(found).toBeDefined(); |
| 51 | expect(found?.name).toEqual(NOTIFIER_NAME); |
| 52 | |
| 53 | yield* stack.destroy(); |
| 54 | }).pipe(logLevel), |
| 55 | { |
| 56 | tags: ["provider:axiom", "provider:axiom:notifier", "live"], |
| 57 | timeout: 120_000, |
| 58 | }, |
| 59 | ); |