Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

http.test.ts

52 lines1.6 KB

1import { assert, it } from "@effect/vitest";
2import { ProjectId } from "@t3tools/contracts";
3import * as Effect from "effect/Effect";
4​
5import {
6 ProjectConflictError,
7 ProjectNotFoundError,
8 ProjectOperationError,
9} from "./ProjectService.ts";
10import { ServerRuntimeStartupError } from "../serverRuntimeStartup.ts";
11import { failProjectMutation } from "./http.ts";
12​
13const projectId = ProjectId.make("project:http-mutation");
14​
15it.effect.each([
16 new ProjectNotFoundError({ projectId }),
17 new ProjectConflictError({
18 projectId,
19 workspaceRoot: "/workspace/project",
20 conflictingProjectId: ProjectId.make("project:http-mutation-conflict"),
21 }),
22])("maps expected project mutation failures to invalid requests", (cause) =>
23 Effect.gen(function* () {
24 const error = yield* failProjectMutation(cause).pipe(Effect.flip);
25​
26 assert.equal(error._tag, "EnvironmentRequestInvalidError");
27 assert.equal(error.code, "invalid_request");
28 assert.equal(error.reason, "invalid_command");
29 }),
30);
31​
32it.effect.each([
33 new ProjectOperationError({
34 operation: "dispatch-project-command",
35 projectId,
36 cause: "database unavailable",
37 }),
38 new ServerRuntimeStartupError({
39 mode: "web",
40 host: null,
41 port: 0,
42 cause: "startup unavailable",
43 }),
44])("keeps operational and startup failures internal", (cause) =>
45 Effect.gen(function* () {
46 const error = yield* failProjectMutation(cause).pipe(Effect.flip);
47​
48 assert.equal(error._tag, "EnvironmentInternalError");
49 assert.equal(error.code, "internal_error");
50 assert.equal(error.reason, "project_mutation_failed");
51 }),
52);