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

101 lines
3.4 KiB
TypeScript

import * as AWS from "@/AWS";
import { RegexPatternSet } from "@/AWS/WAFv2";
import * as Test from "@/Test/Alchemy";
import * as wafv2 from "@distilled.cloud/aws/wafv2";
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 RegexPatternSetStillExists extends Data.TaggedError(
"RegexPatternSetStillExists",
)<{
readonly name: string;
}> {}
const assertDeleted = (name: string, id: string) =>
wafv2.getRegexPatternSet({ Name: name, Scope: "REGIONAL", Id: id }).pipe(
Effect.flatMap(() => Effect.fail(new RegexPatternSetStillExists({ name }))),
Effect.catchTag("WAFNonexistentItemException", () => Effect.void),
Effect.retry({
while: (e) => e._tag === "RegexPatternSetStillExists",
schedule: Schedule.max([Schedule.exponential(500), Schedule.recurs(8)]),
}),
);
test.provider(
"create, update expressions and tags, delete",
(stack) =>
Effect.gen(function* () {
// reconcile away any prior partial/crashed deployment
yield* stack.destroy();
const set = yield* stack.deploy(
Effect.gen(function* () {
return yield* RegexPatternSet("LifecycleRegexSet", {
regularExpressions: ["^/wp-admin", "\\.php$"],
description: "bad paths",
tags: { Environment: "test" },
});
}),
);
expect(set.scope).toBe("REGIONAL");
expect([...set.regularExpressions].sort()).toEqual([
"\\.php$",
"^/wp-admin",
]);
// out-of-band verification via distilled
const created = yield* wafv2.getRegexPatternSet({
Name: set.regexPatternSetName,
Scope: "REGIONAL",
Id: set.regexPatternSetId,
});
expect(
(created.RegexPatternSet?.RegularExpressionList ?? [])
.map((r) => r.RegexString)
.sort(),
).toEqual(["\\.php$", "^/wp-admin"]);
expect(created.RegexPatternSet?.Description).toBe("bad paths");
const tags = yield* wafv2.listTagsForResource({
ResourceARN: set.regexPatternSetArn,
});
const tagRecord = Object.fromEntries(
(tags.TagInfoForResource?.TagList ?? []).map((t) => [t.Key, t.Value]),
);
expect(tagRecord.Environment).toBe("test");
expect(tagRecord["alchemy::id"]).toBe("LifecycleRegexSet");
// expressions are mutable — updated in place
const updated = yield* stack.deploy(
Effect.gen(function* () {
return yield* RegexPatternSet("LifecycleRegexSet", {
regularExpressions: ["^/admin"],
description: "bad paths",
tags: { Environment: "test", Extra: "1" },
});
}),
);
expect(updated.regexPatternSetId).toBe(set.regexPatternSetId);
expect(updated.regularExpressions).toEqual(["^/admin"]);
const afterUpdate = yield* wafv2.getRegexPatternSet({
Name: set.regexPatternSetName,
Scope: "REGIONAL",
Id: set.regexPatternSetId,
});
expect(
(afterUpdate.RegexPatternSet?.RegularExpressionList ?? []).map(
(r) => r.RegexString,
),
).toEqual(["^/admin"]);
yield* stack.destroy();
yield* assertDeleted(set.regexPatternSetName, set.regexPatternSetId);
}),
{ tags: ["provider:aws", "provider:aws:wafv2", "live"], timeout: 120_000 },
);