Files
minstrel/internal/notifications/render_test.go
T
bvandeusenandClaude Opus 5.5 561c1d5eae
release / web (push) Failing after 1m29s
release / go (push) Successful in 1m55s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m22s
release / android (push) Successful in 4m57s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 4m23s
feat: new-music notices come from the scanner; request notices and the original specs go
Request notifications (approved, declined, completed, pending) are removed
along with the request flow that produced them. A new_music kind takes the
"new music arrived" slot: when a scan or a watcher batch finishes, the
scanner claims every album not yet announced (albums.announced_at) and tells
every user about the ones that are new: an album with a track on disk and
no track older than itself. The first import into an empty library, and an
album formed only by retagging tracks already held, announce nothing. One
notice per scan, carrying up to 50 albums and the total; it is never
coalesced, so a notice already emailed can't quietly absorb later arrivals.
It feeds the daily summary email, grouped by artist. Defaults: inbox and
email on, phone off.

Migration 0103 deletes request-kind notification rows and prefs, swaps the
kind CHECKs to new_music, and adds albums.announced_at with every album
held marked announced, so the first scan after it announces nothing old.

Web and Android: labels, the Android "Requests" settings section becomes
"New music", the shade channel your_requests becomes new_music (the old one
is deleted at startup), and "/" opens Home in the app. TrackLabel moves to
the notifications package. docs/smart-music-{server,client}-spec.md are
deleted per the operator; an Android comment loses the word "exchanges".

Grimoire #7666, #7671.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 23:29:13 -05:00

96 lines
4.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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: "Moe Shop", Title: "WWW", AlbumID: "al-1"}}})
require.Equal(t, "New album", one.Title)
require.Equal(t, "Moe Shop – WWW 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 WWW.", render(KindQuarantineFlagged, Payload{Name: "WWW", Actor: "Ann"}).Body)
require.Equal(t, "Ann flagged WWW: bad rip", render(KindQuarantineFlagged, Payload{Name: "WWW", 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: Weezer – Buddy Holly.",
render(KindTracksMissing, Payload{Count: 1, Items: []string{"Weezer – Buddy Holly"}}).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: Weezer – Buddy Holly (alice).",
render(KindPlaybackErrors, Payload{Count: 1, Items: []string{"Weezer – Buddy Holly (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": "WWW", "count": float64(2)}, Payload{Name: "WWW", Count: 2}.Map())
}