navidrome/persistence/artist_repository_test.go

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

73 lines
1.5 KiB
Go
Raw Normal View History

package persistence
2020-01-12 23:32:06 +01:00
import (
2020-01-31 21:58:17 +01:00
"context"
"github.com/astaxie/beego/orm"
"github.com/deluan/navidrome/log"
2020-01-24 01:44:08 +01:00
"github.com/deluan/navidrome/model"
2020-05-13 22:49:55 +02:00
"github.com/deluan/navidrome/model/request"
2020-01-12 23:32:06 +01:00
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("ArtistRepository", func() {
2020-01-15 04:22:34 +01:00
var repo model.ArtistRepository
2020-01-12 23:32:06 +01:00
BeforeEach(func() {
2020-05-13 22:49:55 +02:00
ctx := log.NewContext(context.TODO())
ctx = request.WithUser(ctx, model.User{ID: "userid"})
2020-01-31 21:58:17 +01:00
repo = NewArtistRepository(ctx, orm.NewOrm())
2020-01-12 23:32:06 +01:00
})
Describe("Count", func() {
It("returns the number of artists in the DB", func() {
Expect(repo.CountAll()).To(Equal(int64(2)))
})
})
2020-03-26 01:33:32 +01:00
Describe("Exists", func() {
It("returns true for an artist that is in the DB", func() {
Expect(repo.Exists("3")).To(BeTrue())
})
It("returns false for an artist that is in the DB", func() {
Expect(repo.Exists("666")).To(BeFalse())
})
})
2020-01-12 23:32:06 +01:00
Describe("Get", func() {
It("saves and retrieves data", func() {
Expect(repo.Get("2")).To(Equal(&artistKraftwerk))
})
2020-01-12 23:32:06 +01:00
})
2020-01-31 21:58:17 +01:00
Describe("GetStarred", func() {
It("returns all starred records", func() {
Expect(repo.GetStarred(model.QueryOptions{})).To(Equal(model.Artists{
artistBeatles,
}))
})
})
Describe("GetIndex", func() {
It("returns the index", func() {
idx, err := repo.GetIndex()
Expect(err).To(BeNil())
Expect(idx).To(Equal(model.ArtistIndexes{
{
ID: "B",
Artists: model.Artists{
artistBeatles,
},
},
{
ID: "K",
Artists: model.Artists{
artistKraftwerk,
},
},
}))
})
2020-01-12 23:32:06 +01:00
})
})