Storm AlbumRepository complete.

This commit is contained in:
Deluan
2020-01-10 17:58:08 -05:00
committed by Deluan Quintão
parent 0ca691b37f
commit c608e917db
10 changed files with 267 additions and 13 deletions
@@ -0,0 +1,77 @@
package storm
import (
"github.com/cloudsonic/sonic-server/domain"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("AlbumRepository", func() {
var repo domain.AlbumRepository
var data domain.Albums
BeforeEach(func() {
Db().Drop(&_Album{})
repo = NewAlbumRepository()
data = domain.Albums{
{ID: "1", Name: "Sgt Peppers", Artist: "The Beatles", ArtistID: "1"},
{ID: "2", Name: "Abbey Road", Artist: "The Beatles", ArtistID: "1"},
{ID: "3", Name: "Radioactivity", Artist: "Kraftwerk", ArtistID: "2", Starred: true},
}
for _, a := range data {
repo.Put(&a)
}
})
Describe("GetAll", func() {
It("returns all records", func() {
Expect(repo.GetAll(domain.QueryOptions{})).To(Equal(data))
})
It("returns all records sorted", func() {
Expect(repo.GetAll(domain.QueryOptions{SortBy: "Name"})).To(Equal(domain.Albums{
{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() {
Expect(repo.GetAll(domain.QueryOptions{SortBy: "Name", Desc: true})).To(Equal(domain.Albums{
{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() {
Expect(repo.GetAll(domain.QueryOptions{Offset: 1, Size: 1})).To(Equal(domain.Albums{
{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() {
Expect(repo.GetStarred(domain.QueryOptions{})).To(Equal(domain.Albums{
{ID: "3", Name: "Radioactivity", Artist: "Kraftwerk", ArtistID: "2", Starred: true},
}))
})
})
Describe("FindByArtist", func() {
It("returns all records from a given ArtistID", func() {
Expect(repo.FindByArtist("1")).To(Equal(domain.Albums{
{ID: "1", Name: "Sgt Peppers", Artist: "The Beatles", ArtistID: "1"},
{ID: "2", Name: "Abbey Road", Artist: "The Beatles", ArtistID: "1"},
}))
})
})
})