ci / module boundaries / boundaries (push) Successful in 10s
ci / mobile / mobile (Metro-бандл Android) (push) Successful in 1m30s
ci / api / api (push) Successful in 58s
ci / contract / contract (сгенерированный код совпадает с openapi.yaml) (push) Successful in 1m1s
ci / db / db (push) Failing after 25s
ci / docker / docker (образы собираются — их сервер собирает сам при обновлении) (push) Successful in 1m36s
ci / ts / ts (packages + web) (push) Failing after 6m3s
72 lines
2.8 KiB
Go
72 lines
2.8 KiB
Go
package uploads
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/require"
|
|
"pipu/api/internal/library"
|
|
)
|
|
|
|
func TestReleaseGroupsSeparateAlbumsAndPreserveDiscsAndCompilations(t *testing.T) {
|
|
one := releaseFile("One", 1, 1, 180000)
|
|
two := releaseFile("Two", 1, 2, 180000)
|
|
other := releaseFile("Other", 1, 1, 180000)
|
|
other.Meta.Album = "Another album"
|
|
groups := groupReleaseFiles([]File{one, two, other})
|
|
require.Len(t, groups, 2)
|
|
var album []uuid.UUID
|
|
for _, g := range groups {
|
|
if g.Album == "Album" {
|
|
album = g.Files
|
|
}
|
|
}
|
|
require.ElementsMatch(t, []uuid.UUID{one.ID, two.ID}, album)
|
|
// Album artist, rather than each track artist, keeps compilations together.
|
|
one.Meta.Artist = "Singer one"
|
|
two.Meta.Artist = "Singer two"
|
|
one.Meta.AlbumArtist = "Various Artists"
|
|
two.Meta.AlbumArtist = "Various Artists"
|
|
require.Len(t, groupReleaseFiles([]File{one, two}), 1)
|
|
// Without album artist, folder context still keeps the two discs of a compilation together.
|
|
one.Meta.AlbumArtist = ""
|
|
two.Meta.AlbumArtist = ""
|
|
one.ClientRelPath = nullable(`Collection\Compilation\CD1\01.flac`)
|
|
two.ClientRelPath = nullable("Collection/Compilation/Disc 02/01.flac")
|
|
require.Len(t, groupReleaseFiles([]File{one, two}), 1)
|
|
}
|
|
func TestReleaseGroupsUseFoldersWhenAlbumTagsAreMissing(t *testing.T) {
|
|
one := releaseFile("One", 1, 1, 180000)
|
|
one.Meta.Album = library.UnknownAlbum
|
|
two := releaseFile("Two", 1, 2, 180000)
|
|
two.Meta.Album = ""
|
|
other := releaseFile("Other", 1, 1, 180000)
|
|
other.Meta.Album = library.UnknownAlbum
|
|
one.ClientRelPath = nullable("Artist/First/CD 1/01.flac")
|
|
two.ClientRelPath = nullable("Artist/First/Диск 2/01.flac")
|
|
other.ClientRelPath = nullable("Artist/Second/01.flac")
|
|
require.Len(t, groupReleaseFiles([]File{one, two, other}), 2)
|
|
other.Status = StatusWithdrawn
|
|
require.Len(t, groupReleaseFiles([]File{one, two, other}), 1)
|
|
// Unknown root files stay a single explicitly reviewable group, never invented albums per file.
|
|
one.ClientRelPath = nil
|
|
two.ClientRelPath = nil
|
|
require.Len(t, groupReleaseFiles([]File{one, two}), 1)
|
|
}
|
|
func TestReleaseGroupsRespectEditionIdentifiersAndKnownMissingTags(t *testing.T) {
|
|
one := releaseFile("One", 1, 1, 180000)
|
|
two := releaseFile("Two", 2, 1, 180000)
|
|
a, b := uuid.NewString(), uuid.NewString()
|
|
one.Tags = map[string]string{"musicbrainz_albumid": a}
|
|
groups := groupReleaseFiles([]File{one, two})
|
|
require.Len(t, groups, 1, "missing ID inherits the sole known edition of the same album")
|
|
key := groups[0].Key
|
|
two.Tags = map[string]string{"musicbrainz_albumid": b}
|
|
require.Len(t, groupReleaseFiles([]File{one, two}), 2, "different known editions must remain separate")
|
|
two.Tags = map[string]string{"musicbrainz_albumid": a}
|
|
two.Meta.Album = "Different spelling"
|
|
groups = groupReleaseFiles([]File{two, one})
|
|
require.Len(t, groups, 1)
|
|
require.Equal(t, key, groups[0].Key)
|
|
}
|