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 cci from "@distilled.cloud/gcp/contactcenterinsights_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 | cci.getProjectsLocationsDashboards({ 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 | "getProjectsLocationsDashboards on a missing dashboard 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 | cci.getProjectsLocationsDashboards({ |
| 34 | name: `projects/${project}/locations/us-central1/dashboards/alchemy-missing-dashboard`, |
| 35 | }), |
| 36 | ); |
| 37 | expect(error._tag).toEqual("NotFound"); |
| 38 | |
| 39 | yield* stack.destroy(); |
| 40 | }).pipe(logLevel), |
| 41 | { |
| 42 | tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"], |
| 43 | timeout: 90_000, |
| 44 | }, |
| 45 | ); |
| 46 | |
| 47 | // The testing project rejects every dashboard create with BadRequest |
| 48 | // "Request contains an invalid argument." Set GCP_TEST_CCI_DASHBOARDS=1 on |
| 49 | // a project where CCI dashboards are available. |
| 50 | test.provider.skipIf(!!process.env.FAST || !process.env.GCP_TEST_CCI_DASHBOARDS)( |
| 51 | "create, update, and delete a dashboard", |
| 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.ContactCenterInsights.Dashboard("Overview", { |
| 59 | location: "us-central1", |
| 60 | displayName: "overview", |
| 61 | description: "call quality", |
| 62 | }); |
| 63 | }), |
| 64 | ); |
| 65 | |
| 66 | expect(created.name).toContain("/dashboards/"); |
| 67 | expect(created.displayName).toEqual("overview"); |
| 68 | expect(created.description).toEqual("call quality"); |
| 69 | |
| 70 | const fetched = yield* cci.getProjectsLocationsDashboards({ |
| 71 | name: created.name, |
| 72 | }); |
| 73 | expect(fetched.name).toEqual(created.name); |
| 74 | expect(fetched.description).toContain("alchemy-id="); |
| 75 | |
| 76 | const updated = yield* stack.deploy( |
| 77 | Effect.gen(function* () { |
| 78 | return yield* GCP.ContactCenterInsights.Dashboard("Overview", { |
| 79 | location: "us-central1", |
| 80 | dashboardId: created.dashboardId, |
| 81 | displayName: "overview-v2", |
| 82 | description: "updated quality", |
| 83 | }); |
| 84 | }), |
| 85 | ); |
| 86 | expect(updated.name).toEqual(created.name); |
| 87 | expect(updated.displayName).toEqual("overview-v2"); |
| 88 | expect(updated.description).toEqual("updated quality"); |
| 89 | |
| 90 | yield* stack.destroy(); |
| 91 | const gone = yield* waitUntilGone(created.name); |
| 92 | expect(gone).toEqual("gone"); |
| 93 | }).pipe(logLevel), |
| 94 | { |
| 95 | tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"], |
| 96 | timeout: 90_000, |
| 97 | }, |
| 98 | ); |