Refactor code structure for improved readability and maintainability
This commit is contained in:
27
test/errors.test.js
Normal file
27
test/errors.test.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { apiError, describe, sourceError } from "../server/errors.js";
|
||||
|
||||
test("Ошибки API: код и статус для клиентов", () => {
|
||||
assert.deepEqual(describe(apiError(404, "group_not_found", "В документе нет группы 1-А.")), {
|
||||
status: 404,
|
||||
code: "group_not_found",
|
||||
message: "В документе нет группы 1-А.",
|
||||
});
|
||||
assert.deepEqual(describe({ code: "LIMIT_FILE_SIZE" }).code, "file_too_large");
|
||||
// Faults of the server itself never show their technical text.
|
||||
const internal = describe(new TypeError("Cannot read properties of undefined"));
|
||||
assert.equal(internal.status, 500);
|
||||
assert.equal(internal.code, "internal");
|
||||
assert.doesNotMatch(internal.message, /undefined/);
|
||||
});
|
||||
|
||||
test("Ошибки источника: таймаут curl отдельно от недоступности", () => {
|
||||
assert.equal(sourceError({ code: 28 }).code, "source_timeout");
|
||||
assert.equal(sourceError({ code: 28 }).status, 504);
|
||||
assert.equal(sourceError({ killed: true, signal: "SIGTERM" }).code, "source_timeout");
|
||||
assert.equal(sourceError({ code: 6 }).code, "source_unavailable");
|
||||
assert.equal(sourceError({ code: 22 }).status, 502);
|
||||
const own = apiError(502, "source_invalid", "Таблица недель не распознана.");
|
||||
assert.equal(sourceError(own), own);
|
||||
});
|
||||
Reference in New Issue
Block a user