@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 116 lines 3.61 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 androidenterprise from "@distilled.cloud/gcp/androidenterprise_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import { enterpriseId, logLevel, probeEnterpriseId, runLifecycle } from "./common.ts";
8
9 const { test } = Test.make({ providers: GCP.providers() });
10
11 const waitUntilGone = (accountId: string, pageId: string) =>
12 androidenterprise.getStorelayoutpages({ enterpriseId: accountId, pageId }).pipe(
13 Effect.as("found" as const),
14 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
15 Effect.repeat({
16 schedule: Schedule.spaced("1 second"),
17 until: (status) => status === "gone",
18 times: 10,
19 }),
20 );
21
22 test.provider.skipIf(!runLifecycle)(
23 "getStorelayoutpages on a missing page fails with a typed tag",
24 (stack) =>
25 Effect.gen(function* () {
26 yield* stack.destroy();
27
28 const error = yield* Effect.flip(
29 androidenterprise.getStorelayoutpages({
30 enterpriseId: probeEnterpriseId,
31 pageId: "alchemy-missing-page",
32 }),
33 );
34 expect(error._tag).toEqual("NotFound");
35
36 yield* stack.destroy();
37 }).pipe(logLevel),
38 {
39 tags: ["provider:gcp", "provider:gcp:androidenterprise", "live"],
40 timeout: 90_000,
41 },
42 );
43
44 test.provider.skipIf(runLifecycle)(
45 "insertStorelayoutpages without the EMM OAuth scope fails with InsufficientAuthenticationScopes",
46 (stack) =>
47 Effect.gen(function* () {
48 yield* stack.destroy();
49
50 const error = yield* Effect.flip(
51 androidenterprise.insertStorelayoutpages({
52 enterpriseId: probeEnterpriseId,
53 body: {
54 name: [{ locale: "en-US", text: "Alchemy Probe Page" }],
55 },
56 }),
57 );
58 expect(error._tag).toEqual("InsufficientAuthenticationScopes");
59
60 yield* stack.destroy();
61 }).pipe(logLevel),
62 {
63 tags: ["provider:gcp", "provider:gcp:androidenterprise", "live"],
64 timeout: 90_000,
65 },
66 );
67
68 test.provider.skipIf(!runLifecycle)(
69 "create, update, and delete a store layout page",
70 (stack) =>
71 Effect.gen(function* () {
72 yield* stack.destroy();
73
74 const created = yield* stack.deploy(
75 Effect.gen(function* () {
76 return yield* GCP.AndroidEnterprise.Storelayoutpage("Home", {
77 enterpriseId: enterpriseId!,
78 name: [{ locale: "en-US", text: "Home" }],
79 });
80 }),
81 );
82
83 expect(created.pageId.length).toBeGreaterThan(0);
84 expect(created.enterpriseId).toEqual(enterpriseId);
85 expect(created.name?.[0]?.text).toEqual("Home");
86
87 const fetched = yield* androidenterprise.getStorelayoutpages({
88 enterpriseId: created.enterpriseId,
89 pageId: created.pageId,
90 });
91 expect(fetched.id).toEqual(created.pageId);
92 expect(fetched.name?.[0]?.text).toEqual("Home");
93
94 const updated = yield* stack.deploy(
95 Effect.gen(function* () {
96 return yield* GCP.AndroidEnterprise.Storelayoutpage("Home", {
97 enterpriseId: created.enterpriseId,
98 pageId: created.pageId,
99 name: [{ locale: "en-US", text: "Featured" }],
100 });
101 }),
102 );
103
104 expect(updated.pageId).toEqual(created.pageId);
105 expect(updated.name?.[0]?.text).toEqual("Featured");
106
107 yield* stack.destroy();
108
109 const gone = yield* waitUntilGone(created.enterpriseId, created.pageId);
110 expect(gone).toEqual("gone");
111 }).pipe(logLevel),
112 {
113 tags: ["provider:gcp", "provider:gcp:androidenterprise", "live"],
114 timeout: 90_000,
115 },
116 );