Raise Jest coverage above global thresholds.

Add real MCP HTTP/tool/entrypoint tests and extend torrent/qbt coverage
so statements, branches, functions, and lines all meet the configured floors.
This commit is contained in:
2026-08-07 19:37:22 +02:00
parent ac97862edb
commit b04e70e261
5 changed files with 549 additions and 7 deletions

View File

@@ -0,0 +1,88 @@
/**
* mcp.js is a side-effect entrypoint (listen). Load it with mocks so we cover
* wiring without binding a real port.
*/
describe('mcp.js entry', () => {
const originalEnv = { ...process.env };
let listenCb;
let mockApp;
let registerMcpHttp;
beforeEach(() => {
jest.resetModules();
listenCb = null;
mockApp = {
use: jest.fn(),
get: jest.fn((path, handler) => {
mockApp._health = handler;
}),
listen: jest.fn((port, cb) => {
listenCb = cb;
return { close: jest.fn() };
}),
};
const expressFn = jest.fn(() => mockApp);
expressFn.json = jest.fn(() => (req, res, next) => next && next());
jest.doMock('express', () => expressFn);
registerMcpHttp = jest.fn();
jest.doMock('../src/mcp-http', () => ({ registerMcpHttp }));
});
afterEach(() => {
process.env = { ...originalEnv };
jest.resetModules();
jest.dontMock('express');
jest.dontMock('../src/mcp-http');
});
it('registers health + MCP and listens (auth mode)', () => {
process.env.WEBSHARE_USERNAME = 'user';
process.env.WEBSHARE_PASSWORD = 'pass';
process.env.PORT = '3456';
process.env.MCP_PATH = '/custom-mcp';
require('../src/mcp');
expect(mockApp.use).toHaveBeenCalled();
expect(registerMcpHttp).toHaveBeenCalledWith(mockApp, {
username: 'user',
password: 'pass',
path: '/custom-mcp',
});
expect(mockApp.listen).toHaveBeenCalledWith('3456', expect.any(Function));
const res = { json: jest.fn() };
mockApp._health({}, res);
expect(res.json).toHaveBeenCalledWith({
ok: true,
mcp: '/custom-mcp',
guest: false,
});
const log = jest.spyOn(console, 'log').mockImplementation(() => {});
listenCb();
expect(log).toHaveBeenCalledWith(expect.stringMatching(/auth/));
log.mockRestore();
});
it('reports guest mode when credentials missing', () => {
delete process.env.WEBSHARE_USERNAME;
delete process.env.WEBSHARE_PASSWORD;
delete process.env.PORT;
delete process.env.MCP_PATH;
require('../src/mcp');
const res = { json: jest.fn() };
mockApp._health({}, res);
expect(res.json).toHaveBeenCalledWith({
ok: true,
mcp: '/mcp',
guest: true,
});
const log = jest.spyOn(console, 'log').mockImplementation(() => {});
listenCb();
expect(log).toHaveBeenCalledWith(expect.stringMatching(/guest/));
log.mockRestore();
});
});