openreader/tests/unit/audiobook-scope.spec.ts
Richard R 1f4794a706 feat(auth): implement session gatekeeping and architectural reorganization
- Introduce `USE_ANONYMOUS_AUTH_SESSIONS` to make guest access an opt-in feature.
- Transition root-level pages into `(app)` and `(public)` route groups for improved access control.
- Adopt Figtree as the primary typeface and implement a pre-render theme initialization script.
- Decouple audiobook chapter processing into a standalone API route and harden resource ownership logic.
- Replace the legacy footer with a unified layout and add skeleton loading states for document lists.
- Update environment documentation and test suites to align with the revised routing and auth flows.

BREAKING CHANGE: The audiobook generation API has been restructured, moving specific chapter logic to `/api/audiobook/chapter`.
2026-02-15 11:12:42 -07:00

36 lines
1.6 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { buildAllowedAudiobookUserIds, pickAudiobookOwner } from '../../src/lib/server/audiobook-scope';
test.describe('audiobook scope selection', () => {
test('uses only unclaimed scope when auth is disabled', () => {
const result = buildAllowedAudiobookUserIds(false, null, 'unclaimed::ns');
expect(result.preferredUserId).toBe('unclaimed::ns');
expect(result.allowedUserIds).toEqual(['unclaimed::ns']);
});
test('includes both preferred and unclaimed scopes when auth is enabled', () => {
const result = buildAllowedAudiobookUserIds(true, 'user-123', 'unclaimed::ns');
expect(result.preferredUserId).toBe('user-123');
expect(result.allowedUserIds).toEqual(['user-123', 'unclaimed::ns']);
});
test('deduplicates preferred/unclaimed ids when they are the same', () => {
const result = buildAllowedAudiobookUserIds(true, 'unclaimed::ns', 'unclaimed::ns');
expect(result.allowedUserIds).toEqual(['unclaimed::ns']);
});
test('prefers unclaimed owner when both scopes exist', () => {
const owner = pickAudiobookOwner(['user-123', 'unclaimed::ns'], 'user-123', 'unclaimed::ns');
expect(owner).toBe('unclaimed::ns');
});
test('falls back to preferred owner when unclaimed is missing', () => {
const owner = pickAudiobookOwner(['user-123'], 'user-123', 'unclaimed::ns');
expect(owner).toBe('user-123');
});
test('returns null when no matching owners exist', () => {
const owner = pickAudiobookOwner([], 'user-123', 'unclaimed::ns');
expect(owner).toBeNull();
});
});