Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
fix: errors.tsとerrors.test.tsを修正、src/entry/main.tsにimportの記述を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
C4N4242 committed Jan 5, 2024
1 parent 79f6a99 commit a47a410
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
47 changes: 32 additions & 15 deletions src/entry/adaptor/errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
// function that takes an error type and returns a string type
// the errors in the conversion source is defined in ../service/entry.test.ts
// the error code of the conversion destination is written in README.md
import { describe, it, expect } from "vitest";

function errorToCode(error: Error): string {
switch (error.message) {
case "too many members":
return "TOO_MANY_MEMBERS";
case "no member":
return "NO_MEMBER";
case "teamName Exists":
return "TEAM_ALREADY_EXISTS";
default:
return "UNKNOWN_ERROR";
}
}
describe("正しくエラーコードに変換できる", () => {
const errorToCode = (error: Error) => {
switch (error.message) {
case "too many members":
return "TOO_MANY_MEMBERS";
case "no member":
return "NO_MEMBER";
case "teamName Exists":
return "TEAM_ALREADY_EXISTS";
default:
return "UNKNOWN_ERROR";
}
};
it("too many members", () => {
const error = new Error("too many members");
expect(errorToCode(error)).toBe("TOO_MANY_MEMBERS");
});
it("no member", () => {
const error = new Error("no member");
expect(errorToCode(error)).toBe("NO_MEMBER");
});
it("teamName Exists", () => {
const error = new Error("teamName Exists");
expect(errorToCode(error)).toBe("TEAM_ALREADY_EXISTS");
});

it("other", () => {
const error = new Error("other");
expect(errorToCode(error)).toBe("UNKNOWN_ERROR");
});
});
14 changes: 13 additions & 1 deletion src/entry/adaptor/errors.ts
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
// write something here
export { errorToCode };
function errorToCode(error: Error): string {
switch (error.message) {
case "too many members":
return "TOO_MANY_MEMBERS";
case "no member":
return "NO_MEMBER";
case "teamName Exists":
return "TEAM_ALREADY_EXISTS";
default:
return "UNKNOWN_ERROR";
}
}
1 change: 1 addition & 0 deletions src/entry/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { entryRequestSchema } from "./schema.js";
import { Controller } from "./controller.js";
import { Result } from "@mikuroxina/mini-fn";
import { JSONEntryRepository } from "./adaptor/json.js";
import { errorToCode } from "./adaptor/errors.ts";

export const entryHandler = new Hono();
// export const controller = new Controller(new DummyRepository());
Expand Down

0 comments on commit a47a410

Please sign in to comment.