1
0

feat: matchedAlbum on item detail, onLoan collection filter

This commit is contained in:
2026-09-03 21:25:47 +02:00
parent d63bc4bc12
commit f8f240f00a
4 changed files with 126 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { openDatabase, type DB } from '../src/db.js'
import { resolveRipStatus } from '../src/ripstatus.js'
import { resolveRipStatus, findMatchedAlbum } from '../src/ripstatus.js'
describe('resolveRipStatus', () => {
let db: DB
@@ -56,3 +56,42 @@ describe('resolveRipStatus', () => {
expect(resolveRipStatus(db, 1, itemId)).toBe('ripped')
})
})
describe('findMatchedAlbum', () => {
let db: DB
beforeEach(() => {
db = openDatabase(':memory:')
db.prepare("INSERT INTO users (id, username, password_hash, is_admin) VALUES (1, 'sam', 'x', 1)").run()
db.prepare(
"INSERT INTO collection_items (id, user_id, discogs_release_id, title, artist) VALUES (10, 1, 100, 'Motion', 'The Cinematic Orchestra')"
).run()
})
function addAlbum(id: number, title: string, artist: string) {
db.prepare('INSERT INTO digital_albums (id, user_id, subsonic_id, title, artist) VALUES (?, 1, ?, ?, ?)').run(
id,
`sub-${id}`,
title,
artist
)
}
it('returns the match-linked album', () => {
addAlbum(1, 'Motion (Remastered)', 'The Cinematic Orchestra')
db.prepare('INSERT INTO match_links (user_id, item_id, album_id) VALUES (1, 10, 1)').run()
const m = findMatchedAlbum(db, 1, 10)
expect(m).toMatchObject({ subsonicId: 'sub-1', lastPlayedAt: null })
})
it('falls back to the confident fuzzy match', () => {
addAlbum(2, 'Motion!', 'Cinematic Orchestra')
const m = findMatchedAlbum(db, 1, 10)
expect(m).toMatchObject({ subsonicId: 'sub-2' })
})
it('returns null when nothing matches or the item is missing', () => {
expect(findMatchedAlbum(db, 1, 10)).toBeNull()
expect(findMatchedAlbum(db, 1, 9999)).toBeNull()
})
})