@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 139 lines 4.74 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 firebasedataconnect from "@distilled.cloud/gcp/firebasedataconnect_v1";
5 import * as Effect from "effect/Effect";
6 import * as Schedule from "effect/Schedule";
7 import {
8 location,
9 logLevel,
10 missingSchema,
11 currentProject,
12 schemaSource,
13 unlinkedDatasources,
14 } from "./common.ts";
15
16 const { test } = Test.make({ providers: GCP.providers() });
17
18 const waitUntilGone = (name: string) =>
19 firebasedataconnect.getProjectsLocationsServicesSchemas({ name }).pipe(
20 Effect.as("found" as const),
21 Effect.catchTag("NotFound", () => Effect.succeed("gone" as const)),
22 Effect.repeat({
23 schedule: Schedule.spaced("3 seconds"),
24 until: (status) => status === "gone",
25 times: 10,
26 }),
27 );
28
29 test.provider(
30 "getProjectsLocationsServicesSchemas on a missing schema fails with a typed tag",
31 (stack) =>
32 Effect.gen(function* () {
33 const project = yield* currentProject;
34
35 yield* stack.destroy();
36
37 const missing = yield* missingSchema();
38 const error = yield* Effect.flip(
39 firebasedataconnect.getProjectsLocationsServicesSchemas({
40 name: missing,
41 }),
42 );
43 expect(error._tag).toEqual("NotFound");
44
45 const page = yield* firebasedataconnect.listProjectsLocationsServicesSchemas({
46 parent: `projects/${project}/locations/${location}/services/-`,
47 pageSize: 10,
48 });
49 expect((page.schemas ?? []).map((item) => item.name)).not.toContain(missing);
50
51 yield* stack.destroy();
52 }).pipe(logLevel),
53 {
54 tags: ["provider:gcp", "provider:gcp:firebasedataconnect", "live"],
55 timeout: 90_000,
56 },
57 );
58
59 test.provider(
60 "create, update, and delete a Data Connect schema",
61 (stack) =>
62 Effect.gen(function* () {
63 yield* stack.destroy();
64
65 const created = yield* stack.deploy(
66 Effect.gen(function* () {
67 const service = yield* GCP.FirebaseDataConnect.Service("App", {
68 displayName: "alchemy-test-dataconnect",
69 labels: { env: "test" },
70 });
71 const schema = yield* GCP.FirebaseDataConnect.ServicesSchema("Main", {
72 service: service.name,
73 source: schemaSource(),
74 datasources: unlinkedDatasources,
75 displayName: "alchemy-test-schema",
76 labels: { env: "test" },
77 });
78 return { service, schema };
79 }),
80 );
81
82 expect(created.schema.name).toContain("/schemas/main");
83 expect(created.schema.schemaId).toEqual("main");
84 expect(created.schema.location).toEqual(location);
85 expect(created.schema.displayName).toEqual("alchemy-test-schema");
86 expect(created.schema.labels).toMatchObject({ env: "test" });
87 expect(created.schema.service).toEqual(created.service.name);
88 expect(created.schema.reconciling).toEqual(false);
89
90 const fetched = yield* firebasedataconnect.getProjectsLocationsServicesSchemas({
91 name: created.schema.name,
92 });
93 expect(fetched.name).toEqual(created.schema.name);
94 expect(fetched.displayName).toEqual("alchemy-test-schema");
95 expect(fetched.labels?.env).toEqual("test");
96 expect(fetched.source?.files?.[0]?.path).toEqual("schema.gql");
97
98 const updated = yield* stack.deploy(
99 Effect.gen(function* () {
100 const service = yield* GCP.FirebaseDataConnect.Service("App", {
101 serviceId: created.service.serviceId,
102 displayName: "alchemy-prod-dataconnect",
103 labels: { env: "prod" },
104 });
105 const schema = yield* GCP.FirebaseDataConnect.ServicesSchema("Main", {
106 service: service.name,
107 source: schemaSource("body: String"),
108 datasources: unlinkedDatasources,
109 displayName: "alchemy-prod-schema",
110 labels: { env: "prod", role: "schema" },
111 });
112 return { service, schema };
113 }),
114 );
115
116 expect(updated.schema.name).toEqual(created.schema.name);
117 expect(updated.schema.displayName).toEqual("alchemy-prod-schema");
118 expect(updated.schema.labels).toMatchObject({
119 env: "prod",
120 role: "schema",
121 });
122
123 const refetched = yield* firebasedataconnect.getProjectsLocationsServicesSchemas({
124 name: created.schema.name,
125 });
126 expect(refetched.displayName).toEqual("alchemy-prod-schema");
127 expect(refetched.labels?.env).toEqual("prod");
128 expect(refetched.source?.files?.[0]?.content).toContain("body: String");
129
130 yield* stack.destroy();
131
132 const gone = yield* waitUntilGone(created.schema.name);
133 expect(gone).toEqual("gone");
134 }).pipe(logLevel),
135 {
136 tags: ["provider:gcp", "provider:gcp:firebasedataconnect", "live"],
137 timeout: 120_000,
138 },
139 );