38 lines
1.3 KiB
Swift
38 lines
1.3 KiB
Swift
import Domain
|
|
import Store
|
|
import Testing
|
|
|
|
@Test func searchRanksExactArtistFirstAndFindsTheirSongs() async {
|
|
let source = SourceID()
|
|
func id(_ remote: String) -> EntityID {
|
|
EntityID(source: source, remote: remote)
|
|
}
|
|
func track(_ remote: String, _ title: String, by artist: String, _ artistID: EntityID?) -> Change {
|
|
.upsert(.track(Track(
|
|
id: id(remote),
|
|
title: title,
|
|
albumID: nil,
|
|
albumTitle: "",
|
|
artistID: artistID,
|
|
artistName: artist,
|
|
duration: 1
|
|
)))
|
|
}
|
|
let library = MemoryLibrary()
|
|
await library.apply([
|
|
.upsert(.artist(Artist(id: id("ar-1"), name: "Kai Angel"))),
|
|
.upsert(.artist(Artist(id: id("ar-2"), name: "Angel Olsen"))),
|
|
.upsert(.album(Album(id: id("al-1"), title: "Shh...", artistID: id("ar-1"), artistName: "Kai Angel"))),
|
|
track("t-1", "andy warhol", by: "Kai Angel", id("ar-1")),
|
|
track("t-2", "Fallen Angel", by: "Other", nil),
|
|
])
|
|
|
|
let exact = await library.search("kai angel")
|
|
#expect(exact.top.map(\.id) == [id("ar-1"), id("t-1"), id("al-1")])
|
|
#expect(exact.tracks.map(\.id) == [id("t-1")])
|
|
|
|
let broad = await library.search("angel")
|
|
#expect(broad.artists.map(\.id) == [id("ar-2"), id("ar-1")])
|
|
#expect(broad.tracks.map(\.id) == [id("t-2"), id("t-1")])
|
|
}
|