2020-01-15 00:23:29 +01:00
|
|
|
package persistence
|
2020-01-13 00:55:55 +01:00
|
|
|
|
|
|
|
import (
|
2020-01-19 21:37:41 +01:00
|
|
|
"github.com/astaxie/beego/orm"
|
2020-01-24 01:44:08 +01:00
|
|
|
"github.com/deluan/navidrome/model"
|
2020-01-13 00:55:55 +01:00
|
|
|
. "github.com/onsi/ginkgo"
|
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("AlbumRepository", func() {
|
2020-01-15 04:22:34 +01:00
|
|
|
var repo model.AlbumRepository
|
2020-01-13 00:55:55 +01:00
|
|
|
|
|
|
|
BeforeEach(func() {
|
2020-01-19 21:37:41 +01:00
|
|
|
repo = NewAlbumRepository(orm.NewOrm())
|
2020-01-13 00:55:55 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetAll", func() {
|
|
|
|
It("returns all records", func() {
|
|
|
|
Expect(repo.GetAll()).To(Equal(testAlbums))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("returns all records sorted", func() {
|
2020-01-20 04:36:15 +01:00
|
|
|
Expect(repo.GetAll(model.QueryOptions{Sort: "Name"})).To(Equal(model.Albums{
|
2020-01-15 23:49:09 +01:00
|
|
|
albumAbbeyRoad,
|
|
|
|
albumRadioactivity,
|
|
|
|
albumSgtPeppers,
|
2020-01-13 00:55:55 +01:00
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("returns all records sorted desc", func() {
|
2020-01-20 04:36:15 +01:00
|
|
|
Expect(repo.GetAll(model.QueryOptions{Sort: "Name", Order: "desc"})).To(Equal(model.Albums{
|
2020-01-15 23:49:09 +01:00
|
|
|
albumSgtPeppers,
|
|
|
|
albumRadioactivity,
|
|
|
|
albumAbbeyRoad,
|
2020-01-13 00:55:55 +01:00
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
It("paginates the result", func() {
|
2020-01-20 04:36:15 +01:00
|
|
|
Expect(repo.GetAll(model.QueryOptions{Offset: 1, Max: 1})).To(Equal(model.Albums{
|
2020-01-15 23:49:09 +01:00
|
|
|
albumAbbeyRoad,
|
2020-01-13 00:55:55 +01:00
|
|
|
}))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("GetStarred", func() {
|
|
|
|
It("returns all starred records", func() {
|
2020-01-22 05:01:43 +01:00
|
|
|
Expect(repo.GetStarred("userid", model.QueryOptions{})).To(Equal(model.Albums{
|
2020-01-15 23:49:09 +01:00
|
|
|
albumRadioactivity,
|
2020-01-13 00:55:55 +01:00
|
|
|
}))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
Describe("FindByArtist", func() {
|
|
|
|
It("returns all records from a given ArtistID", func() {
|
2020-01-15 04:22:34 +01:00
|
|
|
Expect(repo.FindByArtist("1")).To(Equal(model.Albums{
|
2020-01-15 23:49:09 +01:00
|
|
|
albumAbbeyRoad,
|
|
|
|
albumSgtPeppers,
|
2020-01-13 00:55:55 +01:00
|
|
|
}))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|