release / go (push) Successful in 2m7s
release / web (push) Successful in 1m25s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 4m30s
release / android (push) Successful in 4m39s
release / Build signed APK (push) Successful in 5m10s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
- Module path: github.com/Fabled-Sword/minstrel, in go.mod, every import and the Dockerfile's version ldflags. - buildinfo.ProjectURL, the contact outside services see in Minstrel's User-Agent: https://github.com/Fabled-Sword/minstrel. - README's compose example pulls ghcr.io/fabled-sword/minstrel:latest. - docs/security.md sends problem reports to the GitHub issues. - The demo-library stack builds Minstrel from the checkout, since :dev is not published to GHCR. - hygiene.go's same-site example uses example.com names. The workbench CI (.gitea/, ci/, export-ignored) still builds and publishes :dev to the private registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
97 lines
3.2 KiB
Go
97 lines
3.2 KiB
Go
package library
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"io"
|
|
"log/slog"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
|
|
"github.com/Fabled-Sword/minstrel/internal/dbtest"
|
|
"github.com/Fabled-Sword/minstrel/internal/notifications"
|
|
)
|
|
|
|
// newMusicNotices returns user's unread new_music notices' payloads.
|
|
func newMusicNotices(t *testing.T, q *dbq.Queries, user dbq.User) []notifications.Payload {
|
|
t.Helper()
|
|
rows, err := q.ListNotifications(context.Background(), dbq.ListNotificationsParams{UserID: user.ID, PageLimit: 50})
|
|
if err != nil {
|
|
t.Fatalf("list notifications: %v", err)
|
|
}
|
|
var out []notifications.Payload
|
|
for _, r := range rows {
|
|
if r.ReadAt.Valid || r.Kind != string(notifications.KindNewMusic) {
|
|
continue
|
|
}
|
|
var p notifications.Payload
|
|
if err := json.Unmarshal(r.Payload, &p); err != nil {
|
|
t.Fatalf("payload: %v", err)
|
|
}
|
|
out = append(out, p)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// Every user hears about an album new to the library, once. The first import
|
|
// into an empty library is the library being set up, and an album that only
|
|
// formed because tracks already held were retagged into it is not new music.
|
|
func TestAnnounceNewAlbums_TellsEveryoneOfEachNewAlbumOnce(t *testing.T) {
|
|
pool := dbtest.Pool(t)
|
|
admin := notifyingAdmin(t, pool)
|
|
ctx := context.Background()
|
|
q := dbq.New(pool)
|
|
listener, err := q.CreateUser(ctx, dbq.CreateUserParams{
|
|
Username: dbtest.TestUserPrefix + "listener", PasswordHash: "x", ApiTokenHash: "listener",
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s := New(pool, slog.New(slog.NewTextHandler(io.Discard, nil)), nil, nil)
|
|
dir := t.TempDir()
|
|
|
|
// First import: claimed, not announced.
|
|
held, _, artist := seedTrack(t, pool, filepath.Join(dir, "a.mp3"))
|
|
s.announceNewAlbums(ctx)
|
|
if got := newMusicNotices(t, q, admin); len(got) != 0 {
|
|
t.Fatalf("the first import was announced: %+v", got)
|
|
}
|
|
|
|
// A new album with its own new track.
|
|
arrived, err := q.UpsertAlbum(ctx, dbq.UpsertAlbumParams{Title: "Geomantic", SortTitle: "Geomantic", ArtistID: artist.ID})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := q.UpsertTrack(ctx, dbq.UpsertTrackParams{
|
|
Title: "Music Is Maps", AlbumID: arrived.ID, ArtistID: artist.ID,
|
|
DurationMs: 1000, FilePath: filepath.Join(dir, "b.mp3"), FileSize: 100, FileFormat: "mp3",
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// And an album formed by retagging a track the library already held.
|
|
retagged, err := q.UpsertAlbum(ctx, dbq.UpsertAlbumParams{Title: "Retitled", SortTitle: "Retitled", ArtistID: artist.ID})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := pool.Exec(ctx, `UPDATE tracks SET album_id = $2 WHERE id = $1`, held.ID, retagged.ID); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
s.announceNewAlbums(ctx)
|
|
for _, u := range []dbq.User{admin, listener} {
|
|
got := newMusicNotices(t, q, u)
|
|
if len(got) != 1 || got[0].Count != 1 || len(got[0].Albums) != 1 ||
|
|
got[0].Albums[0].Title != "Geomantic" || got[0].Albums[0].AlbumID != arrived.ID.String() ||
|
|
got[0].Albums[0].Artist != "Delete Test Artist" {
|
|
t.Fatalf("%s's notices = %+v, want one naming Geomantic alone", u.Username, got)
|
|
}
|
|
}
|
|
|
|
// Nothing new since: nothing more to say.
|
|
s.announceNewAlbums(ctx)
|
|
if got := newMusicNotices(t, q, listener); len(got) != 1 {
|
|
t.Fatalf("an announced album was announced again: %+v", got)
|
|
}
|
|
}
|