Files
immich-folio/lib/__tests__/derive-location.test.ts
Ralksta a813433891 release: v0.13.0 (#535)
Twenty-nine commits since v0.12.0. See CHANGELOG.md for the full list
and the upgrade notes.

Ten additions — the SEO package (site URL, robots.txt, sitemap.xml,
JSON-LD), slideshow mode, opt-in original downloads, copy-link,
previous/next album navigation, alt text from the Immich description,
per-album location precision, the update notice, a Help tab, and a
subpage cover grid separate from its photo grid. Two fixes: CJK album
slugs, and the lightbox control bar.

Photo of the Day (#476) was built on `dev` and reverted as not planned;
it never appears in a release.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01DmsHVRL9yQvckUB1ZpVWre

---------

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>
2026-08-25 10:08:12 +02:00

80 lines
2.7 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest';
vi.mock('@/lib/env', () => ({
env: {
IMMICH_API_URL: 'http://localhost:2283',
IMMICH_API_KEY: 'test-key',
SITE_TITLE: 'Test Gallery',
SITE_SUBTITLE: '',
CACHE_TTL: 300,
IMMICH_TIMEOUT_MS: 15000,
RATE_LIMIT_RPM: 120,
TRUSTED_PROXY_HOPS: 0,
},
}));
vi.mock('@/lib/config/parser', () => ({
loadYaml: vi.fn(),
clearYamlCache: vi.fn(),
validateUuid: (id: string) => id,
}));
import { deriveGallery } from '@/lib/config';
import type { GalleryYaml } from '@/lib/config/schema';
const A = '11111111-1111-1111-1111-111111111111';
const B = '22222222-2222-2222-2222-222222222222';
describe('deriveGallery — location precision (#469)', () => {
it('leaves an album without a setting absent, meaning exact', () => {
const gallery: GalleryYaml = { albums: [A] };
expect(deriveGallery(gallery).albumLocationPrecision[A]).toBeUndefined();
});
it('reads a per-album setting', () => {
const gallery: GalleryYaml = { albums: [{ [A]: { location: 'city' } }] };
expect(deriveGallery(gallery).albumLocationPrecision[A]).toBe('city');
});
it('applies a subpage setting to every album on it', () => {
const gallery: GalleryYaml = {
subpages: [{ name: 'Gardens', location: 'country', albums: [A, B] }],
};
const derived = deriveGallery(gallery);
expect(derived.albumLocationPrecision[A]).toBe('country');
expect(derived.albumLocationPrecision[B]).toBe('country');
});
it("lets an album state its own, overriding the subpage's", () => {
const gallery: GalleryYaml = {
subpages: [
{ name: 'Gardens', location: 'city', albums: [A, { [B]: { location: 'hidden' } }] },
],
};
const derived = deriveGallery(gallery);
expect(derived.albumLocationPrecision[A]).toBe('city');
expect(derived.albumLocationPrecision[B]).toBe('hidden');
});
/**
* A typo in a privacy setting must not fall back to `exact` — that would
* publish the position it was meant to withhold.
*/
it('throws on an unknown album value rather than defaulting', () => {
const gallery: GalleryYaml = { albums: [{ [A]: { location: 'приблизительно' } }] };
expect(() => deriveGallery(gallery)).toThrow(/unknown location/i);
});
it('throws on an unknown subpage value', () => {
const gallery: GalleryYaml = {
subpages: [{ name: 'Gardens', location: 'vague', albums: [A] }],
};
expect(() => deriveGallery(gallery)).toThrow(/unknown location/i);
});
it('names the valid values in the error, so the log line is enough to fix it', () => {
const gallery: GalleryYaml = { albums: [{ [A]: { location: 'nope' } }] };
expect(() => deriveGallery(gallery)).toThrow(/exact.*city.*country.*hidden/);
});
});