1import * as AWS from "@/AWS";
2import { Role } from "@/AWS/IAM";
3import { Schedule } from "@/AWS/Scheduler/Schedule.ts";
4import { Queue } from "@/AWS/SQS/Queue.ts";
5import * as Provider from "@/Provider";
6import * as Test from "@/Test/Alchemy";
7import { expect } from "alchemy-test";
8import * as Effect from "effect/Effect";
9
10const { test } = Test.make({ providers: AWS.providers() });
11
12// Canonical `list()` test (AWS account/region-scoped collection across all
13// schedule groups): deploy a real schedule (with the IAM role + SQS target it
14// requires), resolve the provider from context via the typed `findProvider`,
15// call `list()`, and assert the deployed schedule appears in the
16// exhaustively-paginated result.
17test.provider(
18 "list enumerates the deployed schedule",
19 (stack) =>
20 Effect.gen(function* () {
21 yield* stack.destroy();
22
23 // The Schedule provider internally retries the "execution role must allow
24 // EventBridge Scheduler to assume the role" ValidationException until the
25 // freshly-created IAM role propagates, so the deploy needs no retry here.
26 const deployed = yield* stack.deploy(
27 Effect.gen(function* () {
28 const queue = yield* Queue("ListScheduleQueue", {
29 queueName: "alchemy-test-schedule-list-queue",
30 });
31
32 const role = yield* Role("ListScheduleRole", {
33 roleName: "alchemy-test-schedule-list-role",
34 assumeRolePolicyDocument: {
35 Version: "2012-10-17",
36 Statement: [
37 {
38 Effect: "Allow",
39 Principal: { Service: "scheduler.amazonaws.com" },
40 Action: ["sts:AssumeRole"],
41 },
42 ],
43 },
44 inlinePolicies: {
45 ScheduleTarget: {
46 Version: "2012-10-17",
47 Statement: [
48 {
49 Effect: "Allow",
50 Action: ["sqs:SendMessage"],
51 Resource: [queue.queueArn],
52 },
53 ],
54 },
55 },
56 });
57
58 return yield* Schedule("ListSchedule", {
59 name: "alchemy-test-schedule-list",
60 scheduleExpression: "rate(1 hour)",
61 flexibleTimeWindow: { Mode: "OFF" },
62 target: {
63 Arn: queue.queueArn,
64 RoleArn: role.roleArn,
65 },
66 });
67 }),
68 );
69
70 const provider = yield* Provider.findProvider(Schedule);
71 const all = yield* provider.list();
72
73 expect(all.some((s) => s.scheduleName === deployed.scheduleName)).toBe(
74 true,
75 );
76 expect(
77 all.some(
78 (s) =>
79 s.scheduleName === deployed.scheduleName &&
80 s.scheduleArn === deployed.scheduleArn,
81 ),
82 ).toBe(true);
83
84 yield* stack.destroy();
85 }),
86 {
87 tags: [
88 "provider:aws",
89 "provider:aws:iam",
90 "provider:aws:scheduler",
91 "provider:aws:sqs",
92 "live",
93 ],
94 },
95);