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