navidrome/core/share_test.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.2 KiB
Go
Raw Normal View History

2021-06-08 22:32:08 +02:00
package core
import (
"context"
"github.com/deluan/rest"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/tests"
2022-07-26 22:47:16 +02:00
. "github.com/onsi/ginkgo/v2"
2021-06-08 22:32:08 +02:00
. "github.com/onsi/gomega"
)
var _ = Describe("Share", func() {
var ds model.DataStore
var share Share
var mockedRepo rest.Persistable
ctx := context.Background()
2021-06-08 22:32:08 +02:00
BeforeEach(func() {
ds = &tests.MockDataStore{}
mockedRepo = ds.Share(ctx).(rest.Persistable)
2021-06-08 22:32:08 +02:00
share = NewShare(ds)
})
Describe("NewRepository", func() {
var repo rest.Persistable
BeforeEach(func() {
repo = share.NewRepository(ctx).(rest.Persistable)
_ = ds.Album(ctx).Put(&model.Album{ID: "123", Name: "Album"})
2021-06-08 22:32:08 +02:00
})
Describe("Save", func() {
It("it sets a random ID", func() {
entity := &model.Share{Description: "test", ResourceIDs: "123"}
2021-06-08 22:32:08 +02:00
id, err := repo.Save(entity)
Expect(err).ToNot(HaveOccurred())
Expect(id).ToNot(BeEmpty())
2023-01-20 04:52:55 +01:00
Expect(entity.ID).To(Equal(id))
2021-06-08 22:32:08 +02:00
})
})
Describe("Update", func() {
It("filters out read-only fields", func() {
entity := &model.Share{}
err := repo.Update("id", entity)
2021-06-08 22:32:08 +02:00
Expect(err).ToNot(HaveOccurred())
Expect(mockedRepo.(*tests.MockShareRepo).Cols).To(ConsistOf("description"))
2021-06-08 22:32:08 +02:00
})
})
})
})