t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/Cognito/UserPoolDomain.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

76 lines
2.6 KiB
TypeScript

import * as AWS from "@/AWS";
import { UserPool, UserPoolDomain } from "@/AWS/Cognito";
import * as Test from "@/Test/Alchemy";
import * as cip from "@distilled.cloud/aws/cognito-identity-provider";
import { expect } from "alchemy-test";
import * as Data from "effect/Data";
import * as Effect from "effect/Effect";
import * as Schedule from "effect/Schedule";
const { test } = Test.make({ providers: AWS.providers() });
class DomainStillExists extends Data.TaggedError("DomainStillExists")<{
readonly domain: string;
}> {}
const assertDomainDeleted = (domain: string) =>
cip.describeUserPoolDomain({ Domain: domain }).pipe(
Effect.flatMap((r) =>
r.DomainDescription?.UserPoolId === undefined
? Effect.void
: Effect.fail(new DomainStillExists({ domain })),
),
Effect.retry({
while: (e) => e._tag === "DomainStillExists",
schedule: Schedule.max([Schedule.exponential(500), Schedule.recurs(8)]),
}),
);
test.provider(
"cognito-prefix domain lifecycle",
(stack) =>
Effect.gen(function* () {
yield* stack.destroy();
const outputs = yield* stack.deploy(
Effect.gen(function* () {
const pool = yield* UserPool("DomainTestPool", {});
const domain = yield* UserPoolDomain("AuthDomain", {
userPoolId: pool.userPoolId,
});
return { pool, domain };
}),
);
expect(outputs.domain.domain).toMatch(/^[a-z0-9-]+$/);
expect(outputs.domain.domain).not.toContain("cognito");
expect(outputs.domain.domain).not.toContain("aws");
expect(outputs.domain.userPoolId).toBe(outputs.pool.userPoolId);
expect(outputs.domain.cloudFrontDomain).toBeTruthy();
// out-of-band verification via distilled
const described = yield* cip.describeUserPoolDomain({
Domain: outputs.domain.domain,
});
expect(described.DomainDescription?.UserPoolId).toBe(
outputs.pool.userPoolId,
);
expect(described.DomainDescription?.Status).toBe("ACTIVE");
// no-op deploy converges without error
const noop = yield* stack.deploy(
Effect.gen(function* () {
const pool = yield* UserPool("DomainTestPool", {});
const domain = yield* UserPoolDomain("AuthDomain", {
userPoolId: pool.userPoolId,
});
return { pool, domain };
}),
);
expect(noop.domain.domain).toBe(outputs.domain.domain);
yield* stack.destroy();
yield* assertDomainDeleted(outputs.domain.domain);
}),
{ tags: ["provider:aws", "provider:aws:cognito", "live"], timeout: 180_000 },
);