package model import ( "strings" "testing" "time" "gotest.tools/v3/assert" ) func Test_Release(t *testing.T) { t.Run("prints correct description HTML", func(t *testing.T) { release := Release{ Description: "this is\na test\ndescription!", } // descriptions are set by privileged users, // so we'll allow HTML injection here assert.Equal( t, string(release.GetDescriptionHTML()), "this is
a test
description!", ) }) t.Run("prints correct release date", func(t *testing.T) { release := Release{ ReleaseDate: time.Date(2025, time.July, 26, 16, 0, 0, 0, time.UTC), } assert.Equal(t, release.TextReleaseDate(), "2025-07-26T16:00") assert.Equal(t, release.PrintReleaseDate(), "26 July 2025") }) t.Run("returns correct artwork", func(t *testing.T) { artwork := "testartwork.png" release := Release{ Artwork: artwork } assert.Equal(t, release.GetArtwork(), artwork) }) t.Run("returns placeholder artwork when empty", func(t *testing.T) { release := Release{} assert.Equal(t, release.GetArtwork(), "/img/default-cover-art.png") }) t.Run("singles", func(t *testing.T) { release := Release{ Tracks: []*Track{}, } t.Run("false when no tracks are present", func(t *testing.T) { assert.Equal(t, release.IsSingle(), false) }) release.Tracks = append(release.Tracks, &Track{}) t.Run("true when one track is present", func(t *testing.T) { assert.Equal(t, release.IsSingle(), true) }) release.Tracks = append(release.Tracks, &Track{}) t.Run("false when >1 tracks are present", func(t *testing.T) { assert.Equal(t, release.IsSingle(), false) }) }) t.Run("released", func(t *testing.T) { release := Release { ReleaseDate: time.Now(), } t.Run("true when release date in the past", func(t *testing.T) { assert.Equal(t, release.IsReleased(), true) }) release.ReleaseDate = time.Now().Add(time.Hour) t.Run("false when release date in the future", func(t *testing.T) { assert.Equal(t, release.IsReleased(), false) }) }) t.Run("printing artists", func(t *testing.T) { artist1 := "ari melody" artist2 := "aridoodle" artist3 := "idk" artist4 := "guest" release := Release{} t.Run("prints \"Unknown Artist\" when release has no credits", func(t *testing.T) { assert.Equal(t, release.PrintArtists(false, true), "Unknown Artist") }) release.Credits = append( release.Credits, &Credit{ Artist: Artist{ Name: artist1 }, Primary: true }, ) t.Run("prints ONLY first artist name when release has one credit", func(t *testing.T) { assert.Equal(t, release.PrintArtists(false, true), artist1) }) release.Credits = append(release.Credits, []*Credit{ { Artist: Artist{ Name: artist2 }, Primary: true }, { Artist: Artist{ Name: artist3 }, Primary: false }, { Artist: Artist{ Name: artist4 }, Primary: true }, }...) t.Run("can get only unique primary artist names", func(t *testing.T) { assert.Equal( t, strings.Join(release.GetUniqueArtistNames(true), " "), strings.Join([]string{ artist1, artist2, artist4 }, " "), ) }) t.Run("can get only unique artist names", func(t *testing.T) { assert.Equal( t, strings.Join(release.GetUniqueArtistNames(false), " "), strings.Join([]string{ artist1, artist2, artist3, artist4 }, " "), ) }) t.Run("can print only primary artists, with ampersands", func(t *testing.T) { assert.Equal( t, release.PrintArtists(true, true), "ari melody, aridoodle & guest", ) }) t.Run("can print only primary artists, without ampersands", func(t *testing.T) { assert.Equal( t, release.PrintArtists(true, false), "ari melody, aridoodle, guest", ) }) t.Run("can print all artists, with ampersands", func(t *testing.T) { assert.Equal( t, release.PrintArtists(false, true), "ari melody, aridoodle, idk & guest", ) }) t.Run("can print all artists, without ampersands", func(t *testing.T) { assert.Equal( t, release.PrintArtists(false, false), "ari melody, aridoodle, idk, guest", ) }) }) }