@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 127 lines 3.9 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 essentialcontacts from "@distilled.cloud/gcp/essentialcontacts_v1";
5 import * as Effect from "effect/Effect";
6 import { MinimumLogLevel } from "effect/References";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info");
12
13 const waitUntilGone = (name: string) =>
14 essentialcontacts.getFoldersContacts({ name }).pipe(
15 Effect.as("found" as const),
16 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
17 Effect.repeat({
18 schedule: Schedule.spaced("1 second"),
19 until: (status) => status === "gone",
20 times: 10,
21 }),
22 );
23
24 // Folder contacts need a folder the test identity can manage contacts on.
25 // Set GOOGLE_FOLDER_ID to run these tests.
26 const folderId = process.env.GOOGLE_FOLDER_ID;
27 const runLifecycle = !!folderId;
28
29 const folderOf = () =>
30 Effect.succeed(
31 folderId === undefined
32 ? ""
33 : folderId.startsWith("folders/")
34 ? folderId
35 : `folders/${folderId}`,
36 );
37
38 test.provider.skipIf(!runLifecycle)(
39 "getFoldersContacts on a missing contact fails with a typed tag",
40 (stack) =>
41 Effect.gen(function* () {
42 yield* stack.destroy();
43
44 const folder = yield* folderOf();
45 const error = yield* Effect.flip(
46 essentialcontacts.getFoldersContacts({
47 name: `${folder}/contacts/0`,
48 }),
49 );
50 expect(error._tag).toEqual("NotFound");
51
52 yield* stack.destroy();
53 }).pipe(logLevel),
54 {
55 tags: ["provider:gcp", "provider:gcp:essentialcontacts", "live"],
56 timeout: 90_000,
57 },
58 );
59
60 test.provider.skipIf(!runLifecycle)(
61 "create, update, replace, and delete a folder essential contact",
62 (stack) =>
63 Effect.gen(function* () {
64 yield* stack.destroy();
65
66 const folder = yield* folderOf();
67
68 const created = yield* stack.deploy(
69 Effect.gen(function* () {
70 return yield* GCP.EssentialContacts.FolderContact("Ops", {
71 folderId: folder,
72 email: "folder-ops@example.com",
73 languageTag: "en-US",
74 notificationCategorySubscriptions: ["ALL"],
75 });
76 }),
77 );
78
79 expect(created.contactId.length).toBeGreaterThan(0);
80 expect(created.parent).toEqual(folder);
81 expect(created.email).toEqual("folder-ops@example.com");
82 expect(created.languageTag).toEqual("en-US");
83
84 const fetched = yield* essentialcontacts.getFoldersContacts({
85 name: created.name,
86 });
87 expect(fetched.name).toEqual(created.name);
88 expect(fetched.email).toContain("+alc.");
89
90 const updated = yield* stack.deploy(
91 Effect.gen(function* () {
92 return yield* GCP.EssentialContacts.FolderContact("Ops", {
93 folderId: folder,
94 email: "folder-ops@example.com",
95 languageTag: "en-GB",
96 notificationCategorySubscriptions: ["TECHNICAL"],
97 });
98 }),
99 );
100
101 expect(updated.name).toEqual(created.name);
102 expect(updated.languageTag).toEqual("en-GB");
103 expect(updated.notificationCategorySubscriptions).toEqual(["TECHNICAL"]);
104
105 const replaced = yield* stack.deploy(
106 Effect.gen(function* () {
107 return yield* GCP.EssentialContacts.FolderContact("Ops", {
108 folderId: folder,
109 email: "folder-sec@example.com",
110 languageTag: "en-GB",
111 notificationCategorySubscriptions: ["SECURITY"],
112 });
113 }),
114 );
115
116 expect(replaced.email).toEqual("folder-sec@example.com");
117
118 yield* stack.destroy();
119
120 const gone = yield* waitUntilGone(replaced.name);
121 expect(gone).toEqual("gone");
122 }).pipe(logLevel),
123 {
124 tags: ["provider:gcp", "provider:gcp:essentialcontacts", "live"],
125 timeout: 90_000,
126 },
127 );