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: [], verdict: null, verdict_at: null, searched_at: null }; } 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(); }); });