| 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.getCustomersDevices({ 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 | "getCustomersDevices 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.getCustomersDevices({ |
| 30 | name: "customers/missing/devices/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 | "createCustomersDevices 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.createCustomersDevices({ |
| 48 | parent: "customers/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 customer device", |
| 65 | (stack) => |
| 66 | Effect.gen(function* () { |
| 67 | yield* stack.destroy(); |
| 68 | |
| 69 | const parent = yield* firstCustomerName; |
| 70 | expect(parent.length).toBeGreaterThan(0); |
| 71 | |
| 72 | const created = yield* stack.deploy( |
| 73 | Effect.gen(function* () { |
| 74 | return yield* GCP.SasPortal.CustomersDevice("Cbsd", { |
| 75 | parent, |
| 76 | displayName: "rooftop-1", |
| 77 | fccId: "TESTFCC", |
| 78 | serialNumber: "ALCHSN1001", |
| 79 | }); |
| 80 | }), |
| 81 | ); |
| 82 | |
| 83 | expect(created.name.length).toBeGreaterThan(0); |
| 84 | expect(created.parent).toEqual(parent); |
| 85 | expect(created.displayName).toEqual("rooftop-1"); |
| 86 | expect(created.fccId).toEqual("TESTFCC"); |
| 87 | |
| 88 | const fetched = yield* sasportal.getCustomersDevices({ |
| 89 | name: created.name, |
| 90 | }); |
| 91 | expect(fetched.name).toEqual(created.name); |
| 92 | expect(fetched.displayName).toContain("[alchemy "); |
| 93 | |
| 94 | const updated = yield* stack.deploy( |
| 95 | Effect.gen(function* () { |
| 96 | return yield* GCP.SasPortal.CustomersDevice("Cbsd", { |
| 97 | parent, |
| 98 | name: created.name, |
| 99 | displayName: "rooftop-2", |
| 100 | fccId: "TESTFCC", |
| 101 | serialNumber: "ALCHSN1001", |
| 102 | }); |
| 103 | }), |
| 104 | ); |
| 105 | |
| 106 | expect(updated.name).toEqual(created.name); |
| 107 | expect(updated.displayName).toEqual("rooftop-2"); |
| 108 | |
| 109 | yield* stack.destroy(); |
| 110 | |
| 111 | const gone = yield* waitUntilGone(created.name); |
| 112 | expect(gone).toEqual("gone"); |
| 113 | }).pipe(logLevel), |
| 114 | { tags: ["provider:gcp", "provider:gcp:sasportal", "live"], timeout: 90_000 }, |
| 115 | ); |