release: v0.19.0
Release v0.19.0. See the `## [0.19.0] — 2026-09-29` section of [CHANGELOG.md](https://github.com/ralksta/immich-folio/blob/dev/CHANGELOG.md) for the full list. Highlights: client proofing links (#683), custom content pages (#738), asset picker search (#740), concurrent-edit detection (#742), env-locked settings (#739), an accessibility baseline (#741), three security fixes with advisories (#737, #755, #759), and a pre-release quality pass (#780–#797). --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: ralksta <ralksta@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Ralf <rohlenbo79@gmail.com> Co-authored-by: Paul Thies <110185070+ImScheinox@users.noreply.github.com> Co-authored-by: lancetm714 <108419425+lancetm714@users.noreply.github.com> Co-authored-by: Lance Martin <lancetaylor95@gmail.com>
This commit is contained in:
97
lib/__tests__/pages-service.test.ts
Normal file
97
lib/__tests__/pages-service.test.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { mkdtemp, mkdir, readdir, readFile, rm, writeFile } from 'fs/promises';
|
||||
|
||||
/**
|
||||
* content/pages/ storage (#722): the journal's rules — valid slugs only, a
|
||||
* backup before every overwrite, ten saves kept, a `.deleted.bak` on delete.
|
||||
*/
|
||||
let root: string;
|
||||
let pagesDir: string;
|
||||
let backupDir: string;
|
||||
let service: typeof import('../admin/pages-service');
|
||||
|
||||
beforeEach(async () => {
|
||||
root = await mkdtemp(path.join(os.tmpdir(), 'folio-pages-'));
|
||||
pagesDir = path.join(root, 'content', 'pages');
|
||||
backupDir = path.join(pagesDir, '.backups');
|
||||
vi.spyOn(process, 'cwd').mockReturnValue(root);
|
||||
vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||
vi.resetModules();
|
||||
service = await import('../admin/pages-service');
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
vi.restoreAllMocks();
|
||||
await rm(root, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
const page = (title: string, extra = '') =>
|
||||
`---\ntitle: "${title}"\n${extra}---\n\nAbout ${title}\n`;
|
||||
|
||||
describe('pages-service', () => {
|
||||
it('writes, reads and lists a page', async () => {
|
||||
await service.writePage('pricing', page('Pricing', 'draft: true\n'));
|
||||
|
||||
const read = await service.readPage('pricing');
|
||||
expect(read?.parsed.frontmatter).toMatchObject({ title: 'Pricing', draft: true });
|
||||
expect(service.readPageSync('pricing')?.rawMarkdown).toBe(read?.rawMarkdown);
|
||||
|
||||
const list = await service.listPages();
|
||||
expect(list).toEqual([
|
||||
{ slug: 'pricing', frontmatter: expect.objectContaining({ title: 'Pricing' }) },
|
||||
]);
|
||||
expect(service.listPageSlugsSync()).toEqual(['pricing']);
|
||||
});
|
||||
|
||||
it('keeps the SEO description in the frontmatter', async () => {
|
||||
await service.writePage('faq', page('FAQ', 'description: "Questions, answered"\n'));
|
||||
expect((await service.readPage('faq'))?.parsed.frontmatter.description).toBe(
|
||||
'Questions, answered',
|
||||
);
|
||||
});
|
||||
|
||||
it('refuses a slug that is not one, and never touches a path outside', async () => {
|
||||
await expect(service.writePage('../escape', 'x')).rejects.toThrow(/Invalid page slug/);
|
||||
await expect(service.writePage('a/b', 'x')).rejects.toThrow(/Invalid page slug/);
|
||||
expect(await service.readPage('../gallery')).toBeNull();
|
||||
expect(service.resolvePageFilePath('..')).toBeNull();
|
||||
});
|
||||
|
||||
it('answers null for a page that does not exist', async () => {
|
||||
expect(await service.readPage('nothing')).toBeNull();
|
||||
expect(await service.listPages()).toEqual([]);
|
||||
});
|
||||
|
||||
it('backs up the previous version before an overwrite, keeping ten', async () => {
|
||||
await mkdir(pagesDir, { recursive: true });
|
||||
await writeFile(path.join(pagesDir, 'pricing.md'), page('v0'));
|
||||
for (let i = 1; i <= 12; i++) {
|
||||
await service.writePage('pricing', page(`v${i}`));
|
||||
// Distinct timestamps in the backup names.
|
||||
await new Promise((r) => setTimeout(r, 2));
|
||||
}
|
||||
const backups = await readdir(backupDir);
|
||||
expect(backups).toHaveLength(10);
|
||||
expect(await readFile(path.join(pagesDir, 'pricing.md'), 'utf8')).toBe(page('v12'));
|
||||
});
|
||||
|
||||
it('keeps a .deleted.bak copy on delete, and restores from it', async () => {
|
||||
await service.writePage('workshops', page('Workshops'));
|
||||
await expect(service.deletePage('workshops')).resolves.toBe(true);
|
||||
await expect(service.deletePage('workshops')).resolves.toBe(false);
|
||||
expect(await service.readPage('workshops')).toBeNull();
|
||||
|
||||
const [backup] = await service.listPageBackups();
|
||||
expect(backup).toMatchObject({ slug: 'workshops', kind: 'deleted' });
|
||||
|
||||
await expect(service.restorePageBackup(backup.filename)).resolves.toBe('workshops');
|
||||
expect((await service.readPage('workshops'))?.parsed.frontmatter.title).toBe('Workshops');
|
||||
});
|
||||
|
||||
it('refuses to restore from a name it did not write', async () => {
|
||||
await expect(service.restorePageBackup('../gallery.yaml')).rejects.toThrow(/unrecognised/);
|
||||
await expect(service.restorePageBackup('pricing.md')).rejects.toThrow(/unrecognised/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user