1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as cci from "@distilled.cloud/gcp/contactcenterinsights_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 cci.getProjectsLocationsDashboardsCharts({ 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 "getProjectsLocationsDashboardsCharts on a missing chart 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.getProjectsLocationsDashboardsCharts({
37 name: `projects/${project}/locations/us-central1/dashboards/missing/charts/missing`,
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.
53test.provider.skipIf(
54 !!process.env.FAST || !process.env.GCP_TEST_CCI_DASHBOARDS,
55)(
56 "create, update, and delete a dashboard chart",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 const created = yield* stack.deploy(
62 Effect.gen(function* () {
63 const dashboard = yield* GCP.ContactCenterInsights.Dashboard(
64 "Board",
65 {
66 location: "us-central1",
67 displayName: "chart-board",
68 },
69 );
70 return yield* GCP.ContactCenterInsights.DashboardsChart("Volume", {
71 parent: dashboard.name,
72 displayName: "volume",
73 description: "call volume",
74 chartVisualizationType: "BAR",
75 width: 2,
76 height: 2,
77 });
78 }),
79 );
80
81 expect(created.name).toContain("/charts/");
82 expect(created.displayName).toEqual("volume");
83 expect(created.description).toEqual("call volume");
84
85 const fetched = yield* cci.getProjectsLocationsDashboardsCharts({
86 name: created.name,
87 });
88 expect(fetched.name).toEqual(created.name);
89 expect(fetched.description).toContain("alchemy-id=");
90
91 const updated = yield* stack.deploy(
92 Effect.gen(function* () {
93 const dashboard = yield* GCP.ContactCenterInsights.Dashboard(
94 "Board",
95 {
96 location: "us-central1",
97 displayName: "chart-board",
98 },
99 );
100 return yield* GCP.ContactCenterInsights.DashboardsChart("Volume", {
101 parent: dashboard.name,
102 chartId: created.chartId,
103 displayName: "volume-v2",
104 description: "updated volume",
105 chartVisualizationType: "LINE",
106 width: 3,
107 height: 2,
108 });
109 }),
110 );
111 expect(updated.name).toEqual(created.name);
112 expect(updated.displayName).toEqual("volume-v2");
113 expect(updated.description).toEqual("updated volume");
114
115 yield* stack.destroy();
116 const gone = yield* waitUntilGone(created.name);
117 expect(gone).toEqual("gone");
118 }).pipe(logLevel),
119 {
120 tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"],
121 timeout: 90_000,
122 },
123);