| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as androidpublisher from "@distilled.cloud/gcp/androidpublisher_v3"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Schedule from "effect/Schedule"; |
| 7 | import { |
| 8 | logLevel, |
| 9 | packageName, |
| 10 | probePackageName, |
| 11 | missingTag, |
| 12 | runLifecycle, |
| 13 | } from "./common.ts"; |
| 14 | |
| 15 | const { test } = Test.make({ providers: GCP.providers() }); |
| 16 | |
| 17 | const waitUntilGone = (appId: string, editId: string) => |
| 18 | androidpublisher.getEdits({ packageName: appId, editId }).pipe( |
| 19 | Effect.as("found" as const), |
| 20 | Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)), |
| 21 | Effect.repeat({ |
| 22 | schedule: Schedule.spaced("1 second"), |
| 23 | until: (status) => status === "gone", |
| 24 | times: 10, |
| 25 | }), |
| 26 | ); |
| 27 | |
| 28 | test.provider( |
| 29 | "getEdits on a missing edit fails with a typed tag", |
| 30 | (stack) => |
| 31 | Effect.gen(function* () { |
| 32 | yield* stack.destroy(); |
| 33 | |
| 34 | const error = yield* Effect.flip( |
| 35 | androidpublisher.getEdits({ |
| 36 | packageName: probePackageName, |
| 37 | editId: "alchemy-missing-edit", |
| 38 | }), |
| 39 | ); |
| 40 | expect(error._tag).toEqual(missingTag); |
| 41 | |
| 42 | yield* stack.destroy(); |
| 43 | }).pipe(logLevel), |
| 44 | { |
| 45 | tags: ["provider:gcp", "provider:gcp:androidpublisher", "live"], |
| 46 | timeout: 90_000, |
| 47 | }, |
| 48 | ); |
| 49 | |
| 50 | test.provider.skipIf(runLifecycle)( |
| 51 | "insertEdits without Play access fails with a typed tag", |
| 52 | (stack) => |
| 53 | Effect.gen(function* () { |
| 54 | yield* stack.destroy(); |
| 55 | |
| 56 | const error = yield* Effect.flip( |
| 57 | androidpublisher.insertEdits({ |
| 58 | packageName: probePackageName, |
| 59 | body: {}, |
| 60 | }), |
| 61 | ); |
| 62 | expect(error._tag).toEqual("Forbidden"); |
| 63 | |
| 64 | yield* stack.destroy(); |
| 65 | }).pipe(logLevel), |
| 66 | { |
| 67 | tags: ["provider:gcp", "provider:gcp:androidpublisher", "live"], |
| 68 | timeout: 90_000, |
| 69 | }, |
| 70 | ); |
| 71 | |
| 72 | test.provider.skipIf(!runLifecycle)( |
| 73 | "create and delete an app edit", |
| 74 | (stack) => |
| 75 | Effect.gen(function* () { |
| 76 | yield* stack.destroy(); |
| 77 | |
| 78 | const created = yield* stack.deploy( |
| 79 | Effect.gen(function* () { |
| 80 | return yield* GCP.AndroidPublisher.Edit("Release", { |
| 81 | packageName: packageName!, |
| 82 | }); |
| 83 | }), |
| 84 | ); |
| 85 | |
| 86 | expect(created.editId.length).toBeGreaterThan(0); |
| 87 | expect(created.packageName).toEqual(packageName); |
| 88 | |
| 89 | const fetched = yield* androidpublisher.getEdits({ |
| 90 | packageName: created.packageName, |
| 91 | editId: created.editId, |
| 92 | }); |
| 93 | expect(fetched.id).toEqual(created.editId); |
| 94 | |
| 95 | yield* stack.destroy(); |
| 96 | |
| 97 | const gone = yield* waitUntilGone(created.packageName, created.editId); |
| 98 | expect(gone).toEqual("gone"); |
| 99 | }).pipe(logLevel), |
| 100 | { |
| 101 | tags: ["provider:gcp", "provider:gcp:androidpublisher", "live"], |
| 102 | timeout: 90_000, |
| 103 | }, |
| 104 | ); |