| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as cci from "@distilled.cloud/gcp/contactcenterinsights_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import { ChatTranscript } from "./transcript.ts"; |
| 9 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 10 | |
| 11 | const { test } = Test.make({ providers: GCP.providers() }); |
| 12 | |
| 13 | const logLevel = Effect.provideService( |
| 14 | MinimumLogLevel, |
| 15 | process.env.DEBUG ? "Debug" : "Info", |
| 16 | ); |
| 17 | |
| 18 | const waitUntilGone = (name: string) => |
| 19 | cci.getProjectsLocationsConversationsFeedbackLabels({ name }).pipe( |
| 20 | Effect.as("found" as const), |
| 21 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 22 | Effect.repeat({ |
| 23 | schedule: Schedule.spaced("1 second"), |
| 24 | until: (status) => status === "gone", |
| 25 | times: 10, |
| 26 | }), |
| 27 | ); |
| 28 | |
| 29 | test.provider( |
| 30 | "getProjectsLocationsConversationsFeedbackLabels on a missing label fails with a typed tag", |
| 31 | (stack) => |
| 32 | Effect.gen(function* () { |
| 33 | const { project } = yield* GcpEnvironment.current; |
| 34 | yield* stack.destroy(); |
| 35 | |
| 36 | const error = yield* Effect.flip( |
| 37 | cci.getProjectsLocationsConversationsFeedbackLabels({ |
| 38 | name: `projects/${project}/locations/us-central1/conversations/missing/feedbackLabels/missing`, |
| 39 | }), |
| 40 | ); |
| 41 | expect(error._tag).toEqual("NotFound"); |
| 42 | |
| 43 | yield* stack.destroy(); |
| 44 | }).pipe(logLevel), |
| 45 | { |
| 46 | tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"], |
| 47 | timeout: 90_000, |
| 48 | }, |
| 49 | ); |
| 50 | |
| 51 | // Feedback label create fails with BadRequest "Request contains an invalid |
| 52 | // argument." on the testing project (cause not yet isolated). |
| 53 | // Set GCP_TEST_CCI_FEEDBACK_LABELS=1 to run it. |
| 54 | test.provider.skipIf( |
| 55 | !!process.env.FAST || !process.env.GCP_TEST_CCI_FEEDBACK_LABELS, |
| 56 | )( |
| 57 | "create, update, and delete a conversation feedback label", |
| 58 | (stack) => |
| 59 | Effect.gen(function* () { |
| 60 | yield* stack.destroy(); |
| 61 | |
| 62 | const created = yield* stack.deploy( |
| 63 | Effect.gen(function* () { |
| 64 | const conversation = yield* GCP.ContactCenterInsights.Conversation( |
| 65 | "Chat", |
| 66 | { |
| 67 | dataSource: yield* ChatTranscript, |
| 68 | medium: "CHAT", |
| 69 | languageCode: "en-US", |
| 70 | labels: { env: "test" }, |
| 71 | }, |
| 72 | ); |
| 73 | return yield* GCP.ContactCenterInsights.ConversationsFeedbackLabel( |
| 74 | "Topic", |
| 75 | { |
| 76 | parent: conversation.name, |
| 77 | label: "billing", |
| 78 | }, |
| 79 | ); |
| 80 | }), |
| 81 | ); |
| 82 | |
| 83 | expect(created.name).toContain("/feedbackLabels/"); |
| 84 | expect(created.label).toEqual("billing"); |
| 85 | |
| 86 | const fetched = |
| 87 | yield* cci.getProjectsLocationsConversationsFeedbackLabels({ |
| 88 | name: created.name, |
| 89 | }); |
| 90 | expect(fetched.name).toEqual(created.name); |
| 91 | expect(fetched.label).toContain("alchemy-id="); |
| 92 | |
| 93 | const updated = yield* stack.deploy( |
| 94 | Effect.gen(function* () { |
| 95 | const conversation = yield* GCP.ContactCenterInsights.Conversation( |
| 96 | "Chat", |
| 97 | { |
| 98 | dataSource: yield* ChatTranscript, |
| 99 | medium: "CHAT", |
| 100 | languageCode: "en-US", |
| 101 | labels: { env: "test" }, |
| 102 | }, |
| 103 | ); |
| 104 | return yield* GCP.ContactCenterInsights.ConversationsFeedbackLabel( |
| 105 | "Topic", |
| 106 | { |
| 107 | parent: conversation.name, |
| 108 | feedbackLabelId: created.feedbackLabelId, |
| 109 | label: "invoices", |
| 110 | }, |
| 111 | ); |
| 112 | }), |
| 113 | ); |
| 114 | expect(updated.name).toEqual(created.name); |
| 115 | expect(updated.label).toEqual("invoices"); |
| 116 | |
| 117 | yield* stack.destroy(); |
| 118 | const gone = yield* waitUntilGone(created.name); |
| 119 | expect(gone).toEqual("gone"); |
| 120 | }).pipe(logLevel), |
| 121 | { |
| 122 | tags: ["provider:gcp", "provider:gcp:contactcenterinsights", "live"], |
| 123 | timeout: 90_000, |
| 124 | }, |
| 125 | ); |