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, 04:45 UTC
| 1 | import { assert, describe, it } from "@effect/vitest"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | |
| 5 | import { makeIsRepositoryStarred, makeStarRepository } from "./driver.ts"; |
| 6 | import * as GitHubRequestPolicy from "./GitHubRequestPolicy.ts"; |
| 7 | import * as GitHubRest from "./GitHubRest.ts"; |
| 8 | |
| 9 | describe("starred", () => { |
| 10 | it.effect("checks and stars only a valid repository, true only on 204", () => { |
| 11 | const paths: Array<string> = []; |
| 12 | const starred = new Set(["user/starred/pingdotgg/t3code"]); |
| 13 | const api = Layer.mock(GitHubRest.GitHubRest)({ |
| 14 | rest: (input) => { |
| 15 | paths.push(`${input.method ?? "GET"} ${input.path}`); |
| 16 | return starred.has(input.path) |
| 17 | ? Effect.succeed({ |
| 18 | status: 204, |
| 19 | headers: {}, |
| 20 | body: "", |
| 21 | truncated: false, |
| 22 | invalidUtf8: false, |
| 23 | }) |
| 24 | : Effect.fail( |
| 25 | new GitHubRequestPolicy.GitHubApiNotFoundError({ |
| 26 | host: input.host, |
| 27 | operation: input.operation, |
| 28 | }), |
| 29 | ); |
| 30 | }, |
| 31 | }); |
| 32 | return Effect.gen(function* () { |
| 33 | const isStarred = yield* makeIsRepositoryStarred; |
| 34 | const star = yield* makeStarRepository; |
| 35 | assert.isTrue(yield* isStarred("github.com", "pingdotgg/t3code")); |
| 36 | assert.isFalse(yield* isStarred("github.com", "pingdotgg/uploadthing")); |
| 37 | assert.isFalse(yield* isStarred("github.com", "pingdotgg/t3code/../../user")); |
| 38 | assert.isFalse(yield* isStarred("github.com", "../repos")); |
| 39 | assert.isTrue(yield* star("github.com", "pingdotgg/t3code")); |
| 40 | assert.isFalse(yield* star("github.com", "pingdotgg/uploadthing")); |
| 41 | assert.isFalse(yield* star("github.com", "pingdotgg/t3code/../../user")); |
| 42 | assert.isFalse(yield* star("github.com", "../repos")); |
| 43 | assert.deepStrictEqual(paths, [ |
| 44 | "GET user/starred/pingdotgg/t3code", |
| 45 | "GET user/starred/pingdotgg/uploadthing", |
| 46 | "PUT user/starred/pingdotgg/t3code", |
| 47 | "PUT user/starred/pingdotgg/uploadthing", |
| 48 | ]); |
| 49 | }).pipe(Effect.provide(api)); |
| 50 | }); |
| 51 | }); |