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

60 lines
2 KiB
TypeScript

import * as AWS from "@/AWS";
import { ActiveReceiptRuleSet, ReceiptRuleSet } from "@/AWS/SES";
import * as Test from "@/Test/Alchemy";
import * as ses from "@distilled.cloud/aws/ses";
import { expect } from "alchemy-test";
import * as Effect from "effect/Effect";
const { test } = Test.make({ providers: AWS.providers() });
const activeRuleSetName = ses
.describeActiveReceiptRuleSet({})
.pipe(Effect.map((response) => response.Metadata?.Name));
// Account-singleton pointer: capture whatever the account currently points at,
// run the lifecycle, then restore it. `exclusive` takes the whole-process lock
// so no other test observes the mutated active pointer.
test.provider(
"active receipt rule set: point the account at a rule set, then deactivate",
(stack) =>
Effect.gen(function* () {
const captured = yield* activeRuleSetName;
yield* Effect.gen(function* () {
yield* stack.destroy();
const { ruleSet } = yield* stack.deploy(
Effect.gen(function* () {
const ruleSet = yield* ReceiptRuleSet("ActiveSet", {});
yield* ActiveReceiptRuleSet("Active", {
ruleSetName: ruleSet.ruleSetName,
});
return { ruleSet };
}),
);
// out-of-band verification via distilled: the account now points here
const active = yield* activeRuleSetName;
expect(active).toBe(ruleSet.ruleSetName);
yield* stack.destroy();
// deleting our pointer deactivated receiving (we still owned it)
const afterDestroy = yield* activeRuleSetName;
expect(afterDestroy).not.toBe(ruleSet.ruleSetName);
}).pipe(
Effect.ensuring(
captured
? ses
.setActiveReceiptRuleSet({ RuleSetName: captured })
.pipe(Effect.ignore)
: Effect.void,
),
);
}),
{
tags: ["provider:aws", "provider:aws:ses", "live"],
timeout: 120_000,
exclusive: true,
},
);