@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 100 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 "getProjectsLocationsSaas on a missing saas 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.getProjectsLocationsSaas({
19 name: `projects/${project}/locations/${location}/saas/alchemy-missing-saa`,
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 saas",
34 (stack) =>
35 Effect.gen(function* () {
36 const project = yield* currentProject;
37 yield* stack.destroy();
38
39 const created = yield* stack.deploy(
40 Effect.gen(function* () {
41 return yield* GCP.SaasServiceManagement.Saa("Inventory", {
42 location,
43 locations: [{ name: location }],
44 labels: { env: "test" },
45 });
46 }),
47 );
48
49 expect(created.saasId).toEqual(expect.any(String));
50 expect(created.name).toEqual(
51 `projects/${project}/locations/${location}/saas/${created.saasId}`,
52 );
53 expect(created.location).toEqual(location);
54 expect(created.labels).toMatchObject({ env: "test" });
55 expect(created.createTime).toEqual(expect.any(String));
56
57 const fetched = yield* saasservicemgmt.getProjectsLocationsSaas({
58 name: created.name,
59 });
60 expect(fetched.name).toEqual(created.name);
61 expect(fetched.labels?.env).toEqual("test");
62 expect(Object.keys(fetched.labels ?? {}).some((key) => key.startsWith("alchemy-"))).toEqual(
63 true,
64 );
65
66 const updated = yield* stack.deploy(
67 Effect.gen(function* () {
68 return yield* GCP.SaasServiceManagement.Saa("Inventory", {
69 saasId: created.saasId,
70 location,
71 locations: [{ name: location }, { name: "us-east1" }],
72 labels: { env: "prod", role: "saas" },
73 });
74 }),
75 );
76
77 expect(updated.name).toEqual(created.name);
78 expect(updated.saasId).toEqual(created.saasId);
79 expect(updated.labels).toMatchObject({ env: "prod", role: "saas" });
80 expect(updated.locations.map((item) => item.name).sort()).toEqual(
81 [location, "us-east1"].sort(),
82 );
83
84 const refetched = yield* saasservicemgmt.getProjectsLocationsSaas({
85 name: created.name,
86 });
87 expect(refetched.labels?.env).toEqual("prod");
88 expect(refetched.labels?.role).toEqual("saas");
89
90 yield* stack.destroy();
91 const gone = yield* waitUntilGone(
92 saasservicemgmt.getProjectsLocationsSaas({ name: created.name }),
93 );
94 expect(gone).toEqual("gone");
95 }).pipe(logLevel),
96 {
97 tags: ["provider:gcp", "provider:gcp:saasservicemgmt", "live"],
98 timeout: 90_000,
99 },
100 );