| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as androiddeviceprovisioning from "@distilled.cloud/gcp/androiddeviceprovisioning_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { |
| 7 | customerName, |
| 8 | logLevel, |
| 9 | probeName, |
| 10 | probeParent, |
| 11 | resolveDpc, |
| 12 | runLifecycle, |
| 13 | waitUntilGone, |
| 14 | } from "./common.ts"; |
| 15 | |
| 16 | const { test } = Test.make({ providers: GCP.providers() }); |
| 17 | |
| 18 | test.provider.skipIf(!runLifecycle)( |
| 19 | "getCustomersConfigurations on a missing configuration fails with a typed tag", |
| 20 | (stack) => |
| 21 | Effect.gen(function* () { |
| 22 | yield* stack.destroy(); |
| 23 | |
| 24 | const error = yield* Effect.flip( |
| 25 | androiddeviceprovisioning.getCustomersConfigurations({ |
| 26 | name: probeName, |
| 27 | }), |
| 28 | ); |
| 29 | expect(error._tag).toEqual("NotFound"); |
| 30 | |
| 31 | yield* stack.destroy(); |
| 32 | }).pipe(logLevel), |
| 33 | { |
| 34 | tags: ["provider:gcp", "provider:gcp:androiddeviceprovisioning", "live"], |
| 35 | timeout: 90_000, |
| 36 | }, |
| 37 | ); |
| 38 | |
| 39 | test.provider.skipIf(runLifecycle)( |
| 40 | "createCustomersConfigurations without zero-touch access fails with a typed entitlement error", |
| 41 | (stack) => |
| 42 | Effect.gen(function* () { |
| 43 | yield* stack.destroy(); |
| 44 | |
| 45 | const error = yield* Effect.flip( |
| 46 | androiddeviceprovisioning.createCustomersConfigurations({ |
| 47 | parent: probeParent, |
| 48 | body: { |
| 49 | configurationName: "Alchemy Probe", |
| 50 | dpcResourcePath: `${probeParent}/dpcs/0`, |
| 51 | companyName: "Alchemy", |
| 52 | contactEmail: "alchemy-test@example.com", |
| 53 | contactPhone: "+1 555 0100", |
| 54 | isDefault: false, |
| 55 | }, |
| 56 | }), |
| 57 | ); |
| 58 | expect(error._tag).toEqual("InsufficientAuthenticationScopes"); |
| 59 | |
| 60 | yield* stack.destroy(); |
| 61 | }).pipe(logLevel), |
| 62 | { |
| 63 | tags: ["provider:gcp", "provider:gcp:androiddeviceprovisioning", "live"], |
| 64 | timeout: 90_000, |
| 65 | }, |
| 66 | ); |
| 67 | |
| 68 | test.provider.skipIf(!runLifecycle)( |
| 69 | "create, update, and delete a configuration", |
| 70 | (stack) => |
| 71 | Effect.gen(function* () { |
| 72 | yield* stack.destroy(); |
| 73 | |
| 74 | const parent = customerName!; |
| 75 | const dpcResourcePath = yield* resolveDpc(parent); |
| 76 | |
| 77 | const created = yield* stack.deploy( |
| 78 | Effect.gen(function* () { |
| 79 | return yield* GCP.AndroidDeviceProvisioning.CustomersConfiguration( |
| 80 | "Sales", |
| 81 | { |
| 82 | parent, |
| 83 | dpcResourcePath, |
| 84 | companyName: "Alchemy", |
| 85 | contactEmail: "alchemy-test@example.com", |
| 86 | contactPhone: "+1 555 0100", |
| 87 | configurationName: "Sales team", |
| 88 | isDefault: false, |
| 89 | }, |
| 90 | ); |
| 91 | }), |
| 92 | ); |
| 93 | |
| 94 | expect(created.name).toContain("/configurations/"); |
| 95 | expect(created.parent).toEqual(parent); |
| 96 | expect(created.configurationId.length).toBeGreaterThan(0); |
| 97 | expect(created.configurationName).toEqual("Sales team"); |
| 98 | expect(created.companyName).toEqual("Alchemy"); |
| 99 | expect(created.contactEmail).toEqual("alchemy-test@example.com"); |
| 100 | expect(created.isDefault).toEqual(false); |
| 101 | |
| 102 | const fetched = |
| 103 | yield* androiddeviceprovisioning.getCustomersConfigurations({ |
| 104 | name: created.name, |
| 105 | }); |
| 106 | expect(fetched.name).toEqual(created.name); |
| 107 | expect(fetched.configurationName).toContain("[alchemy "); |
| 108 | |
| 109 | const updated = yield* stack.deploy( |
| 110 | Effect.gen(function* () { |
| 111 | return yield* GCP.AndroidDeviceProvisioning.CustomersConfiguration( |
| 112 | "Sales", |
| 113 | { |
| 114 | parent: created.parent, |
| 115 | configurationId: created.configurationId, |
| 116 | dpcResourcePath: created.dpcResourcePath ?? dpcResourcePath, |
| 117 | companyName: created.companyName ?? "Alchemy", |
| 118 | contactEmail: "help@example.com", |
| 119 | contactPhone: created.contactPhone ?? "+1 555 0100", |
| 120 | configurationName: "Field sales", |
| 121 | customMessage: "Contact IT for setup help.", |
| 122 | isDefault: false, |
| 123 | }, |
| 124 | ); |
| 125 | }), |
| 126 | ); |
| 127 | |
| 128 | expect(updated.name).toEqual(created.name); |
| 129 | expect(updated.configurationName).toEqual("Field sales"); |
| 130 | expect(updated.contactEmail).toEqual("help@example.com"); |
| 131 | expect(updated.customMessage).toEqual("Contact IT for setup help."); |
| 132 | |
| 133 | const fetchedUpdate = |
| 134 | yield* androiddeviceprovisioning.getCustomersConfigurations({ |
| 135 | name: updated.name, |
| 136 | }); |
| 137 | expect(fetchedUpdate.configurationName).toContain("Field sales"); |
| 138 | expect(fetchedUpdate.contactEmail).toEqual("help@example.com"); |
| 139 | |
| 140 | yield* stack.destroy(); |
| 141 | |
| 142 | const gone = yield* waitUntilGone(created.name); |
| 143 | expect(gone).toEqual("gone"); |
| 144 | }).pipe(logLevel), |
| 145 | { |
| 146 | tags: ["provider:gcp", "provider:gcp:androiddeviceprovisioning", "live"], |
| 147 | timeout: 90_000, |
| 148 | }, |
| 149 | ); |