Files
silo-server/internal/literaryworks/service_test.go
e084cdd1d6 Add unified literary works for ebooks and audiobooks (#107)
* docs: add literary works design and plan

* feat(literary): add work link schema

* feat(literary): add work domain primitives

* feat(literary): persist work links

* feat(literary): score work matches

* feat(catalog): include literary work summary on item detail

* feat(literary): expose work detail API

* feat(literary): assemble work detail

* feat(literary): add admin work linking primitives

* feat(catalog): group literary items by work

* feat(literary): auto-link works during book scans

* fix(literary): narrow work match candidates

* fix(literary): address work merge blockers

---------

Co-authored-by: rxwatcher <rxwatcher@users.noreply.github.com>
Co-authored-by: Quick <31828688+Quick104@users.noreply.github.com>
2026-06-16 18:17:08 -04:00

40 lines
1.3 KiB
Go

package literaryworks
import "testing"
func TestFilesToResponseIncludesOriginalFormatAndDuration(t *testing.T) {
files := []WorkFile{
{FileID: 10, FilePath: "/books/Project Hail Mary.epub", Size: 12345},
{FileID: 20, FilePath: "/books/Project Hail Mary.m4b", Size: 98765, DurationSeconds: 58200},
}
resp := filesToResponse(files)
if len(resp) != 2 {
t.Fatalf("len = %d, want 2", len(resp))
}
if resp[0].OriginalName != "Project Hail Mary.epub" || resp[0].Format != "epub" || resp[0].MIMEType == "" {
t.Fatalf("ebook file response = %#v", resp[0])
}
if resp[1].Format != "m4b" || resp[1].DurationSeconds != 58200 {
t.Fatalf("audio file response = %#v", resp[1])
}
}
func TestGeneratedWorkIDUsesTitleAndAuthorNotFormat(t *testing.T) {
ebook := MatchItem{Title: "Project Hail Mary", Type: FormatEbook, Authors: []string{"Andy Weir"}}
audio := MatchItem{Title: " Project Hail Mary ", Type: FormatAudiobook, Authors: []string{"Andy Weir"}}
if generatedWorkID(ebook) != generatedWorkID(audio) {
t.Fatalf("generated IDs differ for same title/author across formats")
}
}
func TestCompactContentIDsTrimsAndDeduplicates(t *testing.T) {
got := compactContentIDs([]string{" ebook-1 ", "", "audio-1", "ebook-1"})
if len(got) != 2 || got[0] != "ebook-1" || got[1] != "audio-1" {
t.Fatalf("compactContentIDs = %#v", got)
}
}