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.getProjectsLocationsQaScorecardsRevisions({ 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 "getProjectsLocationsQaScorecardsRevisions on a missing revision 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.getProjectsLocationsQaScorecardsRevisions({
37 name: `projects/${project}/locations/us-central1/qaScorecards/missing/revisions/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// Needs Contact Center AI Insights features the testing project does not
51// have enabled: the parent scorecard's PATCH returns 404 NOT_FOUND "Requested entity was not found."
52test.provider.skipIf(!process.env.GCP_TEST_CCAI_QUALITY || !!process.env.FAST)(
53 "create, update, and delete a qa scorecard revision",
54 (stack) =>
55 Effect.gen(function* () {
56 yield* stack.destroy();
57
58 const created = yield* stack.deploy(
59 Effect.gen(function* () {
60 const card = yield* GCP.ContactCenterInsights.QaScorecard("Quality", {
61 location: "us-central1",
62 displayName: "quality",
63 description: "call quality",
64 });
65 return yield* GCP.ContactCenterInsights.QaScorecardsRevision("V1", {
66 parent: card.name,
67 });
68 }),
69 );
70
71 expect(created.name).toContain("/revisions/");
72 expect(created.parent).toContain("/qaScorecards/");
73 expect(created.qaScorecardRevisionId).toEqual(expect.any(String));
74
75 const fetched = yield* cci.getProjectsLocationsQaScorecardsRevisions({
76 name: created.name,
77 });
78 expect(fetched.name).toEqual(created.name);
79
80 const updated = yield* stack.deploy(
81 Effect.gen(function* () {
82 const card = yield* GCP.ContactCenterInsights.QaScorecard("Quality", {
83 location: "us-central1",
84 displayName: "quality-v2",
85 description: "updated quality",
86 });
87 return yield* GCP.ContactCenterInsights.QaScorecardsRevision("V1", {
88 parent: card.name,
89 qaScorecardRevisionId: created.qaScorecardRevisionId,
90 });
91 }),
92 );
93
94 expect(updated.name).toEqual(created.name);
95 expect(updated.parent).toEqual(created.parent);
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);