1import * as AWS from "@/AWS";
2import { Schedule } from "@/AWS/DataBrew";
3import * as Test from "@/Test/Alchemy";
4import * as databrew from "@distilled.cloud/aws/databrew";
5import { expect } from "alchemy-test";
6import * as Effect from "effect/Effect";
7
8const { test } = Test.make({ providers: AWS.providers() });
9
10const getSchedule = (name: string) =>
11 databrew
12 .describeSchedule({ Name: name })
13 .pipe(
14 Effect.catchTag("ResourceNotFoundException", () =>
15 Effect.succeed(undefined),
16 ),
17 );
18
19const withSchedule = (cronExpression: string) =>
20 Effect.gen(function* () {
21 const schedule = yield* Schedule("Nightly", {
22 cronExpression,
23 tags: { Environment: "test" },
24 });
25 return { schedule };
26 });
27
28test.provider(
29 "create, update, delete a schedule",
30 (stack) =>
31 Effect.gen(function* () {
32 yield* stack.destroy();
33
34 const created = yield* stack.deploy(withSchedule("cron(0 3 * * ? *)"));
35 expect(created.schedule.scheduleArn).toContain(
36 `:schedule/${created.schedule.scheduleName}`,
37 );
38
39 // out-of-band verification
40 const observed = yield* getSchedule(created.schedule.scheduleName);
41 expect(observed?.CronExpression).toEqual("cron(0 3 * * ? *)");
42 expect(observed?.Tags?.["alchemy::id"]).toBeDefined();
43 expect(observed?.Tags?.Environment).toEqual("test");
44
45 // update: new cron expression (same logical resource)
46 yield* stack.deploy(withSchedule("cron(30 4 * * ? *)"));
47 const updated = yield* getSchedule(created.schedule.scheduleName);
48 expect(updated?.CronExpression).toEqual("cron(30 4 * * ? *)");
49
50 yield* stack.destroy();
51 expect(yield* getSchedule(created.schedule.scheduleName)).toBeUndefined();
52 }),
53 { tags: ["provider:aws", "provider:aws:databrew", "live"], timeout: 120_000 },
54);