📄 src/downloader/test/keys.test.ts
D-OPEN SOVEREIGN
1import { describe, it, expect } from 'vitest';
2import { CACHES, CACHE_VERSION, pdfKey, previewKey, pageKey } from '../keys';
3
4describe('keys', () => {
5    it('names caches with the current version', () => {
6        expect(CACHES.pdf).toBe(`dl2-pdf-v${CACHE_VERSION}`);
7        expect(CACHES.preview).toBe(`dl2-preview-v${CACHE_VERSION}`);
8        expect(CACHES.pages).toBe(`dl2-pages-v${CACHE_VERSION}`);
9    });
10
11    it('pdfKey and previewKey share the same /ar/<txId> path', () => {
12        expect(pdfKey('abc123')).toBe('/ar/abc123');
13        expect(previewKey('abc123')).toBe('/ar/abc123');
14        expect(pdfKey('abc123')).toBe(previewKey('abc123'));
15    });
16
17    it('pageKey encodes the txId and appends the page number', () => {
18        expect(pageKey('abc123', 4)).toBe('/pages/abc123/4');
19    });
20
21    it('pageKey URL-encodes txIds with special characters', () => {
22        expect(pageKey('a/b c', 0)).toBe(`/pages/${encodeURIComponent('a/b c')}/0`);
23    });
24});
25