🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Add tests to `core.Share`
Deluan6c1ba8f0d00c
diff --git a/core/share.go b/core/share.goindex b16a57d14..68ee47db5 100644--- a/core/share.go+++ b/core/share.go@@ -41,17 +41,14 @@ type shareRepositoryWrapper struct {func (r *shareRepositoryWrapper) Save(entity interface{}) (string, error) {s := entity.(*model.Share)id, err := gonanoid.Generate("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 9)- s.Name = idif err != nil {return "", err}+ s.Name = idid, err = r.Persistable.Save(s)return id, err}func (r *shareRepositoryWrapper) Update(entity interface{}, _ ...string) error {- s := entity.(*model.Share)- cols := []string{"description"}- err := r.Persistable.Update(s, cols...)- return err+ return r.Persistable.Update(entity, "description")}diff --git a/core/share_test.go b/core/share_test.gonew file mode 100644index 000000000..4c829fb02--- /dev/null+++ b/core/share_test.go@@ -0,0 +1,51 @@+package core++import (+ "context"++ "github.com/deluan/rest"+ "github.com/navidrome/navidrome/model"+ "github.com/navidrome/navidrome/tests"+ . "github.com/onsi/ginkgo"+ . "github.com/onsi/gomega"+)++var _ = Describe("Share", func() {+ var ds model.DataStore+ var share Share+ var mockedRepo rest.Persistable++ BeforeEach(func() {+ ds = &tests.MockDataStore{}+ mockedRepo = ds.Share(context.Background()).(rest.Persistable)+ share = NewShare(ds)+ })++ Describe("NewRepository", func() {+ var repo rest.Persistable++ BeforeEach(func() {+ repo = share.NewRepository(context.Background()).(rest.Persistable)+ })++ Describe("Save", func() {+ It("it adds a random name", func() {+ entity := &model.Share{Description: "test"}+ id, err := repo.Save(entity)+ Expect(err).ToNot(HaveOccurred())+ Expect(id).ToNot(BeEmpty())+ Expect(entity.Name).ToNot(BeEmpty())+ })+ })++ Describe("Update", func() {+ It("filters out read-only fields", func() {+ entity := "entity"+ err := repo.Update(entity)+ Expect(err).ToNot(HaveOccurred())+ Expect(mockedRepo.(*tests.MockShareRepo).Entity).To(Equal("entity"))+ Expect(mockedRepo.(*tests.MockShareRepo).Cols).To(ConsistOf("description"))+ })+ })+ })+})