| 1 | import * as AWS from "@/AWS"; |
| 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 | |
| 7 | const { test } = Test.make({ providers: AWS.providers() }); |
| 8 | |
| 9 | // `Root` is import-only and there is exactly one organization root per |
| 10 | // management account. `list()` enumerates roots via `listRoots` (paginated) and |
| 11 | // hydrates each into the full Attributes shape, or returns `[]` when the account |
| 12 | // isn't an organization management account (the typed |
| 13 | // `AWSOrganizationsNotInUseException` / `AccessDeniedException` are caught to |
| 14 | // `[]`). This runs read-only — it neither creates nor deletes anything. |
| 15 | test.provider( |
| 16 | "list enumerates the organization root", |
| 17 | (stack) => |
| 18 | Effect.gen(function* () { |
| 19 | const provider = yield* Provider.findProvider(AWS.Organizations.Root); |
| 20 | const all = yield* provider.list(); |
| 21 | |
| 22 | // 0 (account is not a management account) or 1 (it is) — never more. |
| 23 | expect(all.length).toBeLessThanOrEqual(1); |
| 24 | |
| 25 | // When the account is an organization management account, the single entry |
| 26 | // carries a well-typed Attributes shape. |
| 27 | if (all.length === 1) { |
| 28 | const root = all[0]; |
| 29 | expect(typeof root.rootId).toBe("string"); |
| 30 | expect(root.rootId.length).toBeGreaterThan(0); |
| 31 | expect(typeof root.rootArn).toBe("string"); |
| 32 | expect(root.rootArn.startsWith("arn:aws:organizations::")).toBe(true); |
| 33 | expect(typeof root.rootName).toBe("string"); |
| 34 | expect(Array.isArray(root.policyTypes)).toBe(true); |
| 35 | expect(typeof root.tags).toBe("object"); |
| 36 | } |
| 37 | |
| 38 | yield* stack.destroy(); |
| 39 | }), |
| 40 | { tags: ["provider:aws", "provider:aws:organizations", "live"] }, |
| 41 | ); |