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.getProjectsLocationsViews({ 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 "getProjectsLocationsViews on a missing view 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.getProjectsLocationsViews({
37 name: `projects/${project}/locations/us-central1/views/alchemy-missing-view`,
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
50test.provider.skipIf(!!process.env.FAST)(
51 "create, update, and delete a view",
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.View("Chat", {
59 location: "us-central1",
60 displayName: "chat",
61 value: 'medium="CHAT"',
62 });
63 }),
64 );
65
66 expect(created.name).toContain("/views/");
67 expect(created.location).toEqual("us-central1");
68 expect(created.displayName).toEqual("chat");
69 expect(created.value).toEqual('medium="CHAT"');
70
71 const fetched = yield* cci.getProjectsLocationsViews({
72 name: created.name,
73 });
74 expect(fetched.name).toEqual(created.name);
75 expect(fetched.displayName).toContain("alchemy-id=");
76
77 const updated = yield* stack.deploy(
78 Effect.gen(function* () {
79 return yield* GCP.ContactCenterInsights.View("Chat", {
80 viewId: created.viewId,
81 location: "us-central1",
82 displayName: "phone",
83 value: 'medium="PHONE_CALL"',
84 });
85 }),
86 );
87
88 expect(updated.name).toEqual(created.name);
89 expect(updated.displayName).toEqual("phone");
90 expect(updated.value).toEqual('medium="PHONE_CALL"');
91
92 const fetchedUpdate = yield* cci.getProjectsLocationsViews({
93 name: updated.name,
94 });
95 expect(fetchedUpdate.value).toEqual('medium="PHONE_CALL"');
96
97 yield* stack.destroy();
98 const gone = yield* waitUntilGone(created.name);
99 expect(gone).toEqual("gone");
100 }).pipe(logLevel),
101 {
102 tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"],
103 timeout: 90_000,
104 },
105);