Files
psysonic/src/utils/serverDisplayName.test.ts
T
Frank Stellmacher 4d564e5016 refactor(auth): E.43 — extract authStore types + defaults + helpers (#608)
First slice of the authStore split. Pure code-move: no behaviour change.

- `authStoreTypes.ts` — `ServerProfile`, `AuthState`, plus all union
  types (`SeekbarStyle`, `LoggingMode`, `NormalizationEngine`,
  `DiscordCoverSource`, `LoudnessLufsPreset`, `LyricsSourceId`,
  `LyricsSourceConfig`, `TrackPreviewLocation`, `TrackPreviewLocations`).
- `authStoreDefaults.ts` — `LOUDNESS_LUFS_PRESETS`,
  `DEFAULT_LOUDNESS_PRE_ANALYSIS_ATTENUATION_DB`,
  `TRACK_PREVIEW_LOCATIONS`, `DEFAULT_TRACK_PREVIEW_LOCATIONS`,
  `DEFAULT_LYRICS_SOURCES`, `MIX_MIN_RATING_FILTER_MAX_STARS`,
  `RANDOM_MIX_SIZE_OPTIONS`.
- `authStoreHelpers.ts` — `generateId`,
  `sanitizeLoudnessLufsPreset`, `sanitizeLoudnessPreAnalysisFromStorage`,
  `clampMixFilterMinStars`, `clampRandomMixSize`,
  `clampSkipStarThreshold`, `skipStarCountStorageKey`,
  `sanitizeSkipStarCounts`.

12 external call sites migrated to direct imports from the new
modules (no re-export shims left in authStore.ts — applies the
[feedback_prevent_god_modules] rule 5: avoid re-export debt).

authStore.ts: 889 → 518 LOC (−371).
2026-05-12 23:22:28 +02:00

37 lines
1.3 KiB
TypeScript

import type { ServerProfile } from '../store/authStoreTypes';
import { describe, expect, it } from 'vitest';
import { serverListDisplayLabel, shortHostFromServerUrl } from './serverDisplayName';
function srv(p: Partial<ServerProfile> & Pick<ServerProfile, 'id'>): ServerProfile {
return {
name: '',
url: 'https://example.com',
username: 'u',
password: 'p',
...p,
};
}
describe('shortHostFromServerUrl', () => {
it('strips https and path', () => {
expect(shortHostFromServerUrl('https://music.one.com/v1')).toBe('music.one.com');
});
it('keeps port', () => {
expect(shortHostFromServerUrl('http://127.0.0.1:4533')).toBe('127.0.0.1:4533');
});
});
describe('serverListDisplayLabel', () => {
it('uses short host when name empty', () => {
const a = srv({ id: '1', url: 'https://a.com', username: 'u', password: 'p', name: '' });
expect(serverListDisplayLabel(a, [a])).toBe('a.com');
});
it('disambiguates duplicate names', () => {
const a = srv({ id: '1', url: 'https://music.one.com', username: 'alice', password: 'p', name: 'Home' });
const b = srv({ id: '2', url: 'https://other.net', username: 'bob', password: 'p', name: 'Home' });
const all = [a, b];
expect(serverListDisplayLabel(a, all)).toBe('alice@music.one.com');
expect(serverListDisplayLabel(b, all)).toBe('bob@other.net');
});
});