The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as GCP from "@alchemy.run/gcp"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as cloudchannel from "@distilled.cloud/gcp/cloudchannel_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { |
| 7 | logLevel, |
| 8 | probeAccountName, |
| 9 | runLifecycle, |
| 10 | waitUntilPartnerRepricingGone, |
| 11 | } from "./common.ts"; |
| 12 | |
| 13 | const { test } = Test.make({ providers: GCP.providers() }); |
| 14 | |
| 15 | const probePartner = `${probeAccountName}/channelPartnerLinks/alchemy-missing`; |
| 16 | const probeMonth = { year: 2099, month: 1, day: 0 }; |
| 17 | |
| 18 | test.provider( |
| 19 | "getAccountsChannelPartnerLinksChannelPartnerRepricingConfigs on a missing config fails with a typed tag", |
| 20 | (stack) => |
| 21 | Effect.gen(function* () { |
| 22 | yield* stack.destroy(); |
| 23 | |
| 24 | const error = yield* Effect.flip( |
| 25 | cloudchannel.getAccountsChannelPartnerLinksChannelPartnerRepricingConfigs({ |
| 26 | name: `${probePartner}/channelPartnerRepricingConfigs/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 | |
| 39 | test.provider.skipIf(runLifecycle)( |
| 40 | "createAccountsChannelPartnerLinksChannelPartnerRepricingConfigs 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.createAccountsChannelPartnerLinksChannelPartnerRepricingConfigs({ |
| 47 | parent: probePartner, |
| 48 | body: { |
| 49 | repricingConfig: { |
| 50 | effectiveInvoiceMonth: probeMonth, |
| 51 | rebillingBasis: "COST_AT_LIST", |
| 52 | adjustment: { |
| 53 | percentageAdjustment: { percentage: { value: "0.00" } }, |
| 54 | }, |
| 55 | entitlementGranularity: { |
| 56 | entitlement: `${probeAccountName}/customers/alchemy-missing/entitlements/alchemy-missing`, |
| 57 | }, |
| 58 | }, |
| 59 | }, |
| 60 | }), |
| 61 | ); |
| 62 | expect(error._tag).toEqual("Forbidden"); |
| 63 | |
| 64 | yield* stack.destroy(); |
| 65 | }).pipe(logLevel), |
| 66 | { |
| 67 | tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"], |
| 68 | timeout: 90_000, |
| 69 | }, |
| 70 | ); |
| 71 | |
| 72 | test.provider.skipIf(!runLifecycle)( |
| 73 | "create, update, and delete a channel partner repricing config", |
| 74 | (stack) => |
| 75 | Effect.gen(function* () { |
| 76 | yield* stack.destroy(); |
| 77 | |
| 78 | const partner = process.env.GOOGLE_CLOUDCHANNEL_PARTNER?.trim() ?? probePartner; |
| 79 | const entitlement = |
| 80 | process.env.GCP_CLOUDCHANNEL_ENTITLEMENT?.trim() ?? |
| 81 | `${probeAccountName}/customers/alchemy-missing/entitlements/alchemy`; |
| 82 | |
| 83 | const created = yield* stack.deploy( |
| 84 | Effect.gen(function* () { |
| 85 | return yield* GCP.CloudChannel.ChannelPartnerLinksChannelPartnerRepricingConfig( |
| 86 | "PartnerBill", |
| 87 | { |
| 88 | parent: partner, |
| 89 | effectiveInvoiceMonth: probeMonth, |
| 90 | adjustmentPercentage: "0.00", |
| 91 | entitlement, |
| 92 | }, |
| 93 | ); |
| 94 | }), |
| 95 | ); |
| 96 | |
| 97 | expect(created.name).toContain("/channelPartnerRepricingConfigs/"); |
| 98 | |
| 99 | const fetched = |
| 100 | yield* cloudchannel.getAccountsChannelPartnerLinksChannelPartnerRepricingConfigs({ |
| 101 | name: created.name, |
| 102 | }); |
| 103 | expect(fetched.name).toEqual(created.name); |
| 104 | |
| 105 | const updated = yield* stack.deploy( |
| 106 | Effect.gen(function* () { |
| 107 | return yield* GCP.CloudChannel.ChannelPartnerLinksChannelPartnerRepricingConfig( |
| 108 | "PartnerBill", |
| 109 | { |
| 110 | parent: partner, |
| 111 | configId: created.configId, |
| 112 | effectiveInvoiceMonth: probeMonth, |
| 113 | adjustmentPercentage: "1.00", |
| 114 | entitlement, |
| 115 | }, |
| 116 | ); |
| 117 | }), |
| 118 | ); |
| 119 | |
| 120 | expect(updated.name).toEqual(created.name); |
| 121 | |
| 122 | yield* stack.destroy(); |
| 123 | |
| 124 | const gone = yield* waitUntilPartnerRepricingGone(created.name); |
| 125 | expect(gone).toEqual("gone"); |
| 126 | }).pipe(logLevel), |
| 127 | { |
| 128 | tags: ["provider:gcp", "provider:gcp:cloudchannel", "live"], |
| 129 | timeout: 90_000, |
| 130 | }, |
| 131 | ); |