Files
bindery/tests/js/proxy-reload.test.mjs
tim 3e29ab6bf0 Name downloaded books with a template
The new "Book Downloads" group in Settings holds a Calibre template for the file name of a
direct download. Without a template, the name stays the title. The name is also the title if
the template fails or gives no name for a book.
2026-10-03 08:09:41 +02:00

32 lines
1.3 KiB
JavaScript

import assert from 'node:assert/strict';
import { test } from 'node:test';
import { find, install, server, settle } from './flow-helpers.mjs';
const ui = install();
const { api, setUnauthorizedHandler } = await import('../../bindery/static/js/lib.js');
const { stopPolling } = await import('../../bindery/static/js/jobs.js');
// The proxy login page has no form to retry from, and a fetch keeps the proxy's own session
// cookie, so only a full page load lets the proxy step in again.
test('a 401 while logged in through the proxy reloads the page', async (t) => {
t.after(() => {
stopPolling();
setUnauthorizedHandler(() => {});
});
const backend = server(t);
backend.on('GET', 'auth/check', { authenticated: true, mode: 'proxy', user: 'alice' });
backend.on('GET', 'config', { metadata_fields: {}, mode_labels: {}, library_available: false, download_fields: {} });
backend.on('GET', 'jobs', []);
backend.on('GET', 'stories', []);
backend.on('GET', 'expired', { error: 'Session ended' }, 401);
await import('../../bindery/static/js/main.js');
await settle();
assert.match(ui.app.textContent, /alice/);
let reloaded = 0;
window.location.reload = () => reloaded++;
await assert.rejects(api('expired'), /Session ended/);
await settle();
assert.equal(reloaded, 1);
assert.equal(backend.sent('GET', 'auth/check').length, 1);
});