| 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.getProjectsLocationsIntegrationsVersionsTestCases({ 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_testcase", |
| 34 | properties: { "Trigger name": "alchemy_testcase" }, |
| 35 | }, |
| 36 | ]; |
| 37 | |
| 38 | test.provider( |
| 39 | "getProjectsLocationsIntegrationsVersionsTestCases on a missing case 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.getProjectsLocationsIntegrationsVersionsTestCases({ |
| 47 | name: `projects/${project}/locations/us-central1/integrations/alchemy-missing/versions/00000000-0000-0000-0000-000000000000/testCases/missing`, |
| 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 test case", |
| 62 | (stack) => |
| 63 | Effect.gen(function* () { |
| 64 | yield* stack.destroy(); |
| 65 | |
| 66 | const created = yield* stack.deploy( |
| 67 | Effect.gen(function* () { |
| 68 | const version = yield* GCP.Integrations.IntegrationsVersion( |
| 69 | "Orders", |
| 70 | { |
| 71 | location: "us-central1", |
| 72 | description: "testcase parent", |
| 73 | triggerConfigs: apiTrigger, |
| 74 | }, |
| 75 | ); |
| 76 | const testCase = |
| 77 | yield* GCP.Integrations.IntegrationsVersionsTestCases("HappyPath", { |
| 78 | version: version.name, |
| 79 | location: "us-central1", |
| 80 | displayName: "happy-path", |
| 81 | description: "fires the API trigger", |
| 82 | triggerId: "api_trigger/alchemy_testcase", |
| 83 | }); |
| 84 | return { version, testCase }; |
| 85 | }), |
| 86 | ); |
| 87 | |
| 88 | expect(created.testCase.name).toContain("/testCases/"); |
| 89 | expect(created.testCase.displayName).toEqual("happy-path"); |
| 90 | expect(created.testCase.description).toEqual("fires the API trigger"); |
| 91 | expect(created.testCase.triggerId).toEqual( |
| 92 | "api_trigger/alchemy_testcase", |
| 93 | ); |
| 94 | |
| 95 | const fetched = |
| 96 | yield* integrations.getProjectsLocationsIntegrationsVersionsTestCases({ |
| 97 | name: created.testCase.name, |
| 98 | }); |
| 99 | expect(fetched.name).toEqual(created.testCase.name); |
| 100 | expect(fetched.description).toContain("alchemy-id="); |
| 101 | |
| 102 | const updated = yield* stack.deploy( |
| 103 | Effect.gen(function* () { |
| 104 | const version = yield* GCP.Integrations.IntegrationsVersion( |
| 105 | "Orders", |
| 106 | { |
| 107 | integrationId: created.version.integrationId, |
| 108 | versionId: created.version.versionId, |
| 109 | location: "us-central1", |
| 110 | description: "testcase parent", |
| 111 | triggerConfigs: apiTrigger, |
| 112 | }, |
| 113 | ); |
| 114 | const testCase = |
| 115 | yield* GCP.Integrations.IntegrationsVersionsTestCases("HappyPath", { |
| 116 | version: version.name, |
| 117 | testCaseId: created.testCase.testCaseId, |
| 118 | location: "us-central1", |
| 119 | displayName: "happy-path", |
| 120 | description: "updated case", |
| 121 | triggerId: "api_trigger/alchemy_testcase", |
| 122 | }); |
| 123 | return { version, testCase }; |
| 124 | }), |
| 125 | ); |
| 126 | |
| 127 | expect(updated.testCase.name).toEqual(created.testCase.name); |
| 128 | expect(updated.testCase.description).toEqual("updated case"); |
| 129 | |
| 130 | yield* stack.destroy(); |
| 131 | const gone = yield* waitUntilGone(created.testCase.name); |
| 132 | expect(gone).toEqual("gone"); |
| 133 | }).pipe(logLevel), |
| 134 | { |
| 135 | tags: ["provider:gcp", "provider:gcp:integrations", "live"], |
| 136 | timeout: 90_000, |
| 137 | }, |
| 138 | ); |