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.getProjectsLocationsAuthorizedViewSets({ 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 "getProjectsLocationsAuthorizedViewSets on a missing set 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.getProjectsLocationsAuthorizedViewSets({
37 name: `projects/${project}/locations/us-central1/authorizedViewSets/alchemy-missing-set`,
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// Needs Contact Center AI Insights features the testing project does not
51// have enabled: create returns 404 NOT_FOUND "Requested entity was not found." and list returns 400 INVALID_ARGUMENT.
52test.provider.skipIf(!process.env.GCP_TEST_CCAI_QUALITY || !!process.env.FAST)(
53 "create, update, and delete an authorized view set",
54 (stack) =>
55 Effect.gen(function* () {
56 yield* stack.destroy();
57
58 const created = yield* stack.deploy(
59 Effect.gen(function* () {
60 return yield* GCP.ContactCenterInsights.AuthorizedViewSet("QaViews", {
61 displayName: "qa",
62 });
63 }),
64 );
65
66 expect(created.authorizedViewSetId).toEqual(expect.any(String));
67 expect(created.name).toContain("/authorizedViewSets/");
68 expect(created.location).toEqual("us-central1");
69 expect(created.displayName).toEqual("qa");
70
71 const fetched = yield* cci.getProjectsLocationsAuthorizedViewSets({
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.AuthorizedViewSet("QaViews", {
80 authorizedViewSetId: created.authorizedViewSetId,
81 location: "us-central1",
82 displayName: "qa-v2",
83 });
84 }),
85 );
86
87 expect(updated.name).toEqual(created.name);
88 expect(updated.displayName).toEqual("qa-v2");
89
90 const fetchedUpdate = yield* cci.getProjectsLocationsAuthorizedViewSets({
91 name: updated.name,
92 });
93 expect(fetchedUpdate.displayName).toContain("qa-v2");
94
95 yield* stack.destroy();
96
97 const gone = yield* waitUntilGone(created.name);
98 expect(gone).toEqual("gone");
99 }).pipe(logLevel),
100 {
101 tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"],
102 timeout: 90_000,
103 },
104);