1import * as AWS from "@/AWS";
2import { ActiveReceiptRuleSet, ReceiptRuleSet } from "@/AWS/SES";
3import * as Test from "@/Test/Alchemy";
4import * as ses from "@distilled.cloud/aws/ses";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7
8const { test } = Test.make({ providers: AWS.providers() });
9
10const activeRuleSetName = ses
11 .describeActiveReceiptRuleSet({})
12 .pipe(Effect.map((response) => response.Metadata?.Name));
13
14// Account-singleton pointer: capture whatever the account currently points at,
15// run the lifecycle, then restore it. `exclusive` takes the whole-process lock
16// so no other test observes the mutated active pointer.
17test.provider(
18 "active receipt rule set: point the account at a rule set, then deactivate",
19 (stack) =>
20 Effect.gen(function* () {
21 const captured = yield* activeRuleSetName;
22
23 yield* Effect.gen(function* () {
24 yield* stack.destroy();
25
26 const { ruleSet } = yield* stack.deploy(
27 Effect.gen(function* () {
28 const ruleSet = yield* ReceiptRuleSet("ActiveSet", {});
29 yield* ActiveReceiptRuleSet("Active", {
30 ruleSetName: ruleSet.ruleSetName,
31 });
32 return { ruleSet };
33 }),
34 );
35
36 // out-of-band verification via distilled: the account now points here
37 const active = yield* activeRuleSetName;
38 expect(active).toBe(ruleSet.ruleSetName);
39
40 yield* stack.destroy();
41
42 // deleting our pointer deactivated receiving (we still owned it)
43 const afterDestroy = yield* activeRuleSetName;
44 expect(afterDestroy).not.toBe(ruleSet.ruleSetName);
45 }).pipe(
46 Effect.ensuring(
47 captured
48 ? ses
49 .setActiveReceiptRuleSet({ RuleSetName: captured })
50 .pipe(Effect.ignore)
51 : Effect.void,
52 ),
53 );
54 }),
55 {
56 tags: ["provider:aws", "provider:aws:ses", "live"],
57 timeout: 120_000,
58 exclusive: true,
59 },
60);