| 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.getDeploymentsDevices({ 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: 8, |
| 19 | }), |
| 20 | ); |
| 21 | |
| 22 | test.provider( |
| 23 | "getDeploymentsDevices on a missing device fails with a typed tag", |
| 24 | (stack) => |
| 25 | Effect.gen(function* () { |
| 26 | yield* stack.destroy(); |
| 27 | |
| 28 | const error = yield* Effect.flip( |
| 29 | sasportal.getDeploymentsDevices({ |
| 30 | name: "nodes/missing/deployments/missing/devices/alchemy-missing", |
| 31 | }), |
| 32 | ); |
| 33 | expect(error._tag).toEqual("NotFound"); |
| 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 | "createNodesDeploymentsDevices 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.createNodesDeploymentsDevices({ |
| 48 | parent: "nodes/missing/deployments/missing", |
| 49 | body: { |
| 50 | displayName: "alchemy-sasportal-probe", |
| 51 | fccId: "TESTFCC", |
| 52 | serialNumber: "ALCHEMYPROBE1", |
| 53 | }, |
| 54 | }), |
| 55 | ); |
| 56 | expect(error._tag).toEqual("ServiceDisabled"); |
| 57 | |
| 58 | yield* stack.destroy(); |
| 59 | }).pipe(logLevel), |
| 60 | { tags: ["provider:gcp", "provider:gcp:sasportal", "live"], timeout: 90_000 }, |
| 61 | ); |
| 62 | |
| 63 | test.provider.skipIf(!runLifecycle)( |
| 64 | "create, update, and delete a nested device", |
| 65 | (stack) => |
| 66 | Effect.gen(function* () { |
| 67 | yield* stack.destroy(); |
| 68 | |
| 69 | const customer = yield* firstCustomerName; |
| 70 | expect(customer.length).toBeGreaterThan(0); |
| 71 | |
| 72 | const created = yield* stack.deploy( |
| 73 | Effect.gen(function* () { |
| 74 | const node = yield* GCP.SasPortal.CustomersNode("Site", { |
| 75 | parent: customer, |
| 76 | displayName: "site-a", |
| 77 | }); |
| 78 | const deployment = yield* GCP.SasPortal.CustomersNodesDeployment( |
| 79 | "Campus", |
| 80 | { |
| 81 | parent: node.name, |
| 82 | displayName: "downtown", |
| 83 | }, |
| 84 | ); |
| 85 | const device = yield* GCP.SasPortal.NodesDeploymentsDevice("Cbsd", { |
| 86 | parent: deployment.name, |
| 87 | displayName: "sector-a", |
| 88 | fccId: "TESTFCC", |
| 89 | serialNumber: "ALCHSNNEST3", |
| 90 | }); |
| 91 | return { node, deployment, device }; |
| 92 | }), |
| 93 | ); |
| 94 | |
| 95 | expect(created.device.name.length).toBeGreaterThan(0); |
| 96 | expect(created.device.displayName).toEqual("sector-a"); |
| 97 | |
| 98 | const fetched = yield* sasportal.getDeploymentsDevices({ |
| 99 | name: created.device.name, |
| 100 | }); |
| 101 | expect(fetched.name).toEqual(created.device.name); |
| 102 | expect(fetched.displayName).toContain("[alchemy "); |
| 103 | |
| 104 | const updated = yield* stack.deploy( |
| 105 | Effect.gen(function* () { |
| 106 | const node = yield* GCP.SasPortal.CustomersNode("Site", { |
| 107 | parent: customer, |
| 108 | name: created.node.name, |
| 109 | displayName: "site-a", |
| 110 | }); |
| 111 | const deployment = yield* GCP.SasPortal.CustomersNodesDeployment( |
| 112 | "Campus", |
| 113 | { |
| 114 | parent: node.name, |
| 115 | name: created.deployment.name, |
| 116 | displayName: "downtown", |
| 117 | }, |
| 118 | ); |
| 119 | const device = yield* GCP.SasPortal.NodesDeploymentsDevice("Cbsd", { |
| 120 | parent: deployment.name, |
| 121 | name: created.device.name, |
| 122 | displayName: "sector-b", |
| 123 | fccId: "TESTFCC", |
| 124 | serialNumber: "ALCHSNNEST3", |
| 125 | }); |
| 126 | return { node, deployment, device }; |
| 127 | }), |
| 128 | ); |
| 129 | |
| 130 | expect(updated.device.name).toEqual(created.device.name); |
| 131 | expect(updated.device.displayName).toEqual("sector-b"); |
| 132 | |
| 133 | yield* stack.destroy(); |
| 134 | |
| 135 | const gone = yield* waitUntilGone(created.device.name); |
| 136 | expect(gone).toEqual("gone"); |
| 137 | }).pipe(logLevel), |
| 138 | { tags: ["provider:gcp", "provider:gcp:sasportal", "live"], timeout: 90_000 }, |
| 139 | ); |