| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as integrations from "@distilled.cloud/gcp/integrations_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | import * as Schedule from "effect/Schedule"; |
| 8 | import { GcpEnvironment } from "@/GCP/Environment"; |
| 9 | |
| 10 | const { test } = Test.make({ providers: GCP.providers() }); |
| 11 | |
| 12 | const logLevel = Effect.provideService( |
| 13 | MinimumLogLevel, |
| 14 | process.env.DEBUG ? "Debug" : "Info", |
| 15 | ); |
| 16 | |
| 17 | const waitUntilGone = (name: string) => |
| 18 | integrations.getProjectsLocationsIntegrationsVersions({ name }).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 | const apiTrigger = [ |
| 29 | { |
| 30 | label: "API Trigger", |
| 31 | triggerType: "API" as const, |
| 32 | triggerNumber: "1", |
| 33 | triggerId: "api_trigger/alchemy_orders", |
| 34 | properties: { "Trigger name": "alchemy_orders" }, |
| 35 | }, |
| 36 | ]; |
| 37 | |
| 38 | test.provider( |
| 39 | "getProjectsLocationsIntegrationsVersions on a missing version fails with a typed tag", |
| 40 | (stack) => |
| 41 | Effect.gen(function* () { |
| 42 | const { project } = yield* GcpEnvironment.current; |
| 43 | yield* stack.destroy(); |
| 44 | |
| 45 | const error = yield* Effect.flip( |
| 46 | integrations.getProjectsLocationsIntegrationsVersions({ |
| 47 | name: `projects/${project}/locations/us-central1/integrations/alchemy-missing/versions/00000000-0000-0000-0000-000000000000`, |
| 48 | }), |
| 49 | ); |
| 50 | expect(error._tag).toEqual("NotFound"); |
| 51 | |
| 52 | yield* stack.destroy(); |
| 53 | }).pipe(logLevel), |
| 54 | { |
| 55 | tags: ["provider:gcp", "provider:gcp:integrations", "live"], |
| 56 | timeout: 90_000, |
| 57 | }, |
| 58 | ); |
| 59 | |
| 60 | test.provider( |
| 61 | "create, update, and delete an integration version", |
| 62 | (stack) => |
| 63 | Effect.gen(function* () { |
| 64 | yield* stack.destroy(); |
| 65 | |
| 66 | const created = yield* stack.deploy( |
| 67 | Effect.gen(function* () { |
| 68 | return yield* GCP.Integrations.IntegrationsVersion("Orders", { |
| 69 | location: "us-central1", |
| 70 | description: "order workflow", |
| 71 | triggerConfigs: apiTrigger, |
| 72 | }); |
| 73 | }), |
| 74 | ); |
| 75 | |
| 76 | expect(created.name).toContain("/integrations/"); |
| 77 | expect(created.name).toContain("/versions/"); |
| 78 | expect(created.location).toEqual("us-central1"); |
| 79 | expect(created.description).toEqual("order workflow"); |
| 80 | |
| 81 | const fetched = |
| 82 | yield* integrations.getProjectsLocationsIntegrationsVersions({ |
| 83 | name: created.name, |
| 84 | }); |
| 85 | expect(fetched.name).toEqual(created.name); |
| 86 | expect(fetched.description).toContain("alchemy-id="); |
| 87 | expect(fetched.description).toContain("order workflow"); |
| 88 | |
| 89 | const updated = yield* stack.deploy( |
| 90 | Effect.gen(function* () { |
| 91 | return yield* GCP.Integrations.IntegrationsVersion("Orders", { |
| 92 | integrationId: created.integrationId, |
| 93 | versionId: created.versionId, |
| 94 | location: "us-central1", |
| 95 | description: "updated workflow", |
| 96 | triggerConfigs: apiTrigger, |
| 97 | }); |
| 98 | }), |
| 99 | ); |
| 100 | |
| 101 | expect(updated.name).toEqual(created.name); |
| 102 | expect(updated.description).toEqual("updated workflow"); |
| 103 | |
| 104 | yield* stack.destroy(); |
| 105 | const gone = yield* waitUntilGone(created.name); |
| 106 | expect(gone).toEqual("gone"); |
| 107 | }).pipe(logLevel), |
| 108 | { |
| 109 | tags: ["provider:gcp", "provider:gcp:integrations", "live"], |
| 110 | timeout: 90_000, |
| 111 | }, |
| 112 | ); |