| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as cci from "@distilled.cloud/gcp/contactcenterinsights_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService( |
| 13 | MinimumLogLevel, |
| 14 | process.env.DEBUG ? "Debug" : "Info", |
| 15 | ); |
| 16 | |
| 17 | const waitUntilGone = (name: string) => |
| 18 | cci.getProjectsLocationsDashboards({ 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 | |
| 28 | test.provider( |
| 29 | "getProjectsLocationsDashboards on a missing dashboard 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 | cci.getProjectsLocationsDashboards({ |
| 37 | name: `projects/${project}/locations/us-central1/dashboards/alchemy-missing-dashboard`, |
| 38 | }), |
| 39 | ); |
| 40 | expect(error._tag).toEqual("NotFound"); |
| 41 | |
| 42 | yield* stack.destroy(); |
| 43 | }).pipe(logLevel), |
| 44 | { |
| 45 | tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"], |
| 46 | timeout: 90_000, |
| 47 | }, |
| 48 | ); |
| 49 | |
| 50 | // The testing project rejects every dashboard create with BadRequest |
| 51 | // "Request contains an invalid argument." Set GCP_TEST_CCI_DASHBOARDS=1 on |
| 52 | // a project where CCI dashboards are available. |
| 53 | test.provider.skipIf( |
| 54 | !!process.env.FAST || !process.env.GCP_TEST_CCI_DASHBOARDS, |
| 55 | )( |
| 56 | "create, update, and delete a dashboard", |
| 57 | (stack) => |
| 58 | Effect.gen(function* () { |
| 59 | yield* stack.destroy(); |
| 60 | |
| 61 | const created = yield* stack.deploy( |
| 62 | Effect.gen(function* () { |
| 63 | return yield* GCP.ContactCenterInsights.Dashboard("Overview", { |
| 64 | location: "us-central1", |
| 65 | displayName: "overview", |
| 66 | description: "call quality", |
| 67 | }); |
| 68 | }), |
| 69 | ); |
| 70 | |
| 71 | expect(created.name).toContain("/dashboards/"); |
| 72 | expect(created.displayName).toEqual("overview"); |
| 73 | expect(created.description).toEqual("call quality"); |
| 74 | |
| 75 | const fetched = yield* cci.getProjectsLocationsDashboards({ |
| 76 | name: created.name, |
| 77 | }); |
| 78 | expect(fetched.name).toEqual(created.name); |
| 79 | expect(fetched.description).toContain("alchemy-id="); |
| 80 | |
| 81 | const updated = yield* stack.deploy( |
| 82 | Effect.gen(function* () { |
| 83 | return yield* GCP.ContactCenterInsights.Dashboard("Overview", { |
| 84 | location: "us-central1", |
| 85 | dashboardId: created.dashboardId, |
| 86 | displayName: "overview-v2", |
| 87 | description: "updated quality", |
| 88 | }); |
| 89 | }), |
| 90 | ); |
| 91 | expect(updated.name).toEqual(created.name); |
| 92 | expect(updated.displayName).toEqual("overview-v2"); |
| 93 | expect(updated.description).toEqual("updated quality"); |
| 94 | |
| 95 | yield* stack.destroy(); |
| 96 | const gone = yield* waitUntilGone(created.name); |
| 97 | expect(gone).toEqual("gone"); |
| 98 | }).pipe(logLevel), |
| 99 | { |
| 100 | tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"], |
| 101 | timeout: 90_000, |
| 102 | }, |
| 103 | ); |