logos-storage-js/src/debug/debug.test.ts

46 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-09-13 19:45:59 +02:00
import { afterEach, assert, describe, it, vi } from "vitest";
import { CodexDebug } from "./debug";
2024-08-15 12:08:51 +02:00
import type { CodexLogLevel } from "./types";
2024-09-27 17:35:50 +02:00
import { CodexError } from "../errors/errors";
2024-08-15 12:08:51 +02:00
describe("debug", () => {
afterEach(() => {
vi.restoreAllMocks();
});
const debug = new CodexDebug("http://localhost:3000");
2024-08-15 12:08:51 +02:00
it("returns an error when trying to setup the log level with a bad value", async () => {
const response = await debug.setLogLevel("TEST" as CodexLogLevel);
assert.deepStrictEqual(response, {
error: true,
2024-09-27 17:35:50 +02:00
data: new CodexError("Cannot validate the input", {
2024-08-15 12:08:51 +02:00
errors: [
{
expected:
'"TRACE" | "DEBUG" | "INFO" | "NOTICE" | "WARN" | "ERROR" | "FATAL"',
message:
'Invalid type: Expected "TRACE" | "DEBUG" | "INFO" | "NOTICE" | "WARN" | "ERROR" | "FATAL" but received "TEST"',
path: undefined,
received: '"TEST"',
},
],
2024-09-27 17:35:50 +02:00
}),
2024-08-15 12:08:51 +02:00
});
});
2024-09-13 22:30:37 +02:00
it("returns a success when trying to setup the log level with a correct value", async () => {
2024-09-13 20:45:30 +02:00
const mockResponse = {
ok: true,
status: 200,
text: async () => "",
} as Response;
globalThis.fetch = vi.fn().mockResolvedValue(mockResponse);
2024-08-15 12:08:51 +02:00
2024-09-13 20:45:30 +02:00
const response = await debug.setLogLevel("ERROR");
2024-08-15 12:08:51 +02:00
2024-09-13 20:45:30 +02:00
assert.deepStrictEqual(response, { error: false, data: "" });
});
2024-08-15 12:08:51 +02:00
});