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.getProjectsLocationsIssueModelsIssues({ name }).pipe(
19 Effect.as("found" as const),
20 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
21 Effect.repeat({
22 schedule: Schedule.spaced("2 seconds"),
23 until: (status) => status === "gone",
24 times: 10,
25 }),
26 );
27
28test.provider(
29 "getProjectsLocationsIssueModelsIssues on a missing issue 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.getProjectsLocationsIssueModelsIssues({
37 name: `projects/${project}/locations/us-central1/issueModels/missing/issues/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 a project with at least 100 analyzed conversations; otherwise create fails with
51// BadRequest "Project: `...` has too few conversations with the given filters.
52// Current number: 0. Minimum requirement is: 100."
53test.provider.skipIf(
54 !!process.env.FAST || !process.env.GCP_TEST_CCI_ISSUE_MODELS,
55)(
56 "create, update, and delete an issue model issue",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 const created = yield* stack.deploy(
62 Effect.gen(function* () {
63 const model = yield* GCP.ContactCenterInsights.IssueModel("Topics", {
64 location: "us-central1",
65 displayName: "issue-parent",
66 languageCode: "en-US",
67 modelType: "TYPE_V2",
68 });
69 return yield* GCP.ContactCenterInsights.IssueModelsIssue("Billing", {
70 parent: model.name,
71 displayName: "billing",
72 displayDescription: "questions about invoices",
73 });
74 }),
75 );
76
77 expect(created.name).toContain("/issues/");
78 expect(created.displayName).toEqual("billing");
79 expect(created.displayDescription).toEqual("questions about invoices");
80
81 const fetched = yield* cci.getProjectsLocationsIssueModelsIssues({
82 name: created.name,
83 });
84 expect(fetched.name).toEqual(created.name);
85 expect(fetched.displayDescription).toContain("alchemy-id=");
86
87 const updated = yield* stack.deploy(
88 Effect.gen(function* () {
89 const model = yield* GCP.ContactCenterInsights.IssueModel("Topics", {
90 location: "us-central1",
91 displayName: "issue-parent",
92 languageCode: "en-US",
93 modelType: "TYPE_V2",
94 });
95 return yield* GCP.ContactCenterInsights.IssueModelsIssue("Billing", {
96 parent: model.name,
97 displayName: "billing-v2",
98 displayDescription: "updated invoices",
99 });
100 }),
101 );
102 expect(updated.name).toEqual(created.name);
103 expect(updated.displayName).toEqual("billing-v2");
104 expect(updated.displayDescription).toEqual("updated invoices");
105
106 yield* stack.destroy();
107 const gone = yield* waitUntilGone(created.name);
108 expect(gone).toEqual("gone");
109 }).pipe(logLevel),
110 {
111 tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"],
112 timeout: 120_000,
113 },
114);