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 waitUntilPartnerCustomerGone,
12} from "./common.ts";
13
14const { test } = Test.make({ providers: GCP.providers() });
15
16const probePartner = `${probeAccountName}/channelPartnerLinks/alchemy-missing`;
17
18test.provider(
19 "getAccountsChannelPartnerLinksCustomers on a missing customer fails with a typed tag",
20 (stack) =>
21 Effect.gen(function* () {
22 yield* stack.destroy();
23
24 const error = yield* Effect.flip(
25 cloudchannel.getAccountsChannelPartnerLinksCustomers({
26 name: `${probeAccountName}/customers/alchemy-missing`,
27 }),
28 );
29 expect(error._tag).toEqual("Forbidden");
30
31 yield* stack.destroy();
32 }).pipe(logLevel),
33 {
34 tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"],
35 timeout: 90_000,
36 },
37);
38
39test.provider.skipIf(runLifecycle)(
40 "createAccountsChannelPartnerLinksCustomers without Cloud Channel access fails with a typed entitlement error",
41 (stack) =>
42 Effect.gen(function* () {
43 yield* stack.destroy();
44
45 const error = yield* Effect.flip(
46 cloudchannel.createAccountsChannelPartnerLinksCustomers({
47 parent: probePartner,
48 body: probeCustomerBody,
49 }),
50 );
51 expect(error._tag).toEqual("Forbidden");
52
53 yield* stack.destroy();
54 }).pipe(logLevel),
55 {
56 tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"],
57 timeout: 90_000,
58 },
59);
60
61test.provider.skipIf(!runLifecycle)(
62 "create, update, and delete a channel partner customer",
63 (stack) =>
64 Effect.gen(function* () {
65 yield* stack.destroy();
66
67 const partner =
68 process.env.GOOGLE_CLOUDCHANNEL_PARTNER?.trim() ?? probePartner;
69
70 const created = yield* stack.deploy(
71 Effect.gen(function* () {
72 return yield* GCP.CloudChannel.ChannelPartnerLinksCustomer("Resold", {
73 parent: partner,
74 orgDisplayName: "Resold Corp",
75 });
76 }),
77 );
78
79 expect(created.name).toContain("/customers/");
80 expect(created.orgDisplayName).toEqual("Resold Corp");
81
82 const fetched =
83 yield* cloudchannel.getAccountsChannelPartnerLinksCustomers({
84 name: created.name,
85 });
86 expect(fetched.name).toEqual(created.name);
87 expect(fetched.orgDisplayName).toEqual("Resold Corp");
88
89 const updated = yield* stack.deploy(
90 Effect.gen(function* () {
91 return yield* GCP.CloudChannel.ChannelPartnerLinksCustomer("Resold", {
92 parent: partner,
93 customerId: created.customerId,
94 orgDisplayName: "Resold Corporation",
95 domain: created.domain,
96 });
97 }),
98 );
99
100 expect(updated.name).toEqual(created.name);
101 expect(updated.orgDisplayName).toEqual("Resold Corporation");
102
103 yield* stack.destroy();
104
105 const gone = yield* waitUntilPartnerCustomerGone(created.name);
106 expect(gone).toEqual("gone");
107 }).pipe(logLevel),
108 {
109 tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"],
110 timeout: 90_000,
111 },
112);