1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as chromemanagement from "@distilled.cloud/gcp/chromemanagement_v1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import {
7 customerName,
8 logLevel,
9 probeName,
10 probeParent,
11 runLifecycle,
12 waitUntilGone,
13} from "./common.ts";
14
15const { test } = Test.make({ providers: GCP.providers() });
16
17const probeBody: chromemanagement.GoogleChromeManagementVersionsV1ConnectorConfig =
18 {
19 displayName: "Alchemy Probe",
20 type: "REPORTING",
21 details: {
22 pubSubConfig: {
23 topicFullPath:
24 "projects/alchemy-gcp-testing-83661/topics/alchemy-probe",
25 reportingSettings: {
26 enabledDefaultEvents: ["ALL_DEFAULT_EVENTS"],
27 },
28 },
29 },
30 };
31
32test.provider.skipIf(!runLifecycle)(
33 "getCustomersConnectorConfigs on a missing connector config fails with a typed tag",
34 (stack) =>
35 Effect.gen(function* () {
36 yield* stack.destroy();
37
38 const error = yield* Effect.flip(
39 chromemanagement.getCustomersConnectorConfigs({
40 name: probeName,
41 }),
42 );
43 expect(error._tag).toEqual("NotFound");
44
45 yield* stack.destroy();
46 }).pipe(logLevel),
47 {
48 tags: ["provider:gcp", "provider:gcp:chromemanagement", "live"],
49 timeout: 90_000,
50 },
51);
52
53test.provider.skipIf(runLifecycle)(
54 "createCustomersConnectorConfigs without Chrome Management access fails with InsufficientScopes",
55 (stack) =>
56 Effect.gen(function* () {
57 yield* stack.destroy();
58
59 const error = yield* Effect.flip(
60 chromemanagement.createCustomersConnectorConfigs({
61 parent: probeParent,
62 connectorConfigId: "alchemy-probe",
63 body: probeBody,
64 }),
65 );
66 expect(error._tag).toEqual("InsufficientScopes");
67
68 yield* stack.destroy();
69 }).pipe(logLevel),
70 {
71 tags: ["provider:gcp", "provider:gcp:chromemanagement", "live"],
72 timeout: 90_000,
73 },
74);
75
76test.provider.skipIf(!runLifecycle)(
77 "create, update, and delete a connector config",
78 (stack) =>
79 Effect.gen(function* () {
80 yield* stack.destroy();
81
82 const parent = customerName;
83
84 const created = yield* stack.deploy(
85 Effect.gen(function* () {
86 const topic = yield* GCP.PubSub.Topic("ChromeEvents", {});
87 const config = yield* GCP.ChromeManagement.CustomersConnectorConfig(
88 "Reporting",
89 {
90 parent,
91 type: "REPORTING",
92 displayName: "Alchemy reporting",
93 details: {
94 pubSubConfig: {
95 topicFullPath: topic.name,
96 reportingSettings: {
97 enabledDefaultEvents: ["ALL_DEFAULT_EVENTS"],
98 },
99 },
100 },
101 },
102 );
103 return { config, topicName: topic.name };
104 }),
105 );
106
107 expect(created.config.name).toContain("/connectorConfigs/");
108 expect(created.config.parent).toEqual(parent);
109 expect(created.config.connectorConfigId.length).toBeGreaterThan(0);
110 expect(created.config.displayName).toEqual("Alchemy reporting");
111 expect(created.config.type).toEqual("REPORTING");
112 expect(created.config.details?.pubSubConfig?.topicFullPath).toEqual(
113 created.topicName,
114 );
115
116 const fetched = yield* chromemanagement.getCustomersConnectorConfigs({
117 name: created.config.name,
118 });
119 expect(fetched.name).toEqual(created.config.name);
120 expect(fetched.displayName).toContain("[alchemy ");
121 expect(fetched.type).toEqual("REPORTING");
122
123 const updated = yield* stack.deploy(
124 Effect.gen(function* () {
125 const topic = yield* GCP.PubSub.Topic("ChromeEvents", {});
126 const config = yield* GCP.ChromeManagement.CustomersConnectorConfig(
127 "Reporting",
128 {
129 parent: created.config.parent,
130 connectorConfigId: created.config.connectorConfigId,
131 type: "REPORTING",
132 displayName: "Alchemy reporting (prod)",
133 details: {
134 pubSubConfig: {
135 topicFullPath: topic.name,
136 reportingSettings: {
137 enabledDefaultEvents: ["BROWSER_CRASH_EVENT"],
138 enabledOptInEvents: ["ALL_OPT_IN_EVENTS"],
139 },
140 },
141 },
142 },
143 );
144 return { config, topicName: topic.name };
145 }),
146 );
147
148 expect(updated.config.name).toEqual(created.config.name);
149 expect(updated.config.displayName).toEqual("Alchemy reporting (prod)");
150 expect(
151 updated.config.details?.pubSubConfig?.reportingSettings
152 ?.enabledDefaultEvents,
153 ).toContain("BROWSER_CRASH_EVENT");
154
155 const fetchedUpdate =
156 yield* chromemanagement.getCustomersConnectorConfigs({
157 name: updated.config.name,
158 });
159 expect(fetchedUpdate.displayName).toContain("Alchemy reporting (prod)");
160
161 yield* stack.destroy();
162
163 const gone = yield* waitUntilGone(created.config.name);
164 expect(gone).toEqual("gone");
165 }).pipe(logLevel),
166 {
167 tags: ["provider:gcp", "provider:gcp:chromemanagement", "live"],
168 timeout: 90_000,
169 },
170);