The best way to control Claude Code, Codex and more from any computer or phone

main
ts 58 lines 2.35 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Account } from "@alchemy.run/aws/Organizations";
3 import { expect } from "@alchemy.run/test";
4 import * as Provider from "alchemy/Provider";
5 import * as Effect from "effect/Effect";
6 import * as OrganizationLease from "./OrganizationLease.ts";
7
8 const { test } = OrganizationLease.make({ providers: AWS.providers() }, "shared");
9
10 // Organizations APIs require the caller to be the MANAGEMENT account of an AWS
11 // Organization, and creating member accounts is slow + irreversible. So this is
12 // a read-only `list()` test: resolve the typed provider, call `list()`, and
13 // assert it returns a well-typed `Attributes[]` (the same shape `read`
14 // produces).
15 //
16 // `list()` catches `AWSOrganizationsNotInUseException` and returns `[]` when the
17 // testing account is not an organization management account, so this passes on a
18 // standalone account too. When run against a management account
19 // (`AWS_TEST_ORG_MANAGEMENT=1`) it additionally asserts at least one account
20 // (the management account itself) appears.
21 test.provider(
22 "list enumerates organization accounts",
23 () =>
24 Effect.gen(function* () {
25 const provider = yield* Provider.findProvider(Account);
26 const all = yield* provider.list();
27
28 expect(Array.isArray(all)).toBe(true);
29 for (const account of all) {
30 expect(typeof account.accountId).toBe("string");
31 expect(typeof account.accountArn).toBe("string");
32 expect(account.tags).toBeDefined();
33 if (account.name != null) {
34 expect(typeof account.name).toBe("string");
35 }
36 if (account.email != null) {
37 expect(typeof account.email).toBe("string");
38 }
39 }
40
41 if (process.env.AWS_TEST_ORG_MANAGEMENT) {
42 expect(all.length).toBeGreaterThan(0);
43 const management = all.find(
44 (account) =>
45 typeof account.name === "string" &&
46 account.name.length > 0 &&
47 typeof account.email === "string" &&
48 account.email.length > 0,
49 );
50 expect(management).toBeDefined();
51 expect(typeof management?.name).toBe("string");
52 expect(management!.name!.length).toBeGreaterThan(0);
53 expect(typeof management?.email).toBe("string");
54 expect(management!.email!.length).toBeGreaterThan(0);
55 }
56 }),
57 { tags: ["provider:aws", "provider:aws:organizations", "live"] },
58 );