| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as firebaseappcheck from "@distilled.cloud/gcp/firebaseappcheck_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { |
| 7 | lifecycleAppId, |
| 8 | logLevel, |
| 9 | runLifecycle, |
| 10 | missingDebugToken, |
| 11 | waitUntilDebugTokenGone, |
| 12 | } from "./common.ts"; |
| 13 | |
| 14 | const { test } = Test.make({ providers: GCP.providers() }); |
| 15 | |
| 16 | test.provider( |
| 17 | "getProjectsAppsDebugTokens on a missing token fails with a typed tag", |
| 18 | (stack) => |
| 19 | Effect.gen(function* () { |
| 20 | yield* stack.destroy(); |
| 21 | |
| 22 | const missing = yield* missingDebugToken(); |
| 23 | const error = yield* Effect.flip( |
| 24 | firebaseappcheck.getProjectsAppsDebugTokens({ |
| 25 | name: missing, |
| 26 | }), |
| 27 | ); |
| 28 | expect(error._tag).toEqual("ServiceDisabled"); |
| 29 | |
| 30 | yield* stack.destroy(); |
| 31 | }).pipe(logLevel), |
| 32 | { |
| 33 | tags: ["provider:gcp", "provider:gcp:firebaseappcheck", "live"], |
| 34 | timeout: 90_000, |
| 35 | }, |
| 36 | ); |
| 37 | |
| 38 | test.provider.skipIf(!runLifecycle)( |
| 39 | "create, update, and delete a debug token", |
| 40 | (stack) => |
| 41 | Effect.gen(function* () { |
| 42 | yield* stack.destroy(); |
| 43 | |
| 44 | const app = lifecycleAppId ?? ""; |
| 45 | |
| 46 | const created = yield* stack.deploy( |
| 47 | Effect.gen(function* () { |
| 48 | return yield* GCP.FirebaseAppCheck.AppsDebugToken("Local", { |
| 49 | app, |
| 50 | displayName: "alchemy-test", |
| 51 | }); |
| 52 | }), |
| 53 | ); |
| 54 | |
| 55 | expect(created.name).toContain("/debugTokens/"); |
| 56 | expect(created.debugTokenId).toEqual(expect.any(String)); |
| 57 | expect(created.appId).toEqual(expect.any(String)); |
| 58 | expect(created.displayName).toEqual("alchemy-test"); |
| 59 | expect(created.token).toEqual(expect.any(String)); |
| 60 | expect((created.token ?? "").length).toBeGreaterThan(8); |
| 61 | |
| 62 | const fetched = yield* firebaseappcheck.getProjectsAppsDebugTokens({ |
| 63 | name: created.name, |
| 64 | }); |
| 65 | expect(fetched.name).toEqual(created.name); |
| 66 | expect(fetched.displayName).toContain("[alchemy "); |
| 67 | expect(fetched.displayName).toContain("alchemy-test"); |
| 68 | expect(fetched.token).toBeFalsy(); |
| 69 | |
| 70 | const updated = yield* stack.deploy( |
| 71 | Effect.gen(function* () { |
| 72 | return yield* GCP.FirebaseAppCheck.AppsDebugToken("Local", { |
| 73 | app, |
| 74 | displayName: "alchemy-prod", |
| 75 | token: created.token, |
| 76 | }); |
| 77 | }), |
| 78 | ); |
| 79 | |
| 80 | expect(updated.name).toEqual(created.name); |
| 81 | expect(updated.displayName).toEqual("alchemy-prod"); |
| 82 | expect(updated.token).toEqual(created.token); |
| 83 | |
| 84 | yield* stack.destroy(); |
| 85 | |
| 86 | const gone = yield* waitUntilDebugTokenGone(created.name); |
| 87 | expect(gone).toEqual("gone"); |
| 88 | }).pipe(logLevel), |
| 89 | { |
| 90 | tags: ["provider:gcp", "provider:gcp:firebaseappcheck", "live"], |
| 91 | timeout: 90_000, |
| 92 | }, |
| 93 | ); |