@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, 03:37 UTC

main
ts 50 lines 1.98 KB
Raw
1 import * as NodeServices from "@effect/platform-node/NodeServices";
2 import { GUEST_MESSAGE_MAX_LENGTH } from "@t3tools/contracts";
3 import { assert, it } from "@effect/vitest";
4 import * as Effect from "effect/Effect";
5 import { HttpServerRequest } from "effect/http";
6
7 import { readSubmission } from "./http.ts";
8
9 it.effect("keeps a JSON file a guest attaches as a file, not a form field", () =>
10 Effect.gen(function* () {
11 const form = new FormData();
12 form.append("shareId", "share-1");
13 form.append("text", "");
14 form.append("file", new File(['{"a":1}'], "data.json", { type: "application/json" }));
15 const request = HttpServerRequest.fromWeb(
16 new Request("http://localhost/api/guest/messages?share=share-1", {
17 method: "POST",
18 body: form,
19 }),
20 );
21 const submission = yield* readSubmission.pipe(
22 Effect.provideService(HttpServerRequest.HttpServerRequest, request),
23 );
24 assert.deepEqual(
25 submission?.uploads.map((upload) => [upload.name, upload.contentType]),
26 [["data.json", "application/json"]],
27 );
28 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
29 );
30
31 it.effect("keeps a multi-line form message within the length limit as the guest typed it", () =>
32 Effect.gen(function* () {
33 // At the limit with LF, over it once each line break is counted as CRLF.
34 const lines = Array.from({ length: 50 }, () => "x".repeat(79));
35 const text = lines.join("\n").padEnd(GUEST_MESSAGE_MAX_LENGTH, "x");
36 const form = new FormData();
37 form.append("shareId", "share-1");
38 form.append("text", text);
39 const request = HttpServerRequest.fromWeb(
40 new Request("http://localhost/api/guest/messages?share=share-1", {
41 method: "POST",
42 body: form,
43 }),
44 );
45 const submission = yield* readSubmission.pipe(
46 Effect.provideService(HttpServerRequest.HttpServerRequest, request),
47 );
48 assert.strictEqual(submission?.fields.text, text);
49 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
50 );