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

main
ts 61 lines 1.86 KB
Raw
1 import { expect } from "bun:test";
2 import * as Cloudflare from "@alchemy.run/cloudflare";
3 import * as Test from "@alchemy.run/test/Bun";
4 import * as Effect from "effect/Effect";
5 import * as HttpApiClient from "effect/http-api/HttpApiClient";
6 import * as FetchHttpClient from "effect/http/FetchHttpClient";
7 import * as HttpClientRequest from "effect/http/HttpClientRequest";
8 import Stack from "./alchemy.run.ts";
9 import { ShortyApi } from "./ShortyApi.ts";
10
11 // #region show
12 const { test, beforeAll, deploy } = Test.make({
13 providers: Cloudflare.providers(),
14 // #region dev
15 dev: true,
16 // #endregion dev
17 });
18 // #region deploy
19
20 const stack = beforeAll(deploy(Stack));
21 // #endregion deploy
22 // #region test
23
24 test(
25 "creates and reads back a link",
26 Effect.gen(function* () {
27 const { api } = yield* stack;
28 const shorty = yield* HttpApiClient.make(ShortyApi, { baseUrl: api });
29 // #region create
30
31 const link = yield* shorty.links.create({ payload: { url: "https://effect.website" } });
32 // #endregion create
33 // #region check
34 const found = yield* shorty.links.get({ params: { code: link.code } });
35 expect(found.url).toBe("https://effect.website");
36 // #endregion check
37 }),
38 );
39 // #endregion test
40 // #endregion show
41
42 test(
43 "a missing link is a typed LinkNotFound",
44 Effect.gen(function* () {
45 const { api } = yield* stack;
46 const shorty = yield* HttpApiClient.make(ShortyApi, { baseUrl: api });
47 const error = yield* shorty.links.get({ params: { code: "nope" } }).pipe(Effect.flip);
48 expect(error._tag).toBe("LinkNotFound");
49 }),
50 );
51
52 test(
53 "lists every link",
54 Effect.gen(function* () {
55 const { api } = yield* stack;
56 const response = yield* Test.executeWhenReady(HttpClientRequest.get(`${api}/links`)).pipe(
57 Effect.provideService(FetchHttpClient.RequestInit, { redirect: "manual" }),
58 );
59 expect(response.status).toBe(200);
60 }),
61 );