feat: matchedAlbum on item detail, onLoan collection filter
This commit is contained in:
@@ -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()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user