|
|
@@ -0,0 +1,88 @@
|
|
|
+package repository_test
|
|
|
+
|
|
|
+import (
|
|
|
+ . "github.com/onsi/ginkgo"
|
|
|
+ . "github.com/onsi/gomega"
|
|
|
+
|
|
|
+ "github.com/felamaslen/gmus-backend/pkg/database"
|
|
|
+ "github.com/felamaslen/gmus-backend/pkg/repository"
|
|
|
+ "github.com/felamaslen/gmus-backend/pkg/testing"
|
|
|
+)
|
|
|
+
|
|
|
+var _ = Describe("Player repository", func() {
|
|
|
+ db := database.GetConnection()
|
|
|
+
|
|
|
+ var ids []int64
|
|
|
+
|
|
|
+ BeforeEach(func() {
|
|
|
+ testing.PrepareDatabaseForTesting()
|
|
|
+
|
|
|
+ rows, err := db.Queryx(
|
|
|
+ `
|
|
|
+ insert into songs (
|
|
|
+ track_number
|
|
|
+ ,title
|
|
|
+ ,artist
|
|
|
+ ,album
|
|
|
+ ,duration
|
|
|
+ ,modified_date
|
|
|
+ ,base_path
|
|
|
+ ,relative_path
|
|
|
+ )
|
|
|
+ select * from unnest(
|
|
|
+ array[1, 1, 2, 4]
|
|
|
+ ,array['T1', 'T2', 'T3', 'T4']
|
|
|
+ ,array['AR1', 'AR2', 'AR1', 'AR1']
|
|
|
+ ,array['AL1', 'AL2', 'AL1', 'AL3']
|
|
|
+ ,array[100, 200, 300, 250]
|
|
|
+ ,array[123, 456, 789, 120]
|
|
|
+ ,array['/music', '/music', '/music', '/music']
|
|
|
+ ,array['file1.ogg', 'file2.ogg', 'file3.ogg', 'file4.ogg']
|
|
|
+ )
|
|
|
+ returning id
|
|
|
+ `,
|
|
|
+ )
|
|
|
+ if err != nil {
|
|
|
+ panic(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ var id int64
|
|
|
+ ids = []int64{}
|
|
|
+
|
|
|
+ for rows.Next() {
|
|
|
+ rows.Scan(&id)
|
|
|
+ ids = append(ids, id)
|
|
|
+ }
|
|
|
+ rows.Close()
|
|
|
+ })
|
|
|
+
|
|
|
+ Describe("GetNextSongId", func() {
|
|
|
+ Context("when another song exists in the same album", func() {
|
|
|
+ It("should return the correct song ID", func() {
|
|
|
+ id, _ := repository.GetNextSongId(db, ids[0])
|
|
|
+ Expect(id).To(Equal(ids[2]))
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ Context("when another song exists from the same artist", func() {
|
|
|
+ It("should return the correct song ID", func() {
|
|
|
+ id, _ := repository.GetNextSongId(db, ids[2])
|
|
|
+ Expect(id).To(Equal(ids[3]))
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ Context("when another song exists by a different artist", func() {
|
|
|
+ It("should return the correct song ID", func() {
|
|
|
+ id, _ := repository.GetNextSongId(db, ids[3])
|
|
|
+ Expect(id).To(Equal(ids[1]))
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ Context("when no further songs exist", func() {
|
|
|
+ It("should return zero", func() {
|
|
|
+ id, _ := repository.GetNextSongId(db, ids[1])
|
|
|
+ Expect(id).To(Equal(int64(0)))
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+})
|