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