import { describe, it, expect, vi, beforeEach } from 'vitest' import { AssetType, KeyType } from '../src/types' import type { Asset, SharedLink } from '../src/types' import type { Response } from 'express-serve-static-core' import { findMotionPhotoStill } from '../src/share' import { gallery } from '../src/gallery/builder' /* Motion photos: clip ids stay bounded by the share's own assets, and `motionUrl` is emitted only for images with a clip while `ipp.motionPhotos` is on. Config is mocked per test rather than loaded from a file. */ const cfg: Record = {} vi.mock('../src/config/access', () => ({ getConfigOption: (path: string, fallback?: unknown) => (path in cfg ? cfg[path] : fallback), getNumericConfigOption: (path: string, fallback: number) => (path in cfg ? Number(cfg[path]) : fallback) })) const STILL_ID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' const CLIP_ID = 'dddddddd-dddd-dddd-dddd-dddddddddddd' const UNRELATED_ID = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee' function asset (overrides: Partial = {}): Asset { return { id: STILL_ID, key: 'share-key', keyType: KeyType.key, type: AssetType.image, isTrashed: false, ...overrides } } function share (assets: Asset[]): SharedLink { return { key: 'share-key', keyType: KeyType.key, type: 'INDIVIDUAL', assets, expiresAt: null } } /** Render a gallery for these assets and return the items the client receives. */ async function renderItems (assets: Asset[]) { let html = '' const res = { req: { protocol: 'https', headers: { host: 'example.com' } }, header: () => {}, send: (body: string) => { html = body } } as unknown as Response await gallery(res, share(assets)) const match = html.match(/