1import * as AWS from "@/AWS";
2import { Group } from "@/AWS/IdentityCenter";
3import * as Provider from "@/Provider";
4import * as Test from "@/Test/Alchemy";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7
8const { test } = Test.make({ providers: AWS.providers() });
9
10// Identity Center requires an enabled SSO instance / identity store in the
11// testing account. If unavailable, `resolveIdentityStoreId` fails with:
12// Error: "Unable to resolve a single visible Identity Center instance; pass instanceArn explicitly"
13// The testing account is an organization management account where
14// `CreateInstance` fails with a typed ValidationException ("Organization
15// management account is not allowed to perform the operation."), so an
16// instance cannot be provisioned programmatically. Gate the live list test
17// behind ALCHEMY_TEST_IDENTITY_CENTER=1 so an entitled account runs it
18// unchanged.
19const SKIP_IDENTITY_CENTER = !process.env.ALCHEMY_TEST_IDENTITY_CENTER;
20
21// Canonical `list()` test (AWS account-scoped collection within the identity
22// store): deploy a real group, resolve the provider from context via the typed
23// `findProvider`, call `list()`, and assert the deployed group appears in the
24// exhaustively-paginated result.
25test.provider.skipIf(SKIP_IDENTITY_CENTER)(
26 "list enumerates the deployed group",
27 (stack) =>
28 Effect.gen(function* () {
29 yield* stack.destroy();
30
31 const group = yield* stack.deploy(
32 Effect.gen(function* () {
33 return yield* Group("ListGroup", {
34 displayName: "alchemy-list-test-group",
35 description: "Group used to verify list() enumeration",
36 });
37 }),
38 );
39
40 const provider = yield* Provider.findProvider(Group);
41 const all = yield* provider.list();
42
43 expect(all.some((g) => g.groupId === group.groupId)).toBe(true);
44
45 yield* stack.destroy();
46 }),
47 {
48 tags: ["provider:aws", "provider:aws:identitycenter", "live"],
49 timeout: 180_000,
50 },
51);