t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/Organizations/Organization.test.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

46 lines
1.8 KiB
TypeScript

import * as AWS from "@/AWS";
import * as Provider from "@/Provider";
import * as Test from "@/Test/Alchemy";
import { expect } from "alchemy-test";
import * as Effect from "effect/Effect";
const { test } = Test.make({ providers: AWS.providers() });
// Account singleton: an AWS Organization has no list API. `list()` calls
// `describeOrganization` and returns the single org as a one-element array, or
// `[]` when the account isn't a management account (the typed
// `AWSOrganizationsNotInUseException` is caught to `[]`). This runs read-only —
// it neither creates nor deletes an organization.
test.provider(
"list returns the organization singleton",
(stack) =>
Effect.gen(function* () {
const provider = yield* Provider.findProvider(
AWS.Organizations.Organization,
);
const all = yield* provider.list();
// 0 (account is not a management account) or 1 (it is) — never more.
expect(all.length).toBeLessThanOrEqual(1);
// When the account is an organization management account, the single
// entry carries a well-typed Attributes shape.
if (all.length === 1) {
const org = all[0];
expect(typeof org.organizationId).toBe("string");
expect(org.organizationId.length).toBeGreaterThan(0);
expect(typeof org.organizationArn).toBe("string");
expect(org.organizationArn.startsWith("arn:aws:organizations::")).toBe(
true,
);
expect(Array.isArray(org.availablePolicyTypes)).toBe(true);
if (org.managementAccountEmail != null) {
expect(typeof org.managementAccountEmail).toBe("string");
expect(org.managementAccountEmail.length).toBeGreaterThan(0);
}
}
yield* stack.destroy();
}),
{ tags: ["provider:aws", "provider:aws:organizations", "live"] },
);