openreader/tests/unit/audiobook-scope.vitest.spec.ts
Richard R 5f28be5d58 refactor(env): remove legacy no-auth mode and enforce required auth env vars
Eliminate all code paths, configuration, and documentation related to running
without authentication. Require AUTH_SECRET and BASE_URL at startup, updating
middleware, server logic, and runtime checks to assume auth is always enabled.
Simplify onboarding, settings, and test helpers to reflect mandatory auth.
Update environment examples, Docker and deployment docs, and CI/test configs.
Remove no-auth-specific UI flows, test cases, and feature toggles.
2026-05-31 12:09:37 -06:00

30 lines
1.3 KiB
TypeScript

import { describe, expect, test } from 'vitest';
import { buildAllowedAudiobookUserIds, pickAudiobookOwner } from '../../src/lib/server/audiobooks/user-scope';
describe('audiobook scope selection', () => {
test('includes both preferred and unclaimed scopes', () => {
const result = buildAllowedAudiobookUserIds('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('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();
});
});