The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as GCP from "@alchemy.run/gcp"; |
| 2 | import { GcpEnvironment } from "@alchemy.run/gcp/Environment"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as healthcare from "@distilled.cloud/gcp/healthcare_v1"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import { MinimumLogLevel } from "effect/References"; |
| 8 | import * as Schedule from "effect/Schedule"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 13 | |
| 14 | const waitUntilGone = (name: string) => |
| 15 | healthcare.getProjectsLocationsDatasetsConsentStoresConsents({ name }).pipe( |
| 16 | Effect.as("found" as const), |
| 17 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 18 | Effect.repeat({ |
| 19 | schedule: Schedule.spaced("1 second"), |
| 20 | until: (status) => status === "gone", |
| 21 | times: 10, |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | test.provider( |
| 26 | "getProjectsLocationsDatasetsConsentStoresConsents on a missing consent fails with a typed tag", |
| 27 | (stack) => |
| 28 | Effect.gen(function* () { |
| 29 | const { project } = yield* GcpEnvironment.current; |
| 30 | yield* stack.destroy(); |
| 31 | |
| 32 | const error = yield* Effect.flip( |
| 33 | healthcare.getProjectsLocationsDatasetsConsentStoresConsents({ |
| 34 | name: `projects/${project}/locations/us-central1/datasets/missing/consentStores/missing/consents/alchemy-missing`, |
| 35 | }), |
| 36 | ); |
| 37 | expect(error._tag).toEqual("NotFound"); |
| 38 | |
| 39 | yield* stack.destroy(); |
| 40 | }).pipe(logLevel), |
| 41 | { |
| 42 | tags: ["provider:gcp", "provider:gcp:healthcare", "live"], |
| 43 | timeout: 90_000, |
| 44 | }, |
| 45 | ); |
| 46 | |
| 47 | test.provider( |
| 48 | "create, update, and delete a consent", |
| 49 | (stack) => |
| 50 | Effect.gen(function* () { |
| 51 | yield* stack.destroy(); |
| 52 | |
| 53 | const created = yield* stack.deploy( |
| 54 | Effect.gen(function* () { |
| 55 | const dataset = yield* GCP.Healthcare.Dataset("ConsentClinic", { |
| 56 | location: "us-central1", |
| 57 | }); |
| 58 | const store = yield* GCP.Healthcare.DatasetsConsentStore("Consents", { |
| 59 | dataset: dataset.name, |
| 60 | labels: { env: "test" }, |
| 61 | }); |
| 62 | const artifact = yield* GCP.Healthcare.DatasetsConsentStoresConsentArtifact("Proof", { |
| 63 | consentStore: store.name, |
| 64 | userId: "user-123", |
| 65 | consentContentVersion: "v1", |
| 66 | }); |
| 67 | const consent = yield* GCP.Healthcare.DatasetsConsentStoresConsent("Grant", { |
| 68 | consentStore: store.name, |
| 69 | userId: "user-123", |
| 70 | consentArtifact: artifact.name, |
| 71 | state: "DRAFT", |
| 72 | metadata: { source: "app" }, |
| 73 | }); |
| 74 | return { dataset, store, artifact, consent }; |
| 75 | }), |
| 76 | ); |
| 77 | |
| 78 | expect(created.consent.name).toContain("/consents/"); |
| 79 | expect(created.consent.userId).toEqual("user-123"); |
| 80 | expect(created.consent.state).toEqual("DRAFT"); |
| 81 | expect(created.consent.metadata).toMatchObject({ source: "app" }); |
| 82 | |
| 83 | const fetched = yield* healthcare.getProjectsLocationsDatasetsConsentStoresConsents({ |
| 84 | name: created.consent.name, |
| 85 | }); |
| 86 | expect(fetched.name).toEqual(created.consent.name); |
| 87 | expect(fetched.state).toEqual("DRAFT"); |
| 88 | expect(fetched.metadata?.source).toEqual("app"); |
| 89 | expect(fetched.metadata?.["alchemy-id"]).toEqual(expect.any(String)); |
| 90 | |
| 91 | const updated = yield* stack.deploy( |
| 92 | Effect.gen(function* () { |
| 93 | const dataset = yield* GCP.Healthcare.Dataset("ConsentClinic", { |
| 94 | datasetId: created.dataset.datasetId, |
| 95 | location: "us-central1", |
| 96 | }); |
| 97 | const store = yield* GCP.Healthcare.DatasetsConsentStore("Consents", { |
| 98 | dataset: dataset.name, |
| 99 | consentStoreId: created.store.consentStoreId, |
| 100 | labels: { env: "test" }, |
| 101 | }); |
| 102 | const artifact = yield* GCP.Healthcare.DatasetsConsentStoresConsentArtifact("Proof", { |
| 103 | consentStore: store.name, |
| 104 | userId: "user-123", |
| 105 | consentContentVersion: "v1", |
| 106 | }); |
| 107 | const consent = yield* GCP.Healthcare.DatasetsConsentStoresConsent("Grant", { |
| 108 | consentStore: store.name, |
| 109 | userId: "user-123", |
| 110 | consentArtifact: artifact.name, |
| 111 | state: "DRAFT", |
| 112 | metadata: { source: "portal" }, |
| 113 | }); |
| 114 | return { dataset, store, artifact, consent }; |
| 115 | }), |
| 116 | ); |
| 117 | |
| 118 | expect(updated.consent.name).toEqual(created.consent.name); |
| 119 | expect(updated.consent.metadata).toMatchObject({ source: "portal" }); |
| 120 | |
| 121 | yield* stack.destroy(); |
| 122 | const gone = yield* waitUntilGone(created.consent.name); |
| 123 | expect(gone).toEqual("gone"); |
| 124 | }).pipe(logLevel), |
| 125 | { |
| 126 | tags: ["provider:gcp", "provider:gcp:healthcare", "live"], |
| 127 | timeout: 120_000, |
| 128 | }, |
| 129 | ); |