The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 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 androidpublisher from "@distilled.cloud/gcp/androidpublisher_v3"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Schedule from "effect/Schedule"; |
| 7 | import { logLevel, packageName, probePackageName, missingTag, runLifecycle } from "./common.ts"; |
| 8 | |
| 9 | const { test } = Test.make({ providers: GCP.providers() }); |
| 10 | |
| 11 | const waitUntilGone = (appId: string, productId: string, basePlanId: string, offerId: string) => |
| 12 | androidpublisher |
| 13 | .getMonetizationSubscriptionsBasePlansOffers({ |
| 14 | packageName: appId, |
| 15 | productId, |
| 16 | basePlanId, |
| 17 | offerId, |
| 18 | }) |
| 19 | .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 | "getMonetizationSubscriptionsBasePlansOffers on a missing offer fails with a typed tag", |
| 31 | (stack) => |
| 32 | Effect.gen(function* () { |
| 33 | yield* stack.destroy(); |
| 34 | |
| 35 | const error = yield* Effect.flip( |
| 36 | androidpublisher.getMonetizationSubscriptionsBasePlansOffers({ |
| 37 | packageName: probePackageName, |
| 38 | productId: "alchemy_missing_sub", |
| 39 | basePlanId: "monthly", |
| 40 | offerId: "alchemy-missing-offer", |
| 41 | }), |
| 42 | ); |
| 43 | expect(error._tag).toEqual(missingTag); |
| 44 | |
| 45 | yield* stack.destroy(); |
| 46 | }).pipe(logLevel), |
| 47 | { |
| 48 | tags: ["provider:gcp", "provider:gcp:androidpublisher", "live"], |
| 49 | timeout: 90_000, |
| 50 | }, |
| 51 | ); |
| 52 | |
| 53 | test.provider.skipIf(runLifecycle)( |
| 54 | "createMonetizationSubscriptionsBasePlansOffers without Play access fails with a typed tag", |
| 55 | (stack) => |
| 56 | Effect.gen(function* () { |
| 57 | yield* stack.destroy(); |
| 58 | |
| 59 | const error = yield* Effect.flip( |
| 60 | androidpublisher.createMonetizationSubscriptionsBasePlansOffers({ |
| 61 | packageName: probePackageName, |
| 62 | productId: "alchemy_probe_sub", |
| 63 | basePlanId: "monthly", |
| 64 | offerId: "intro", |
| 65 | "regionsVersion.version": "2025/01", |
| 66 | body: { |
| 67 | packageName: probePackageName, |
| 68 | productId: "alchemy_probe_sub", |
| 69 | basePlanId: "monthly", |
| 70 | offerId: "intro", |
| 71 | phases: [ |
| 72 | { |
| 73 | duration: "P1W", |
| 74 | recurrenceCount: 1, |
| 75 | regionalConfigs: [{ regionCode: "US", free: {} }], |
| 76 | }, |
| 77 | ], |
| 78 | regionalConfigs: [{ regionCode: "US", newSubscriberAvailability: true }], |
| 79 | }, |
| 80 | }), |
| 81 | ); |
| 82 | expect(error._tag).toEqual("Forbidden"); |
| 83 | |
| 84 | yield* stack.destroy(); |
| 85 | }).pipe(logLevel), |
| 86 | { |
| 87 | tags: ["provider:gcp", "provider:gcp:androidpublisher", "live"], |
| 88 | timeout: 90_000, |
| 89 | }, |
| 90 | ); |
| 91 | |
| 92 | test.provider.skipIf(!runLifecycle)( |
| 93 | "create, update, and delete a subscription offer", |
| 94 | (stack) => |
| 95 | Effect.gen(function* () { |
| 96 | yield* stack.destroy(); |
| 97 | |
| 98 | const created = yield* stack.deploy( |
| 99 | Effect.gen(function* () { |
| 100 | const subscription = yield* GCP.AndroidPublisher.MonetizationSubscription("Premium", { |
| 101 | packageName: packageName!, |
| 102 | listings: [{ languageCode: "en-US", title: "Premium" }], |
| 103 | basePlans: [ |
| 104 | { |
| 105 | basePlanId: "monthly", |
| 106 | autoRenewingBasePlanType: { billingPeriodDuration: "P1M" }, |
| 107 | regionalConfigs: [ |
| 108 | { |
| 109 | regionCode: "US", |
| 110 | newSubscriberAvailability: true, |
| 111 | price: { currencyCode: "USD", units: "5" }, |
| 112 | }, |
| 113 | ], |
| 114 | }, |
| 115 | ], |
| 116 | }); |
| 117 | const offer = yield* GCP.AndroidPublisher.MonetizationSubscriptionsBasePlansOffer( |
| 118 | "Intro", |
| 119 | { |
| 120 | packageName: packageName!, |
| 121 | productId: subscription.productId, |
| 122 | basePlanId: "monthly", |
| 123 | }, |
| 124 | ); |
| 125 | return { subscription, offer }; |
| 126 | }), |
| 127 | ); |
| 128 | |
| 129 | expect(created.offer.offerId.length).toBeGreaterThan(0); |
| 130 | expect(created.offer.productId).toEqual(created.subscription.productId); |
| 131 | |
| 132 | const fetched = yield* androidpublisher.getMonetizationSubscriptionsBasePlansOffers({ |
| 133 | packageName: created.offer.packageName, |
| 134 | productId: created.offer.productId, |
| 135 | basePlanId: created.offer.basePlanId, |
| 136 | offerId: created.offer.offerId, |
| 137 | }); |
| 138 | expect(fetched.offerId).toEqual(created.offer.offerId); |
| 139 | |
| 140 | const updated = yield* stack.deploy( |
| 141 | Effect.gen(function* () { |
| 142 | const subscription = yield* GCP.AndroidPublisher.MonetizationSubscription("Premium", { |
| 143 | packageName: created.subscription.packageName, |
| 144 | productId: created.subscription.productId, |
| 145 | listings: [{ languageCode: "en-US", title: "Premium" }], |
| 146 | basePlans: [ |
| 147 | { |
| 148 | basePlanId: "monthly", |
| 149 | autoRenewingBasePlanType: { billingPeriodDuration: "P1M" }, |
| 150 | regionalConfigs: [ |
| 151 | { |
| 152 | regionCode: "US", |
| 153 | newSubscriberAvailability: true, |
| 154 | price: { currencyCode: "USD", units: "5" }, |
| 155 | }, |
| 156 | ], |
| 157 | }, |
| 158 | ], |
| 159 | }); |
| 160 | const offer = yield* GCP.AndroidPublisher.MonetizationSubscriptionsBasePlansOffer( |
| 161 | "Intro", |
| 162 | { |
| 163 | packageName: created.offer.packageName, |
| 164 | productId: created.offer.productId, |
| 165 | basePlanId: created.offer.basePlanId, |
| 166 | offerId: created.offer.offerId, |
| 167 | regionalConfigs: [{ regionCode: "US", newSubscriberAvailability: false }], |
| 168 | }, |
| 169 | ); |
| 170 | return { subscription, offer }; |
| 171 | }), |
| 172 | ); |
| 173 | |
| 174 | expect(updated.offer.offerId).toEqual(created.offer.offerId); |
| 175 | expect(updated.offer.regionalConfigs?.[0]?.newSubscriberAvailability).toEqual(false); |
| 176 | |
| 177 | yield* stack.destroy(); |
| 178 | |
| 179 | const gone = yield* waitUntilGone( |
| 180 | created.offer.packageName, |
| 181 | created.offer.productId, |
| 182 | created.offer.basePlanId, |
| 183 | created.offer.offerId, |
| 184 | ); |
| 185 | expect(gone).toEqual("gone"); |
| 186 | }).pipe(logLevel), |
| 187 | { |
| 188 | tags: ["provider:gcp", "provider:gcp:androidpublisher", "live"], |
| 189 | timeout: 90_000, |
| 190 | }, |
| 191 | ); |