1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as healthcare from "@distilled.cloud/gcp/healthcare_v1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import { MinimumLogLevel } from "effect/References";
7import * as Schedule from "effect/Schedule";
8import { GcpEnvironment } from "@/GCP/Environment";
9
10const { test } = Test.make({ providers: GCP.providers() });
11
12const logLevel = Effect.provideService(
13 MinimumLogLevel,
14 process.env.DEBUG ? "Debug" : "Info",
15);
16
17const waitUntilGone = (name: string) =>
18 healthcare.getProjectsLocationsDatasets({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("1 second"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28test.provider(
29 "getProjectsLocationsDatasets on a missing dataset fails with a typed tag",
30 (stack) =>
31 Effect.gen(function* () {
32 const { project } = yield* GcpEnvironment.current;
33 yield* stack.destroy();
34
35 const error = yield* Effect.flip(
36 healthcare.getProjectsLocationsDatasets({
37 name: `projects/${project}/locations/us-central1/datasets/alchemy-missing-dataset`,
38 }),
39 );
40 expect(error._tag).toEqual("NotFound");
41
42 yield* stack.destroy();
43 }).pipe(logLevel),
44 {
45 tags: ["provider:gcp", "provider:gcp:healthcare", "live"],
46 timeout: 90_000,
47 },
48);
49
50test.provider(
51 "create, update, and delete a healthcare dataset",
52 (stack) =>
53 Effect.gen(function* () {
54 yield* stack.destroy();
55
56 const created = yield* stack.deploy(
57 Effect.gen(function* () {
58 return yield* GCP.Healthcare.Dataset("Imaging", {
59 location: "us-central1",
60 timeZone: "America/New_York",
61 });
62 }),
63 );
64
65 expect(created.name).toContain("/datasets/");
66 expect(created.location).toEqual("us-central1");
67 expect(created.timeZone).toEqual("America/New_York");
68
69 const fetched = yield* healthcare.getProjectsLocationsDatasets({
70 name: created.name,
71 });
72 expect(fetched.name).toEqual(created.name);
73 expect(fetched.timeZone).toEqual("America/New_York");
74
75 const updated = yield* stack.deploy(
76 Effect.gen(function* () {
77 return yield* GCP.Healthcare.Dataset("Imaging", {
78 datasetId: created.datasetId,
79 location: "us-central1",
80 timeZone: "UTC",
81 });
82 }),
83 );
84
85 expect(updated.name).toEqual(created.name);
86 expect(updated.timeZone).toEqual("UTC");
87
88 yield* stack.destroy();
89 const gone = yield* waitUntilGone(created.name);
90 expect(gone).toEqual("gone");
91 }).pipe(logLevel),
92 {
93 tags: ["provider:gcp", "provider:gcp:healthcare", "live"],
94 timeout: 120_000,
95 },
96);