test: fix the Suspect sources tests CI rejected (#5410)
release / govulncheck (push) Successful in 15s
release / web (push) Successful in 1m23s
release / go (push) Successful in 1m36s
release / integration (push) Successful in 4m36s
release / android (push) Successful in 5m4s
release / Build signed APK (releases and dev) (push) Successful in 5m13s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 1m11s
release / Verify release artifacts (tag releases only) (push) Skipped
release / govulncheck (push) Successful in 15s
release / web (push) Successful in 1m23s
release / go (push) Successful in 1m36s
release / integration (push) Successful in 4m36s
release / android (push) Successful in 5m4s
release / Build signed APK (releases and dev) (push) Successful in 5m13s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 1m11s
release / Verify release artifacts (tag releases only) (push) Skipped
- staticcheck QF1001: the nil-vs-empty check in TestSourceMarkersFor is now an early continue instead of a negated conjunction. - The page test mocks #lib/api/admin.js whole, so suspectSourcesNextOffset was undefined there. Its test moves to admin.suspect-sources.test.ts, beside admin.scan.test.ts, against the real module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -39,7 +39,10 @@ func TestSourceMarkersFor(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
got := sourceMarkersFor("/music/x/" + c.base)
|
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)
|
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 SuspectSourcesPage from './+page.svelte';
|
||||||
import { createSuspectSourcesQuery } from '#lib/api/admin.js';
|
import { createSuspectSourcesQuery } from '#lib/api/admin.js';
|
||||||
import { suspectSourcesNextOffset } from '#lib/api/admin.js';
|
|
||||||
|
|
||||||
const mocked = createSuspectSourcesQuery as ReturnType<typeof vi.fn>;
|
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();
|
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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user