release / web (push) Failing after 1m16s
release / go (push) Successful in 1m48s
release / govulncheck (push) Successful in 20s
release / integration (push) Successful in 4m0s
release / android (push) Successful in 4m34s
release / Build signed APK (push) Successful in 5m9s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped
Test data and example comments named real artists, records and songs, and carried real MusicBrainz ids. One mapping swaps them for invented ones throughout (Fields of Ontario, Plastic Apes, Marlo Davies, ...), keeping what each case tests: sort order, index letter, escaping, title keys, artist-prefix stripping. A test username is no longer the operator's name. The cover-art and Last.fm connection checks still query real releases; they reach live services and need something that exists there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
4.3 KiB
Go
96 lines
4.3 KiB
Go
package notifications
|
||
|
||
import (
|
||
"encoding/json"
|
||
"testing"
|
||
|
||
"github.com/stretchr/testify/require"
|
||
)
|
||
|
||
// render stores p the way Notify does (through Map) and reads it back.
|
||
func render(k Kind, p Payload) Rendered {
|
||
b, err := json.Marshal(p.Map())
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
return Render(k, b)
|
||
}
|
||
|
||
func TestRender_EveryKindHasATitleAndALink(t *testing.T) {
|
||
for _, k := range Kinds() {
|
||
r := Render(k, []byte(`{}`))
|
||
require.NotEmpty(t, r.Title, k)
|
||
require.NotEqual(t, "Notification", r.Title, "%s falls through to the default", k)
|
||
require.NotEmpty(t, r.Link, k)
|
||
}
|
||
}
|
||
|
||
func TestRender_NewMusicOpensWhatArrived(t *testing.T) {
|
||
one := render(KindNewMusic, Payload{Count: 1, Albums: []Arrival{{Artist: "Mochi Shop", Title: "XYZ", AlbumID: "al-1"}}})
|
||
require.Equal(t, "New album", one.Title)
|
||
require.Equal(t, "Mochi Shop – XYZ is in the library.", one.Body)
|
||
require.Equal(t, "/albums/al-1", one.Link)
|
||
|
||
// Several open Home, whose Recently added row starts with them; the
|
||
// count, not only the albums carried, is what "more" counts.
|
||
many := render(KindNewMusic, Payload{Count: 60, Albums: []Arrival{
|
||
{Artist: "A", Title: "1"}, {Artist: "B", Title: "2"}, {Artist: "C", Title: "3"}, {Artist: "D", Title: "4"},
|
||
}})
|
||
require.Equal(t, "60 new albums", many.Title)
|
||
require.Equal(t, "Now in the library: A – 1, B – 2, C – 3 and 57 more.", many.Body)
|
||
require.Equal(t, "/", many.Link)
|
||
}
|
||
|
||
func TestRender_FlagCarriesTheReasonWhenThereIsOne(t *testing.T) {
|
||
require.Equal(t, "Ann flagged XYZ.", render(KindQuarantineFlagged, Payload{Name: "XYZ", Actor: "Ann"}).Body)
|
||
require.Equal(t, "Ann flagged XYZ: bad rip", render(KindQuarantineFlagged, Payload{Name: "XYZ", Actor: "Ann", Reason: "bad rip"}).Body)
|
||
}
|
||
|
||
func TestRender_CoalescedCountsReadNaturally(t *testing.T) {
|
||
require.Equal(t, "1 track went missing", render(KindTracksMissing, Payload{Count: 1}).Title)
|
||
require.Equal(t, "14 tracks went missing", render(KindTracksMissing, Payload{Count: 14}).Title)
|
||
require.Equal(t, "Library scan failed", render(KindScanFailed, Payload{Count: 1, Detail: "x"}).Title)
|
||
require.Equal(t, "Library scan failed 3 times", render(KindScanFailed, Payload{Count: 3}).Title)
|
||
require.Equal(t, "Some tracks went missing", Render(KindTracksMissing, []byte(`{}`)).Title)
|
||
}
|
||
|
||
// A notice says which, not only how many.
|
||
func TestRender_NamesWhatChanged(t *testing.T) {
|
||
require.Equal(t, "No longer on disk: Glasshouse – Lucky Penny.",
|
||
render(KindTracksMissing, Payload{Count: 1, Items: []string{"Glasshouse – Lucky Penny"}}).Body)
|
||
require.Equal(t, "No longer on disk: A – 1 and B – 2.",
|
||
render(KindTracksMissing, Payload{Count: 2, Items: []string{"A – 1", "B – 2"}}).Body)
|
||
// Three are named; the rest of the count, not only the rest of the
|
||
// stored names, is "more".
|
||
require.Equal(t, "Held more than once: A, B, C and 9 more.",
|
||
render(KindDuplicatesFound, Payload{Count: 12, Items: []string{"A", "B", "C", "D", "E"}}).Body)
|
||
require.Equal(t, "12 new duplicates to review", render(KindDuplicatesFound, Payload{Count: 12}).Title)
|
||
require.Equal(t, "Extra copies removed, the right one kept: A and B.",
|
||
render(KindDuplicatesResolved, Payload{Count: 2, Items: []string{"A", "B"}}).Body)
|
||
require.Equal(t, "Failed to play: Glasshouse – Lucky Penny (alice).",
|
||
render(KindPlaybackErrors, Payload{Count: 1, Items: []string{"Glasshouse – Lucky Penny (alice)"}}).Body)
|
||
}
|
||
|
||
func TestRender_RowsFromBeforeItemsReadAsTheyDid(t *testing.T) {
|
||
require.Equal(t, "Their files are no longer where the library expects them.",
|
||
render(KindTracksMissing, Payload{Count: 4}).Body)
|
||
require.Equal(t, "Merged 8 duplicate copies.",
|
||
render(KindDuplicatesResolved, Payload{Count: 716, Detail: "Merged 8 duplicate copies."}).Body)
|
||
}
|
||
|
||
func TestRender_AScanFailureSaysWhatStopped(t *testing.T) {
|
||
r := render(KindScanFailed, Payload{Count: 1, Detail: "scan root \"/music\" unavailable"})
|
||
require.Equal(t, `The last scan stopped: scan root "/music" unavailable`, r.Body)
|
||
require.Equal(t, "/admin/library", r.Link)
|
||
}
|
||
|
||
func TestRender_AnUnreadablePayloadStillRenders(t *testing.T) {
|
||
r := Render(KindQuarantineFlagged, []byte(`not json`))
|
||
require.Equal(t, "Track flagged", r.Title)
|
||
require.Equal(t, "Someone flagged A track.", r.Body)
|
||
}
|
||
|
||
func TestPayloadMap_DropsEmptyFields(t *testing.T) {
|
||
require.Equal(t, map[string]any{"name": "XYZ", "count": float64(2)}, Payload{Name: "XYZ", Count: 2}.Map())
|
||
}
|