refactor: 도메인이 100개 1000개씩 늘어나도 유지보수 쉬운 구조로 변경
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import { readFile, readdir } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createFailure } from "../../../src/contracts/errors.ts";
|
||||
import { isAppError } from "../../../src/platform/errors/app-error.ts";
|
||||
import {
|
||||
REFERENCE_ERRORS,
|
||||
toReferenceError,
|
||||
type ReferenceError,
|
||||
} from "../../../src/features/reference-feature/application/reference-error.ts";
|
||||
|
||||
describe("reference feature-local errors", () => {
|
||||
it("keeps concrete error kinds feature-local", () => {
|
||||
const error: ReferenceError = {
|
||||
kind: "reference.not-found",
|
||||
category: "domain",
|
||||
severity: "warning",
|
||||
retryability: "never",
|
||||
};
|
||||
|
||||
expect(isAppError(error)).toBe(true);
|
||||
for (const known of Object.values(REFERENCE_ERRORS)) {
|
||||
expect(isAppError(known)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("interprets only its own domain outcomes", () => {
|
||||
expect(toReferenceError(createFailure("NOT_FOUND", "GET_REFERENCE_RESOURCE", 0))).toBe(
|
||||
REFERENCE_ERRORS.NOT_FOUND,
|
||||
);
|
||||
expect(toReferenceError(createFailure("CONFLICT", "CREATE_REFERENCE_RESOURCE", 0))).toBe(
|
||||
REFERENCE_ERRORS.CONFLICT,
|
||||
);
|
||||
expect(
|
||||
toReferenceError(createFailure("NETWORK_UNREACHABLE", "GET_REFERENCE_RESOURCE", 0)),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("is not referenced by any global or central error union", async () => {
|
||||
const offenders: string[] = [];
|
||||
const walk = async (directory: string): Promise<void> => {
|
||||
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
||||
const target = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
if (!target.endsWith(path.join("features", "reference-feature"))) {
|
||||
await walk(target);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!/\.tsx?$/u.test(entry.name)) continue;
|
||||
const source = await readFile(target, "utf8");
|
||||
if (/reference-error\.ts|ReferenceError\b(?!Boundary)/u.test(source)) {
|
||||
offenders.push(target);
|
||||
}
|
||||
}
|
||||
};
|
||||
await walk(path.resolve("src"));
|
||||
expect(offenders).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user