mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
GetBookmarks selected media_file.* without the album cover-stamp projection, so bookmarked songs kept emitting the pre-edit coverArt id after a cover upload/delete. With this fourth copy of the projection appearing, extract it into a shared coverArtUpdatedAtCol helper used by all media_file read paths (list, playlist tracks, single playlist track, bookmarks).
95 lines
3.2 KiB
Go
95 lines
3.2 KiB
Go
package persistence
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/Masterminds/squirrel"
|
|
"github.com/navidrome/navidrome/log"
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/model/request"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("sqlBookmarks", func() {
|
|
var mr model.MediaFileRepository
|
|
|
|
BeforeEach(func() {
|
|
ctx := log.NewContext(context.TODO())
|
|
ctx = request.WithUser(ctx, model.User{ID: "userid"})
|
|
mr = NewMediaFileRepository(ctx, GetDBXBuilder())
|
|
})
|
|
|
|
Describe("Bookmarks", func() {
|
|
It("returns an empty collection if there are no bookmarks", func() {
|
|
Expect(mr.GetBookmarks()).To(BeEmpty())
|
|
})
|
|
|
|
It("saves and overrides bookmarks", func() {
|
|
By("Saving the bookmark")
|
|
Expect(mr.AddBookmark(songAntenna.ID, "this is a comment", 123)).To(BeNil())
|
|
|
|
bms, err := mr.GetBookmarks()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(bms).To(HaveLen(1))
|
|
Expect(bms[0].Item.ID).To(Equal(songAntenna.ID))
|
|
Expect(bms[0].Item.Title).To(Equal(songAntenna.Title))
|
|
Expect(bms[0].Comment).To(Equal("this is a comment"))
|
|
Expect(bms[0].Position).To(Equal(int64(123)))
|
|
created := bms[0].CreatedAt
|
|
updated := bms[0].UpdatedAt
|
|
Expect(created.IsZero()).To(BeFalse())
|
|
Expect(updated).To(BeTemporally(">=", created))
|
|
|
|
By("Overriding the bookmark")
|
|
Expect(mr.AddBookmark(songAntenna.ID, "another comment", 333)).To(BeNil())
|
|
|
|
bms, err = mr.GetBookmarks()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
Expect(bms[0].Item.ID).To(Equal(songAntenna.ID))
|
|
Expect(bms[0].Comment).To(Equal("another comment"))
|
|
Expect(bms[0].Position).To(Equal(int64(333)))
|
|
Expect(bms[0].CreatedAt).To(Equal(created))
|
|
Expect(bms[0].UpdatedAt).To(BeTemporally(">=", updated))
|
|
|
|
By("Saving another bookmark")
|
|
Expect(mr.AddBookmark(songComeTogether.ID, "one more comment", 444)).To(BeNil())
|
|
bms, err = mr.GetBookmarks()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(bms).To(HaveLen(2))
|
|
|
|
By("Delete bookmark")
|
|
Expect(mr.DeleteBookmark(songAntenna.ID)).To(Succeed())
|
|
bms, err = mr.GetBookmarks()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(bms).To(HaveLen(1))
|
|
Expect(bms[0].Item.ID).To(Equal(songComeTogether.ID))
|
|
Expect(bms[0].Item.Title).To(Equal(songComeTogether.Title))
|
|
|
|
Expect(mr.DeleteBookmark(songComeTogether.ID)).To(Succeed())
|
|
Expect(mr.GetBookmarks()).To(BeEmpty())
|
|
})
|
|
|
|
It("exposes the album's cover timestamp on bookmarked songs", func() {
|
|
albumRepo := NewAlbumRepository(request.WithUser(GinkgoT().Context(), model.User{ID: "userid"}), GetDBXBuilder()).(*albumRepository)
|
|
Expect(mr.AddBookmark(songAntenna.ID, "cover test", 1)).To(Succeed())
|
|
DeferCleanup(func() {
|
|
_ = mr.DeleteBookmark(songAntenna.ID)
|
|
// Restore both columns so fixture-equality tests stay untouched
|
|
_, _ = albumRepo.executeSQL(squirrel.Update("album").
|
|
Set("uploaded_image", "").Set("cover_art_updated_at", nil).
|
|
Where(squirrel.Eq{"id": songAntenna.AlbumID}))
|
|
})
|
|
|
|
Expect(albumRepo.UpdateImage(songAntenna.AlbumID, "cover-bm.jpg")).To(Succeed())
|
|
|
|
bms, err := mr.GetBookmarks()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(bms).To(HaveLen(1))
|
|
Expect(bms[0].Item.CoverArtUpdatedAt).ToNot(BeNil())
|
|
})
|
|
})
|
|
})
|