quintodrome/persistence/storm/artist_repository_test.go

59 lines
1.3 KiB
Go
Raw Normal View History

2020-01-10 11:08:23 -09:00
package storm
import (
"github.com/cloudsonic/sonic-server/domain"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("ArtistRepository", func() {
var repo domain.ArtistRepository
BeforeEach(func() {
Db().Drop(&_Artist{})
2020-01-10 11:08:23 -09:00
repo = NewArtistRepository()
})
It("saves and retrieves data", func() {
artist := &domain.Artist{
ID: "1",
Name: "Saara Saara",
AlbumCount: 2,
}
Expect(repo.Put(artist)).To(BeNil())
Expect(repo.Get("1")).To(Equal(artist))
})
2020-01-10 13:58:08 -09:00
It("returns ErrNotFound when the ID does not exist", func() {
_, err := repo.Get("999")
Expect(err).To(MatchError(domain.ErrNotFound))
})
Describe("PurgeInactive", func() {
var data domain.Artists
BeforeEach(func() {
data = domain.Artists{
{ID: "1", Name: "Saara Saara"},
{ID: "2", Name: "Kraftwerk"},
{ID: "3", Name: "The Beatles"},
}
for _, a := range data {
repo.Put(&a)
}
})
It("purges inactive records", func() {
active := domain.Artists{{ID: "1"}, {ID: "3"}}
Expect(repo.PurgeInactive(active)).To(Equal([]string{"2"}))
})
It("doesn't delete anything if all is active", func() {
active := domain.Artists{{ID: "1"}, {ID: "2"}, {ID: "3"}}
Expect(repo.PurgeInactive(active)).To(BeEmpty())
})
2020-01-10 11:08:23 -09:00
})
2020-01-10 11:08:23 -09:00
})