Fix test isolation to prevent loading real user config
Tests were picking up real ~/.warelay/warelay.json with emojis and
prefixes (like "🦞"), causing test assertions to fail. Added proper
config mocks to all test files.
Changes:
- Mock loadConfig() in index.core.test.ts, inbound.media.test.ts,
monitor-inbox.test.ts
- Update test-helpers.ts default mock to disable all prefixes
- Tests now use clean config: no messagePrefix, no responsePrefix,
no timestamp, allowFrom=["*"]
This ensures tests validate core behavior without user-specific config.
The responsePrefix feature itself is already fully config-driven - this
only fixes test isolation.
This commit is contained in:
@@ -9,6 +9,9 @@ vi.mock("../config/config.js", () => ({
|
||||
loadConfig: vi.fn().mockReturnValue({
|
||||
inbound: {
|
||||
allowFrom: ["*"], // Allow all in tests
|
||||
messagePrefix: undefined,
|
||||
responsePrefix: undefined,
|
||||
timestampPrefix: false,
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
@@ -13,6 +13,9 @@ vi.mock("../config/config.js", () => ({
|
||||
loadConfig: vi.fn().mockReturnValue({
|
||||
inbound: {
|
||||
allowFrom: ["*"], // Allow all in tests
|
||||
messagePrefix: undefined,
|
||||
responsePrefix: undefined,
|
||||
timestampPrefix: false,
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
@@ -3,14 +3,28 @@ import { vi } from "vitest";
|
||||
import type { MockBaileysSocket } from "../../test/mocks/baileys.js";
|
||||
import { createMockBaileys } from "../../test/mocks/baileys.js";
|
||||
|
||||
let loadConfigMock: () => unknown = () => ({});
|
||||
let loadConfigMock: () => unknown = () => ({
|
||||
inbound: {
|
||||
allowFrom: ["*"], // Allow all in tests by default
|
||||
messagePrefix: undefined, // No message prefix in tests
|
||||
responsePrefix: undefined, // No response prefix in tests
|
||||
timestampPrefix: false, // No timestamp in tests
|
||||
},
|
||||
});
|
||||
|
||||
export function setLoadConfigMock(fn: () => unknown) {
|
||||
loadConfigMock = fn;
|
||||
}
|
||||
|
||||
export function resetLoadConfigMock() {
|
||||
loadConfigMock = () => ({});
|
||||
loadConfigMock = () => ({
|
||||
inbound: {
|
||||
allowFrom: ["*"],
|
||||
messagePrefix: undefined,
|
||||
responsePrefix: undefined,
|
||||
timestampPrefix: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
vi.mock("../config/config.js", () => ({
|
||||
|
||||
Reference in New Issue
Block a user