36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
|
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
||
|
|
import { mkdtempSync, rmSync, readdirSync } from 'node:fs';
|
||
|
|
import { tmpdir } from 'node:os';
|
||
|
|
import { join } from 'node:path';
|
||
|
|
import { openInMemoryForTest } from '../../src/lib/server/db';
|
||
|
|
import { addDomain, listDomains } from '../../src/lib/server/domains/repository';
|
||
|
|
import { ensureFavicons } from '../../src/lib/server/domains/favicons';
|
||
|
|
|
||
|
|
let imageDir: string;
|
||
|
|
|
||
|
|
beforeEach(() => {
|
||
|
|
imageDir = mkdtempSync(join(tmpdir(), 'kochwas-favicon-'));
|
||
|
|
});
|
||
|
|
|
||
|
|
afterEach(() => {
|
||
|
|
rmSync(imageDir, { recursive: true, force: true });
|
||
|
|
});
|
||
|
|
|
||
|
|
describe('ensureFavicons', () => {
|
||
|
|
it('is a no-op when every domain already has a favicon_path', async () => {
|
||
|
|
const db = openInMemoryForTest();
|
||
|
|
const d = addDomain(db, 'example.com');
|
||
|
|
// simulate already-stored favicon
|
||
|
|
db.prepare('UPDATE allowed_domain SET favicon_path = ? WHERE id = ?').run(
|
||
|
|
'favicon-abc.png',
|
||
|
|
d.id
|
||
|
|
);
|
||
|
|
await ensureFavicons(db, imageDir);
|
||
|
|
// No file written, no DB state changed
|
||
|
|
expect(readdirSync(imageDir).length).toBe(0);
|
||
|
|
const domains = listDomains(db);
|
||
|
|
expect(domains[0].favicon_path).toBe('favicon-abc.png');
|
||
|
|
});
|
||
|
|
|
||
|
|
});
|