2026-08-01 00:29:31 +01:00
|
|
|
package model_test
|
2025-03-24 19:39:10 +00:00
|
|
|
|
|
|
|
|
import (
|
2026-08-01 00:29:31 +01:00
|
|
|
"arimelody-web/model"
|
2026-07-31 05:14:19 +01:00
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
2025-03-24 19:39:10 +00:00
|
|
|
|
2026-07-31 05:14:19 +01:00
|
|
|
"gotest.tools/v3/assert"
|
|
|
|
|
)
|
2025-03-24 19:39:10 +00:00
|
|
|
|
2026-07-31 05:14:19 +01:00
|
|
|
func Test_Release(t *testing.T) {
|
|
|
|
|
t.Run("prints correct description HTML", func(t *testing.T) {
|
2026-08-01 00:29:31 +01:00
|
|
|
release := model.Release{
|
2026-07-31 05:14:19 +01:00
|
|
|
Description: "this is\na test\n<strong>description!</strong>",
|
|
|
|
|
}
|
2025-03-24 19:39:10 +00:00
|
|
|
|
2026-07-31 05:14:19 +01:00
|
|
|
// descriptions are set by privileged users,
|
|
|
|
|
// so we'll allow HTML injection here
|
|
|
|
|
assert.Equal(
|
|
|
|
|
t,
|
|
|
|
|
string(release.GetDescriptionHTML()),
|
|
|
|
|
"this is<br>a test<br><strong>description!</strong>",
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("prints correct release date", func(t *testing.T) {
|
2026-08-01 00:29:31 +01:00
|
|
|
release := model.Release{
|
2026-07-31 05:14:19 +01:00
|
|
|
ReleaseDate: time.Date(2025, time.July, 26, 16, 0, 0, 0, time.UTC),
|
|
|
|
|
}
|
2025-03-24 19:39:10 +00:00
|
|
|
|
2026-07-31 05:14:19 +01:00
|
|
|
assert.Equal(t, release.TextReleaseDate(), "2025-07-26T16:00")
|
|
|
|
|
assert.Equal(t, release.PrintReleaseDate(), "26 July 2025")
|
|
|
|
|
})
|
2025-03-24 19:39:10 +00:00
|
|
|
|
2026-07-31 05:14:19 +01:00
|
|
|
t.Run("returns correct artwork", func(t *testing.T) {
|
|
|
|
|
artwork := "testartwork.png"
|
2026-08-01 00:29:31 +01:00
|
|
|
release := model.Release{ Artwork: artwork }
|
2026-07-31 05:14:19 +01:00
|
|
|
assert.Equal(t, release.GetArtwork(), artwork)
|
|
|
|
|
})
|
2025-03-24 19:39:10 +00:00
|
|
|
|
2026-07-31 05:14:19 +01:00
|
|
|
t.Run("returns placeholder artwork when empty", func(t *testing.T) {
|
2026-08-01 00:29:31 +01:00
|
|
|
release := model.Release{}
|
|
|
|
|
assert.Equal(t, release.GetArtwork(), model.DEFAULT_RELEASE_ARTWORK_URL)
|
2026-07-31 05:14:19 +01:00
|
|
|
})
|
2025-03-24 19:39:10 +00:00
|
|
|
|
2026-07-31 05:14:19 +01:00
|
|
|
t.Run("singles", func(t *testing.T) {
|
2026-08-01 00:29:31 +01:00
|
|
|
release := model.Release{
|
|
|
|
|
Tracks: []*model.Track{},
|
2025-03-24 19:39:10 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-31 05:14:19 +01:00
|
|
|
t.Run("false when no tracks are present", func(t *testing.T) {
|
|
|
|
|
assert.Equal(t, release.IsSingle(), false)
|
|
|
|
|
})
|
2025-03-24 19:39:10 +00:00
|
|
|
|
2026-08-01 00:29:31 +01:00
|
|
|
release.Tracks = append(release.Tracks, &model.Track{})
|
2026-07-31 05:14:19 +01:00
|
|
|
t.Run("true when one track is present", func(t *testing.T) {
|
|
|
|
|
assert.Equal(t, release.IsSingle(), true)
|
|
|
|
|
})
|
2025-03-24 19:39:10 +00:00
|
|
|
|
2026-08-01 00:29:31 +01:00
|
|
|
release.Tracks = append(release.Tracks, &model.Track{})
|
2026-07-31 05:14:19 +01:00
|
|
|
t.Run("false when >1 tracks are present", func(t *testing.T) {
|
|
|
|
|
assert.Equal(t, release.IsSingle(), false)
|
|
|
|
|
})
|
|
|
|
|
})
|
2025-03-24 19:39:10 +00:00
|
|
|
|
2026-07-31 05:14:19 +01:00
|
|
|
t.Run("released", func(t *testing.T) {
|
2026-08-01 00:29:31 +01:00
|
|
|
release := model.Release {
|
2026-07-31 05:14:19 +01:00
|
|
|
ReleaseDate: time.Now(),
|
2025-03-24 19:39:10 +00:00
|
|
|
}
|
|
|
|
|
|
2026-07-31 05:14:19 +01:00
|
|
|
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"
|
|
|
|
|
|
2026-08-01 00:29:31 +01:00
|
|
|
release := model.Release{}
|
2026-07-31 05:14:19 +01:00
|
|
|
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,
|
2026-08-01 00:29:31 +01:00
|
|
|
&model.Credit{ Artist: &model.Artist{ Name: artist1 }, Primary: true },
|
2026-07-31 05:14:19 +01:00
|
|
|
)
|
|
|
|
|
t.Run("prints ONLY first artist name when release has one credit", func(t *testing.T) {
|
|
|
|
|
assert.Equal(t, release.PrintArtists(false, true), artist1)
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-01 00:29:31 +01:00
|
|
|
release.Credits = append(release.Credits, []*model.Credit{
|
|
|
|
|
{ Artist: &model.Artist{ Name: artist2 }, Primary: true },
|
|
|
|
|
{ Artist: &model.Artist{ Name: artist3 }, Primary: false },
|
|
|
|
|
{ Artist: &model.Artist{ Name: artist4 }, Primary: true },
|
2026-07-31 05:14:19 +01:00
|
|
|
}...)
|
|
|
|
|
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",
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
2026-08-01 00:29:31 +01:00
|
|
|
|
|
|
|
|
t.Run("validating release types", func(t *testing.T) {
|
|
|
|
|
t.Run("single", func(t *testing.T) {
|
|
|
|
|
releaseType, ok := model.ValidReleaseType("single")
|
|
|
|
|
assert.Equal(t, ok, true)
|
|
|
|
|
assert.Equal(t, releaseType, model.Single)
|
|
|
|
|
})
|
|
|
|
|
t.Run("album", func(t *testing.T) {
|
|
|
|
|
releaseType, ok := model.ValidReleaseType("album")
|
|
|
|
|
assert.Equal(t, ok, true)
|
|
|
|
|
assert.Equal(t, releaseType, model.Album)
|
|
|
|
|
})
|
|
|
|
|
t.Run("EP", func(t *testing.T) {
|
|
|
|
|
releaseType, ok := model.ValidReleaseType("EP")
|
|
|
|
|
assert.Equal(t, ok, true)
|
|
|
|
|
assert.Equal(t, releaseType, model.EP)
|
|
|
|
|
})
|
|
|
|
|
t.Run("compilation", func(t *testing.T) {
|
|
|
|
|
releaseType, ok := model.ValidReleaseType("compilation")
|
|
|
|
|
assert.Equal(t, ok, true)
|
|
|
|
|
assert.Equal(t, releaseType, model.Compilation)
|
|
|
|
|
})
|
|
|
|
|
t.Run("upcoming", func(t *testing.T) {
|
|
|
|
|
releaseType, ok := model.ValidReleaseType("upcoming")
|
|
|
|
|
assert.Equal(t, ok, true)
|
|
|
|
|
assert.Equal(t, releaseType, model.Upcoming)
|
|
|
|
|
})
|
|
|
|
|
t.Run("invalid", func(t *testing.T) {
|
|
|
|
|
releaseType, ok := model.ValidReleaseType("invalid")
|
|
|
|
|
assert.Equal(t, ok, false)
|
|
|
|
|
assert.Equal(t, string(releaseType), "")
|
|
|
|
|
})
|
|
|
|
|
})
|
2025-03-24 19:39:10 +00:00
|
|
|
}
|