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) => |
| 12 | androidpublisher |
| 13 | .getMonetizationSubscriptions({ |
| 14 | packageName: appId, |
| 15 | productId, |
| 16 | }) |
| 17 | .pipe( |
| 18 | Effect.as("found" as const), |
| 19 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 20 | Effect.repeat({ |
| 21 | schedule: Schedule.spaced("1 second"), |
| 22 | until: (status) => status === "gone", |
| 23 | times: 10, |
| 24 | }), |
| 25 | ); |
| 26 | |
| 27 | test.provider( |
| 28 | "getMonetizationSubscriptions on a missing subscription fails with a typed tag", |
| 29 | (stack) => |
| 30 | Effect.gen(function* () { |
| 31 | yield* stack.destroy(); |
| 32 | |
| 33 | const error = yield* Effect.flip( |
| 34 | androidpublisher.getMonetizationSubscriptions({ |
| 35 | packageName: probePackageName, |
| 36 | productId: "alchemy_missing_sub", |
| 37 | }), |
| 38 | ); |
| 39 | expect(error._tag).toEqual(missingTag); |
| 40 | |
| 41 | yield* stack.destroy(); |
| 42 | }).pipe(logLevel), |
| 43 | { |
| 44 | tags: ["provider:gcp", "provider:gcp:androidpublisher", "live"], |
| 45 | timeout: 90_000, |
| 46 | }, |
| 47 | ); |
| 48 | |
| 49 | test.provider.skipIf(runLifecycle)( |
| 50 | "createMonetizationSubscriptions without Play access fails with a typed tag", |
| 51 | (stack) => |
| 52 | Effect.gen(function* () { |
| 53 | yield* stack.destroy(); |
| 54 | |
| 55 | const error = yield* Effect.flip( |
| 56 | androidpublisher.createMonetizationSubscriptions({ |
| 57 | packageName: probePackageName, |
| 58 | productId: "alchemy_probe_sub", |
| 59 | "regionsVersion.version": "2025/01", |
| 60 | body: { |
| 61 | packageName: probePackageName, |
| 62 | productId: "alchemy_probe_sub", |
| 63 | listings: [{ languageCode: "en-US", title: "Alchemy Probe" }], |
| 64 | }, |
| 65 | }), |
| 66 | ); |
| 67 | expect(error._tag).toEqual("Forbidden"); |
| 68 | |
| 69 | yield* stack.destroy(); |
| 70 | }).pipe(logLevel), |
| 71 | { |
| 72 | tags: ["provider:gcp", "provider:gcp:androidpublisher", "live"], |
| 73 | timeout: 90_000, |
| 74 | }, |
| 75 | ); |
| 76 | |
| 77 | test.provider.skipIf(!runLifecycle)( |
| 78 | "create, update, and delete a subscription", |
| 79 | (stack) => |
| 80 | Effect.gen(function* () { |
| 81 | yield* stack.destroy(); |
| 82 | |
| 83 | const created = yield* stack.deploy( |
| 84 | Effect.gen(function* () { |
| 85 | return yield* GCP.AndroidPublisher.MonetizationSubscription("Premium", { |
| 86 | packageName: packageName!, |
| 87 | listings: [{ languageCode: "en-US", title: "Premium" }], |
| 88 | }); |
| 89 | }), |
| 90 | ); |
| 91 | |
| 92 | expect(created.productId.length).toBeGreaterThan(0); |
| 93 | expect(created.packageName).toEqual(packageName); |
| 94 | expect(created.listings?.[0]?.title).toEqual("Premium"); |
| 95 | |
| 96 | const fetched = yield* androidpublisher.getMonetizationSubscriptions({ |
| 97 | packageName: created.packageName, |
| 98 | productId: created.productId, |
| 99 | }); |
| 100 | expect(fetched.productId).toEqual(created.productId); |
| 101 | expect(fetched.listings?.[0]?.title).toEqual("Premium"); |
| 102 | |
| 103 | const updated = yield* stack.deploy( |
| 104 | Effect.gen(function* () { |
| 105 | return yield* GCP.AndroidPublisher.MonetizationSubscription("Premium", { |
| 106 | packageName: created.packageName, |
| 107 | productId: created.productId, |
| 108 | listings: [{ languageCode: "en-US", title: "Premium Plus" }], |
| 109 | }); |
| 110 | }), |
| 111 | ); |
| 112 | |
| 113 | expect(updated.productId).toEqual(created.productId); |
| 114 | expect(updated.listings?.[0]?.title).toEqual("Premium Plus"); |
| 115 | |
| 116 | yield* stack.destroy(); |
| 117 | |
| 118 | const gone = yield* waitUntilGone(created.packageName, created.productId); |
| 119 | expect(gone).toEqual("gone"); |
| 120 | }).pipe(logLevel), |
| 121 | { |
| 122 | tags: ["provider:gcp", "provider:gcp:androidpublisher", "live"], |
| 123 | timeout: 90_000, |
| 124 | }, |
| 125 | ); |