2020-01-14 14:23:29 -09:00
|
|
|
package persistence
|
2020-01-12 14:55:55 -09:00
|
|
|
|
|
|
|
|
import (
|
2020-01-28 04:22:17 -09:00
|
|
|
"context"
|
|
|
|
|
|
2022-07-30 08:43:48 -08:00
|
|
|
"github.com/beego/beego/v2/client/orm"
|
2020-01-31 05:53:19 -09:00
|
|
|
"github.com/navidrome/navidrome/log"
|
2020-01-23 15:44:08 -09:00
|
|
|
"github.com/navidrome/navidrome/model"
|
2020-05-13 12:49:55 -08:00
|
|
|
"github.com/navidrome/navidrome/model/request"
|
2022-07-26 12:47:16 -08:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2020-01-12 14:55:55 -09:00
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var _ = Describe("AlbumRepository", func() {
|
2020-01-14 18:22:34 -09:00
|
|
|
var repo model.AlbumRepository
|
2020-01-12 14:55:55 -09:00
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
2020-05-13 12:49:55 -08:00
|
|
|
ctx := request.WithUser(log.NewContext(context.TODO()), model.User{ID: "userid", UserName: "johndoe"})
|
2020-01-28 04:22:17 -09:00
|
|
|
repo = NewAlbumRepository(ctx, orm.NewOrm())
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Describe("Get", func() {
|
|
|
|
|
It("returns an existent album", func() {
|
2020-04-19 18:40:24 -08:00
|
|
|
Expect(repo.Get("103")).To(Equal(&albumRadioactivity))
|
2020-01-28 04:22:17 -09:00
|
|
|
})
|
|
|
|
|
It("returns ErrNotFound when the album does not exist", func() {
|
|
|
|
|
_, err := repo.Get("666")
|
|
|
|
|
Expect(err).To(MatchError(model.ErrNotFound))
|
|
|
|
|
})
|
2020-01-12 14:55:55 -09:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Describe("GetAll", func() {
|
|
|
|
|
It("returns all records", func() {
|
|
|
|
|
Expect(repo.GetAll()).To(Equal(testAlbums))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
It("returns all records sorted", func() {
|
2020-01-28 04:22:17 -09:00
|
|
|
Expect(repo.GetAll(model.QueryOptions{Sort: "name"})).To(Equal(model.Albums{
|
2020-01-15 13:49:09 -09:00
|
|
|
albumAbbeyRoad,
|
|
|
|
|
albumRadioactivity,
|
|
|
|
|
albumSgtPeppers,
|
2020-01-12 14:55:55 -09:00
|
|
|
}))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
It("returns all records sorted desc", func() {
|
2020-01-28 04:22:17 -09:00
|
|
|
Expect(repo.GetAll(model.QueryOptions{Sort: "name", Order: "desc"})).To(Equal(model.Albums{
|
2020-01-15 13:49:09 -09:00
|
|
|
albumSgtPeppers,
|
|
|
|
|
albumRadioactivity,
|
|
|
|
|
albumAbbeyRoad,
|
2020-01-12 14:55:55 -09:00
|
|
|
}))
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
It("paginates the result", func() {
|
2020-01-19 18:36:15 -09:00
|
|
|
Expect(repo.GetAll(model.QueryOptions{Offset: 1, Max: 1})).To(Equal(model.Albums{
|
2020-01-15 13:49:09 -09:00
|
|
|
albumAbbeyRoad,
|
2020-01-12 14:55:55 -09:00
|
|
|
}))
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|