The best way to control Claude Code, Codex and more from any computer or phone
| 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 firebaseappcheck from "@distilled.cloud/gcp/firebaseappcheck_v1"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { |
| 7 | logLevel, |
| 8 | runLifecycle, |
| 9 | missingResourcePolicy, |
| 10 | waitUntilResourcePolicyGone, |
| 11 | } from "./common.ts"; |
| 12 | |
| 13 | const { test } = Test.make({ providers: GCP.providers() }); |
| 14 | |
| 15 | test.provider( |
| 16 | "getProjectsServicesResourcePolicies on a missing policy fails with a typed tag", |
| 17 | (stack) => |
| 18 | Effect.gen(function* () { |
| 19 | yield* stack.destroy(); |
| 20 | |
| 21 | const missing = yield* missingResourcePolicy(); |
| 22 | const error = yield* Effect.flip( |
| 23 | firebaseappcheck.getProjectsServicesResourcePolicies({ |
| 24 | name: missing, |
| 25 | }), |
| 26 | ); |
| 27 | expect(["ServiceDisabled", "NotFound"]).toContain(error._tag); |
| 28 | |
| 29 | yield* stack.destroy(); |
| 30 | }).pipe(logLevel), |
| 31 | { |
| 32 | tags: ["provider:gcp", "provider:gcp:firebaseappcheck", "live"], |
| 33 | timeout: 90_000, |
| 34 | }, |
| 35 | ); |
| 36 | |
| 37 | test.provider.skipIf(!runLifecycle)( |
| 38 | "create, update, and delete a resource policy", |
| 39 | (stack) => |
| 40 | Effect.gen(function* () { |
| 41 | yield* stack.destroy(); |
| 42 | |
| 43 | const created = yield* stack.deploy( |
| 44 | Effect.gen(function* () { |
| 45 | return yield* GCP.FirebaseAppCheck.ServicesResourcePolicy("IosOauth", { |
| 46 | enforcementMode: "UNENFORCED", |
| 47 | }); |
| 48 | }), |
| 49 | ); |
| 50 | |
| 51 | expect(created.name).toContain("/resourcePolicies/"); |
| 52 | expect(created.resourcePolicyId).toEqual(expect.any(String)); |
| 53 | expect(created.serviceId).toEqual("oauth2.googleapis.com"); |
| 54 | expect(created.enforcementMode).toEqual("UNENFORCED"); |
| 55 | expect(created.targetResource).toContain("/oauthClients/alc-"); |
| 56 | |
| 57 | const fetched = yield* firebaseappcheck.getProjectsServicesResourcePolicies({ |
| 58 | name: created.name, |
| 59 | }); |
| 60 | expect(fetched.name).toEqual(created.name); |
| 61 | expect(fetched.enforcementMode).toEqual("UNENFORCED"); |
| 62 | expect(fetched.targetResource).toEqual(created.targetResource); |
| 63 | |
| 64 | const updated = yield* stack.deploy( |
| 65 | Effect.gen(function* () { |
| 66 | return yield* GCP.FirebaseAppCheck.ServicesResourcePolicy("IosOauth", { |
| 67 | targetResource: created.targetResource, |
| 68 | enforcementMode: "OFF", |
| 69 | }); |
| 70 | }), |
| 71 | ); |
| 72 | |
| 73 | expect(updated.name).toEqual(created.name); |
| 74 | expect(updated.enforcementMode).toEqual("OFF"); |
| 75 | expect(updated.targetResource).toEqual(created.targetResource); |
| 76 | |
| 77 | yield* stack.destroy(); |
| 78 | |
| 79 | const gone = yield* waitUntilResourcePolicyGone(created.name); |
| 80 | expect(gone).toEqual("gone"); |
| 81 | }).pipe(logLevel), |
| 82 | { |
| 83 | tags: ["provider:gcp", "provider:gcp:firebaseappcheck", "live"], |
| 84 | timeout: 90_000, |
| 85 | }, |
| 86 | ); |