~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
/**
* Regression fence for deleteSubscription's endpoint.
*
* The delete button used to POST to
* /news/api/subscription/subscriptions/{id}, a path that only accepts PUT —
* so every delete 405'd and surfaced as "Failed to delete subscription".
* The live DELETE route is /news/api/subscriptions/{id}; this pins the
* method + URL so the two can't drift apart silently again (the backend
* counterpart is asserted by the FastAPI route-table tests).
*/
import '@js/security/xss-protection.js';
import '@js/components/subscription-manager.js';
let manager;
beforeAll(() => {
if (!window.subscriptionManager) {
document.dispatchEvent(new Event('DOMContentLoaded'));
}
manager = window.subscriptionManager;
});
describe('subscriptionManager.deleteSubscription', () => {
let fetchMock;
beforeEach(() => {
fetchMock = vi.fn().mockResolvedValue({ ok: true });
globalThis.fetch = fetchMock;
// Confirm dialog must accept for the fetch to fire (happy-dom has
// no confirm(); define rather than spy).
window.confirm = vi.fn().mockReturnValue(true);
// Post-delete refresh + toast helpers — stub to isolate the fetch.
vi.spyOn(manager, 'loadSubscriptionData').mockResolvedValue(
undefined
);
vi.spyOn(manager, 'showSuccess').mockImplementation(() => {});
vi.spyOn(manager, 'showError').mockImplementation(() => {});
vi.spyOn(manager, 'getCSRFToken').mockReturnValue('tok');
});
afterEach(() => {
vi.restoreAllMocks();
});
it('sends DELETE to /news/api/subscriptions/{id}', async () => {
await manager.deleteSubscription('sub-123');
expect(fetchMock).toHaveBeenCalledTimes(1);
const [url, options] = fetchMock.mock.calls[0];
expect(url).toBe('/news/api/subscriptions/sub-123');
expect(options.method).toBe('DELETE');
expect(options.headers['X-CSRFToken']).toBe('tok');
expect(manager.showSuccess).toHaveBeenCalled();
expect(manager.loadSubscriptionData).toHaveBeenCalledOnce();
});
it('percent-encodes the ID into one segment of the DELETE path', async () => {
await manager.deleteSubscription('../../api/v1/settings?reset=1#top');
const [url, options] = fetchMock.mock.calls[0];
expect(url).toBe(
'/news/api/subscriptions/..%2F..%2Fapi%2Fv1%2Fsettings%3Freset%3D1%23top'
);
expect(options.method).toBe('DELETE');
// The ID can neither climb out of /news/api/subscriptions/ nor add a
// query string or fragment.
const parsed = new URL(url, 'http://localhost');
expect(parsed.pathname).toBe(url);
expect(parsed.search).toBe('');
expect(parsed.hash).toBe('');
});
it('does not fetch when the confirm dialog is declined', async () => {
window.confirm.mockReturnValue(false);
await manager.deleteSubscription('sub-123');
expect(fetchMock).not.toHaveBeenCalled();
});
it('surfaces an error toast on a non-ok response', async () => {
fetchMock.mockResolvedValue({ ok: false, status: 405 });
await manager.deleteSubscription('sub-123');
expect(manager.showError).toHaveBeenCalled();
expect(manager.showSuccess).not.toHaveBeenCalled();
expect(manager.loadSubscriptionData).not.toHaveBeenCalled();
});
it('does not report success or refresh after a transport failure', async () => {
fetchMock.mockRejectedValue(new Error('network unavailable'));
await manager.deleteSubscription('sub-123');
expect(manager.showError).toHaveBeenCalledWith(
'Error deleting subscription'
);
expect(manager.showSuccess).not.toHaveBeenCalled();
expect(manager.loadSubscriptionData).not.toHaveBeenCalled();
});
});
describe('subscriptionManager.updateSubscription', () => {
let fetchMock;
beforeEach(() => {
fetchMock = vi.fn().mockResolvedValue({ ok: true });
globalThis.fetch = fetchMock;
vi.spyOn(manager, 'loadSubscriptionData').mockResolvedValue(undefined);
vi.spyOn(manager, 'showSuccess').mockImplementation(() => {});
vi.spyOn(manager, 'showError').mockImplementation(() => {});
vi.spyOn(manager, 'getCSRFToken').mockReturnValue('update-token');
});
afterEach(() => {
vi.restoreAllMocks();
});
it('keeps PUT on the nested subscription route and refreshes after success', async () => {
const updates = {
refresh_interval_minutes: 120,
folder: 'papers',
notes: 'Track releases',
};
await manager.updateSubscription('sub-3299', updates);
expect(fetchMock).toHaveBeenCalledWith(
'/news/api/subscription/subscriptions/sub-3299',
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': 'update-token',
},
body: JSON.stringify(updates),
},
);
expect(manager.showSuccess).toHaveBeenCalledWith(
'Subscription updated',
);
expect(manager.loadSubscriptionData).toHaveBeenCalledOnce();
expect(manager.showError).not.toHaveBeenCalled();
});
it('percent-encodes the ID into one segment of the PUT path', async () => {
await manager.updateSubscription('../../api/v1/settings?reset=1#top', {
status: 'paused',
});
const [url, options] = fetchMock.mock.calls[0];
expect(url).toBe(
'/news/api/subscription/subscriptions/..%2F..%2Fapi%2Fv1%2Fsettings%3Freset%3D1%23top'
);
expect(options.method).toBe('PUT');
const parsed = new URL(url, 'http://localhost');
expect(parsed.pathname).toBe(url);
expect(parsed.search).toBe('');
expect(parsed.hash).toBe('');
});
it('does not report success or refresh after a rejected update', async () => {
fetchMock.mockResolvedValue({ ok: false, status: 422 });
await manager.updateSubscription('sub-3299', { status: 'paused' });
expect(manager.showError).toHaveBeenCalledWith(
'Failed to update subscription',
);
expect(manager.showSuccess).not.toHaveBeenCalled();
expect(manager.loadSubscriptionData).not.toHaveBeenCalled();
});
it('does not report success or refresh after an update transport failure', async () => {
fetchMock.mockRejectedValue(new Error('connection reset'));
await manager.updateSubscription('sub-3299', { status: 'active' });
expect(manager.showError).toHaveBeenCalledWith(
'Error updating subscription',
);
expect(manager.showSuccess).not.toHaveBeenCalled();
expect(manager.loadSubscriptionData).not.toHaveBeenCalled();
});
});
describe('subscriptionManager folder and status actions', () => {
let fetchMock;
beforeEach(() => {
fetchMock = vi.fn();
globalThis.fetch = fetchMock;
vi.spyOn(manager, 'loadSubscriptionData').mockResolvedValue(undefined);
vi.spyOn(manager, 'showSuccess').mockImplementation(() => {});
vi.spyOn(manager, 'showError').mockImplementation(() => {});
vi.spyOn(manager, 'getCSRFToken').mockReturnValue('folder-token');
manager.subscriptions = {
Research: [{ id: 'active-sub', status: 'active' }],
Paused: [{ id: 'paused-sub', status: 'paused' }],
};
});
afterEach(() => {
vi.restoreAllMocks();
delete window.prompt;
document.body.replaceChildren();
});
it('derives pause and resume mutations from the owned subscription', async () => {
const update = vi.spyOn(manager, 'updateSubscription')
.mockResolvedValue(true);
await manager.toggleSubscriptionStatus('active-sub');
await manager.toggleSubscriptionStatus('paused-sub');
await manager.toggleSubscriptionStatus('missing-sub');
expect(update.mock.calls).toEqual([
['active-sub', { status: 'paused' }],
['paused-sub', { status: 'active' }],
]);
});
it('switches only the selected folder tab before rendering its cards', () => {
document.body.innerHTML = `
<div id="folderTabs">
<button class="nav-link active" data-folder="all"></button>
<button class="nav-link" data-folder="Research"></button>
</div>
`;
const render = vi.spyOn(manager, 'renderSubscriptions')
.mockImplementation(() => {});
manager.switchFolder('Research');
expect(manager.currentFolder).toBe('Research');
expect(document.querySelector('[data-folder="all"]').classList)
.not.toContain('active');
expect(document.querySelector('[data-folder="Research"]').classList)
.toContain('active');
expect(render).toHaveBeenCalledOnce();
});
it('creates a folder with CSRF and reloads only after success', async () => {
fetchMock.mockResolvedValue({ ok: true });
await manager.createFolder('Migration', '#123456', '🚀');
expect(fetchMock).toHaveBeenCalledWith('/news/api/subscription/folders', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': 'folder-token',
},
body: JSON.stringify({
name: 'Migration',
color: '#123456',
icon: '🚀',
}),
});
expect(manager.showSuccess).toHaveBeenCalledWith('Folder created');
expect(manager.loadSubscriptionData).toHaveBeenCalledOnce();
});
it('surfaces FastAPI detail from a rejected folder create', async () => {
fetchMock.mockResolvedValue({
ok: false,
json: vi.fn().mockResolvedValue({
detail: 'A folder with this name already exists',
}),
});
await manager.createFolder('Migration');
expect(manager.showError).toHaveBeenCalledWith(
'A folder with this name already exists',
);
expect(manager.showSuccess).not.toHaveBeenCalled();
expect(manager.loadSubscriptionData).not.toHaveBeenCalled();
});
it('uses the prompted folder name and ignores a cancelled prompt', () => {
const create = vi.spyOn(manager, 'createFolder').mockResolvedValue();
window.prompt = vi.fn()
.mockReturnValueOnce('Prompted folder')
.mockReturnValueOnce('');
manager.showCreateFolderDialog();
manager.showCreateFolderDialog();
expect(create).toHaveBeenCalledOnce();
expect(create).toHaveBeenCalledWith('Prompted folder');
});
});