| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Test from "@/Test/Alchemy"; |
| 3 | import * as marketplace from "@distilled.cloud/gcp/authorizedbuyersmarketplace_v1"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import { |
| 7 | lifecycleParent, |
| 8 | logLevel, |
| 9 | probeName, |
| 10 | probeParent, |
| 11 | waitUntilGone, |
| 12 | } from "./common.ts"; |
| 13 | |
| 14 | const { test } = Test.make({ providers: GCP.providers() }); |
| 15 | |
| 16 | test.provider( |
| 17 | "getBuyersClientsUsers without the Marketplace OAuth scope fails with AuthorizedBuyersScopeInsufficient", |
| 18 | (stack) => |
| 19 | Effect.gen(function* () { |
| 20 | yield* stack.destroy(); |
| 21 | |
| 22 | const error = yield* Effect.flip( |
| 23 | marketplace.getBuyersClientsUsers({ name: probeName }), |
| 24 | ); |
| 25 | expect(error._tag).toEqual("AuthorizedBuyersScopeInsufficient"); |
| 26 | |
| 27 | yield* stack.destroy(); |
| 28 | }).pipe(logLevel), |
| 29 | { |
| 30 | tags: ["provider:gcp", "provider:gcp:authorizedbuyersmarketplace", "live"], |
| 31 | timeout: 90_000, |
| 32 | }, |
| 33 | ); |
| 34 | |
| 35 | test.provider( |
| 36 | "createBuyersClientsUsers without the Marketplace OAuth scope fails with AuthorizedBuyersScopeInsufficient", |
| 37 | (stack) => |
| 38 | Effect.gen(function* () { |
| 39 | yield* stack.destroy(); |
| 40 | |
| 41 | const error = yield* Effect.flip( |
| 42 | marketplace.createBuyersClientsUsers({ |
| 43 | parent: probeParent, |
| 44 | body: { email: "alchemy-abm-probe@example.com" }, |
| 45 | }), |
| 46 | ); |
| 47 | expect(error._tag).toEqual("AuthorizedBuyersScopeInsufficient"); |
| 48 | |
| 49 | yield* stack.destroy(); |
| 50 | }).pipe(logLevel), |
| 51 | { |
| 52 | tags: ["provider:gcp", "provider:gcp:authorizedbuyersmarketplace", "live"], |
| 53 | timeout: 90_000, |
| 54 | }, |
| 55 | ); |
| 56 | |
| 57 | test.provider.skipIf(!!process.env.FAST || lifecycleParent === undefined)( |
| 58 | "create, update, and delete a client user", |
| 59 | (stack) => |
| 60 | Effect.gen(function* () { |
| 61 | yield* stack.destroy(); |
| 62 | |
| 63 | const parent = lifecycleParent!; |
| 64 | const created = yield* stack.deploy( |
| 65 | Effect.gen(function* () { |
| 66 | return yield* GCP.AuthorizedBuyersMarketplace.BuyersClientsUser( |
| 67 | "Analyst", |
| 68 | { parent, email: "analyst@example.com" }, |
| 69 | ); |
| 70 | }), |
| 71 | ); |
| 72 | |
| 73 | expect(created.name).toContain("/users/"); |
| 74 | expect(created.parent).toEqual(parent); |
| 75 | expect(created.email).toEqual("analyst@example.com"); |
| 76 | expect(created.userId.length).toBeGreaterThan(0); |
| 77 | expect(["INVITED", "ACTIVE", "INACTIVE"]).toContain(created.state); |
| 78 | |
| 79 | const fetched = yield* marketplace.getBuyersClientsUsers({ |
| 80 | name: created.name, |
| 81 | }); |
| 82 | expect(fetched.name).toEqual(created.name); |
| 83 | expect(fetched.email).toEqual("analyst@example.com"); |
| 84 | |
| 85 | const updated = yield* stack.deploy( |
| 86 | Effect.gen(function* () { |
| 87 | return yield* GCP.AuthorizedBuyersMarketplace.BuyersClientsUser( |
| 88 | "Analyst", |
| 89 | { |
| 90 | parent: created.parent, |
| 91 | email: "analyst@example.com", |
| 92 | }, |
| 93 | ); |
| 94 | }), |
| 95 | ); |
| 96 | |
| 97 | expect(updated.name).toEqual(created.name); |
| 98 | expect(updated.email).toEqual("analyst@example.com"); |
| 99 | expect(updated.userId).toEqual(created.userId); |
| 100 | |
| 101 | const replaced = yield* stack.deploy( |
| 102 | Effect.gen(function* () { |
| 103 | return yield* GCP.AuthorizedBuyersMarketplace.BuyersClientsUser( |
| 104 | "Analyst", |
| 105 | { |
| 106 | parent: created.parent, |
| 107 | email: "analyst-v2@example.com", |
| 108 | }, |
| 109 | ); |
| 110 | }), |
| 111 | ); |
| 112 | |
| 113 | expect(replaced.email).toEqual("analyst-v2@example.com"); |
| 114 | expect(replaced.parent).toEqual(created.parent); |
| 115 | |
| 116 | const fetchedReplace = yield* marketplace.getBuyersClientsUsers({ |
| 117 | name: replaced.name, |
| 118 | }); |
| 119 | expect(fetchedReplace.email).toEqual("analyst-v2@example.com"); |
| 120 | |
| 121 | yield* stack.destroy(); |
| 122 | |
| 123 | const gone = yield* waitUntilGone(replaced.name); |
| 124 | expect(gone).toEqual("gone"); |
| 125 | }).pipe(logLevel), |
| 126 | { |
| 127 | tags: ["provider:gcp", "provider:gcp:authorizedbuyersmarketplace", "live"], |
| 128 | timeout: 90_000, |
| 129 | }, |
| 130 | ); |