| 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 | // Account singleton: an AWS Organization has no list API. `list()` calls |
| 10 | // `describeOrganization` and returns the single org as a one-element array, or |
| 11 | // `[]` when the account isn't a management account (the typed |
| 12 | // `AWSOrganizationsNotInUseException` is caught to `[]`). This runs read-only — |
| 13 | // it neither creates nor deletes an organization. |
| 14 | test.provider( |
| 15 | "list returns the organization singleton", |
| 16 | (stack) => |
| 17 | Effect.gen(function* () { |
| 18 | const provider = yield* Provider.findProvider( |
| 19 | AWS.Organizations.Organization, |
| 20 | ); |
| 21 | const all = yield* provider.list(); |
| 22 | |
| 23 | // 0 (account is not a management account) or 1 (it is) — never more. |
| 24 | expect(all.length).toBeLessThanOrEqual(1); |
| 25 | |
| 26 | // When the account is an organization management account, the single |
| 27 | // entry carries a well-typed Attributes shape. |
| 28 | if (all.length === 1) { |
| 29 | const org = all[0]; |
| 30 | expect(typeof org.organizationId).toBe("string"); |
| 31 | expect(org.organizationId.length).toBeGreaterThan(0); |
| 32 | expect(typeof org.organizationArn).toBe("string"); |
| 33 | expect(org.organizationArn.startsWith("arn:aws:organizations::")).toBe( |
| 34 | true, |
| 35 | ); |
| 36 | expect(Array.isArray(org.availablePolicyTypes)).toBe(true); |
| 37 | if (org.managementAccountEmail != null) { |
| 38 | expect(typeof org.managementAccountEmail).toBe("string"); |
| 39 | expect(org.managementAccountEmail.length).toBeGreaterThan(0); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | yield* stack.destroy(); |
| 44 | }), |
| 45 | { tags: ["provider:aws", "provider:aws:organizations", "live"] }, |
| 46 | ); |