quintodrome/persistence/album_repository_test.go

68 lines
2 KiB
Go
Raw Normal View History

package persistence
2020-01-12 14:55:55 -09:00
import (
2020-01-14 18:22:34 -09:00
"github.com/cloudsonic/sonic-server/model"
2020-01-12 14:55:55 -09:00
. "github.com/onsi/ginkgo"
. "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() {
repo = NewAlbumRepository()
})
Describe("GetAll", func() {
It("returns all records", func() {
Expect(repo.GetAll()).To(Equal(testAlbums))
})
It("returns all records sorted", func() {
2020-01-14 18:22:34 -09:00
Expect(repo.GetAll(model.QueryOptions{SortBy: "Name"})).To(Equal(model.Albums{
2020-01-12 14:55:55 -09:00
{ID: "2", Name: "Abbey Road", Artist: "The Beatles", ArtistID: "1"},
{ID: "3", Name: "Radioactivity", Artist: "Kraftwerk", ArtistID: "2", Starred: true},
{ID: "1", Name: "Sgt Peppers", Artist: "The Beatles", ArtistID: "1"},
}))
})
It("returns all records sorted desc", func() {
2020-01-14 18:22:34 -09:00
Expect(repo.GetAll(model.QueryOptions{SortBy: "Name", Desc: true})).To(Equal(model.Albums{
2020-01-12 14:55:55 -09:00
{ID: "1", Name: "Sgt Peppers", Artist: "The Beatles", ArtistID: "1"},
{ID: "3", Name: "Radioactivity", Artist: "Kraftwerk", ArtistID: "2", Starred: true},
{ID: "2", Name: "Abbey Road", Artist: "The Beatles", ArtistID: "1"},
}))
})
It("paginates the result", func() {
2020-01-14 18:22:34 -09:00
Expect(repo.GetAll(model.QueryOptions{Offset: 1, Size: 1})).To(Equal(model.Albums{
2020-01-12 14:55:55 -09:00
{ID: "2", Name: "Abbey Road", Artist: "The Beatles", ArtistID: "1"},
}))
})
})
Describe("GetAllIds", func() {
It("returns all records", func() {
Expect(repo.GetAllIds()).To(Equal([]string{"1", "2", "3"}))
})
})
Describe("GetStarred", func() {
It("returns all starred records", func() {
2020-01-14 18:22:34 -09:00
Expect(repo.GetStarred(model.QueryOptions{})).To(Equal(model.Albums{
2020-01-12 14:55:55 -09:00
{ID: "3", Name: "Radioactivity", Artist: "Kraftwerk", ArtistID: "2", Starred: true},
}))
})
})
Describe("FindByArtist", func() {
It("returns all records from a given ArtistID", func() {
2020-01-14 18:22:34 -09:00
Expect(repo.FindByArtist("1")).To(Equal(model.Albums{
2020-01-12 14:55:55 -09:00
{ID: "2", Name: "Abbey Road", Artist: "The Beatles", ArtistID: "1"},
{ID: "1", Name: "Sgt Peppers", Artist: "The Beatles", ArtistID: "1"},
}))
})
})
})