@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 103 lines 3.3 KB
Raw
1 import * as GCP from "@alchemy.run/gcp";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as saasservicemgmt from "@distilled.cloud/gcp/saasservicemgmt_v1";
5 import * as Effect from "effect/Effect";
6 import { location, logLevel, currentProject, runLifecycle, waitUntilGone } from "./common.ts";
7
8 const { test } = Test.make({ providers: GCP.providers() });
9
10 test.provider(
11 "getProjectsLocationsTenants on a missing tenant fails with a typed tag",
12 (stack) =>
13 Effect.gen(function* () {
14 const project = yield* currentProject;
15 yield* stack.destroy();
16
17 const error = yield* Effect.flip(
18 saasservicemgmt.getProjectsLocationsTenants({
19 name: `projects/${project}/locations/${location}/tenants/alchemy-missing-tnt`,
20 }),
21 );
22 expect(error._tag).toEqual("NotFound");
23
24 yield* stack.destroy();
25 }).pipe(logLevel),
26 {
27 tags: ["provider:gcp", "provider:gcp:saasservicemgmt", "live"],
28 timeout: 90_000,
29 },
30 );
31
32 test.provider.skipIf(!runLifecycle)(
33 "create, update, and delete a tenant",
34 (stack) =>
35 Effect.gen(function* () {
36 yield* stack.destroy();
37
38 const created = yield* stack.deploy(
39 Effect.gen(function* () {
40 const product = yield* GCP.SaasServiceManagement.Saa("Inventory", {
41 location,
42 locations: [{ name: location }],
43 labels: { env: "test" },
44 });
45 const tenant = yield* GCP.SaasServiceManagement.Tenant("Acme", {
46 location,
47 saas: product.name,
48 labels: { env: "test" },
49 });
50 return { product, tenant };
51 }),
52 );
53
54 expect(created.tenant.name).toContain("/tenants/");
55 expect(created.tenant.saasId).toEqual(created.product.saasId);
56 expect(created.tenant.labels).toMatchObject({ env: "test" });
57
58 const fetched = yield* saasservicemgmt.getProjectsLocationsTenants({
59 name: created.tenant.name,
60 });
61 expect(fetched.name).toEqual(created.tenant.name);
62 expect(fetched.labels?.env).toEqual("test");
63 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
64 true,
65 );
66
67 const updated = yield* stack.deploy(
68 Effect.gen(function* () {
69 const product = yield* GCP.SaasServiceManagement.Saa("Inventory", {
70 saasId: created.product.saasId,
71 location,
72 locations: [{ name: location }],
73 labels: { env: "test" },
74 });
75 const tenant = yield* GCP.SaasServiceManagement.Tenant("Acme", {
76 tenantId: created.tenant.tenantId,
77 location,
78 saas: product.name,
79 labels: { env: "prod", customer: "acme" },
80 });
81 return { product, tenant };
82 }),
83 );
84
85 expect(updated.tenant.name).toEqual(created.tenant.name);
86 expect(updated.tenant.labels).toMatchObject({
87 env: "prod",
88 customer: "acme",
89 });
90
91 yield* stack.destroy();
92 const gone = yield* waitUntilGone(
93 saasservicemgmt.getProjectsLocationsTenants({
94 name: created.tenant.name,
95 }),
96 );
97 expect(gone).toEqual("gone");
98 }).pipe(logLevel),
99 {
100 tags: ["provider:gcp", "provider:gcp:saasservicemgmt", "live"],
101 timeout: 90_000,
102 },
103 );