1import * as GCP from "@/GCP";
2import * as Test from "@/Test/Alchemy";
3import * as cloudchannel from "@distilled.cloud/gcp/cloudchannel_v1";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import {
7 logLevel,
8 probeAccountName,
9 probeCustomerBody,
10 runLifecycle,
11 waitUntilCustomerGone,
12} from "./common.ts";
13
14const { test } = Test.make({ providers: GCP.providers() });
15
16test.provider(
17 "getAccountsCustomers on a missing customer fails with a typed tag",
18 (stack) =>
19 Effect.gen(function* () {
20 yield* stack.destroy();
21
22 const error = yield* Effect.flip(
23 cloudchannel.getAccountsCustomers({
24 name: `${probeAccountName}/customers/alchemy-missing`,
25 }),
26 );
27 expect(error._tag).toEqual("Forbidden");
28
29 yield* stack.destroy();
30 }).pipe(logLevel),
31 {
32 tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"],
33 timeout: 90_000,
34 },
35);
36
37test.provider.skipIf(runLifecycle)(
38 "createAccountsCustomers without Cloud Channel access fails with a typed entitlement error",
39 (stack) =>
40 Effect.gen(function* () {
41 yield* stack.destroy();
42
43 const error = yield* Effect.flip(
44 cloudchannel.createAccountsCustomers({
45 parent: probeAccountName,
46 body: probeCustomerBody,
47 }),
48 );
49 expect(error._tag).toEqual("Forbidden");
50
51 yield* stack.destroy();
52 }).pipe(logLevel),
53 {
54 tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"],
55 timeout: 90_000,
56 },
57);
58
59test.provider.skipIf(!runLifecycle)(
60 "create, update, and delete a customer",
61 (stack) =>
62 Effect.gen(function* () {
63 yield* stack.destroy();
64
65 const created = yield* stack.deploy(
66 Effect.gen(function* () {
67 return yield* GCP.CloudChannel.Customer("Acme", {
68 parent: probeAccountName,
69 orgDisplayName: "Acme Corp",
70 });
71 }),
72 );
73
74 expect(created.name.startsWith(`${probeAccountName}/customers/`)).toEqual(
75 true,
76 );
77 expect(created.customerId.length).toBeGreaterThan(0);
78 expect(created.orgDisplayName).toEqual("Acme Corp");
79 expect(created.domain).toEqual(expect.any(String));
80
81 const fetched = yield* cloudchannel.getAccountsCustomers({
82 name: created.name,
83 });
84 expect(fetched.name).toEqual(created.name);
85 expect(fetched.orgDisplayName).toEqual("Acme Corp");
86
87 const updated = yield* stack.deploy(
88 Effect.gen(function* () {
89 return yield* GCP.CloudChannel.Customer("Acme", {
90 parent: probeAccountName,
91 customerId: created.customerId,
92 orgDisplayName: "Acme Corporation",
93 domain: created.domain,
94 });
95 }),
96 );
97
98 expect(updated.name).toEqual(created.name);
99 expect(updated.orgDisplayName).toEqual("Acme Corporation");
100
101 yield* stack.destroy();
102
103 const gone = yield* waitUntilCustomerGone(created.name);
104 expect(gone).toEqual("gone");
105 }).pipe(logLevel),
106 {
107 tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"],
108 timeout: 90_000,
109 },
110);