Admin: Suspect sources report (#5410) #153

Merged
bvandeusen merged 2 commits from dev into main 2026-10-08 16:03:54 -04:00
3 changed files with 47 additions and 13 deletions
Showing only changes of commit 2205b2927b - Show all commits
+4 -1
View File
@@ -39,7 +39,10 @@ func TestSourceMarkersFor(t *testing.T) {
}
for _, c := range cases {
got := sourceMarkersFor("/music/x/" + c.base)
if !slices.Equal(got, c.want) && !(len(got) == 0 && len(c.want) == 0) {
if len(got) == 0 && len(c.want) == 0 {
continue // nil and empty both mean "no markers"
}
if !slices.Equal(got, c.want) {
t.Errorf("%s:\n got %v\n want %v", c.base, got, c.want)
}
}
@@ -0,0 +1,43 @@
import { describe, expect, test } from 'vitest';
import { suspectSourcesNextOffset } from './admin';
import type { AdminSuspectResponse, AdminSuspectTrack } from './types';
function track(id: string): AdminSuspectTrack {
return {
track_id: id,
title: id,
artist_id: 'ar',
artist_name: 'Artist',
album_id: 'al',
album_title: 'Album',
file_path: `/music/${id}.mp3`,
duration_sec: 180,
disc_number: null,
track_number: null,
markers: []
};
}
function page(offset: number, total: number): AdminSuspectResponse {
return {
total,
limit: 50,
offset,
groups: [
{ directory: 'a', tracks: [track('1'), track('2')] },
{ directory: 'b', tracks: [track('3')] }
]
};
}
// limit and total are in tracks, so the next offset must count tracks across
// groups, not the number of groups.
describe('suspectSourcesNextOffset', () => {
test('counts tracks, not groups', () => {
expect(suspectSourcesNextOffset(page(0, 10))).toBe(3);
});
test('stops at the total', () => {
expect(suspectSourcesNextOffset(page(7, 10))).toBeUndefined();
});
});
@@ -9,7 +9,6 @@ vi.mock('#lib/api/admin.js', () => ({
import SuspectSourcesPage from './+page.svelte';
import { createSuspectSourcesQuery } from '#lib/api/admin.js';
import { suspectSourcesNextOffset } from '#lib/api/admin.js';
const mocked = createSuspectSourcesQuery as ReturnType<typeof vi.fn>;
@@ -112,14 +111,3 @@ describe('Suspect sources page', () => {
expect(screen.queryByRole('button', { name: /more/i })).not.toBeInTheDocument();
});
});
describe('suspectSourcesNextOffset', () => {
test('counts tracks, not groups, and stops at the total', () => {
const groups = [
{ directory: 'a', tracks: [track('1', '1.mp3', []), track('2', '2.mp3', [])] },
{ directory: 'b', tracks: [track('3', '3.mp3', [])] }
];
expect(suspectSourcesNextOffset(page(0, 10, groups))).toBe(3);
expect(suspectSourcesNextOffset(page(7, 10, groups))).toBeUndefined();
});
});