|
@@ -147,4 +147,35 @@ var _ = Describe("Player repository", func() {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ Describe("GetShuffledSong", func() {
|
|
|
|
|
+ It("should return a random song", func() {
|
|
|
|
|
+ result, _ := repository.GetShuffledSong(db, &ids[0])
|
|
|
|
|
+ Expect(result).NotTo(BeNil())
|
|
|
|
|
+ Expect(result.Id).To(BeElementOf(ids))
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ It("should not return the given song", func() {
|
|
|
|
|
+ // Iterate 10 times to be quite confident - it's not a mathematical proof
|
|
|
|
|
+ // but it doesn't need to be
|
|
|
|
|
+ for i := 0; i < 10; i++ {
|
|
|
|
|
+ result0, _ := repository.GetShuffledSong(db, &ids[0])
|
|
|
|
|
+ result4, _ := repository.GetShuffledSong(db, &ids[4])
|
|
|
|
|
+
|
|
|
|
|
+ Expect(result0).NotTo(BeNil())
|
|
|
|
|
+ Expect(result4).NotTo(BeNil())
|
|
|
|
|
+
|
|
|
|
|
+ Expect(result0.Id).NotTo(Equal(ids[0]))
|
|
|
|
|
+ Expect(result4.Id).NotTo(Equal(ids[4]))
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ Context("when no currentSongId is given", func() {
|
|
|
|
|
+ It("should return a random song", func() {
|
|
|
|
|
+ result, _ := repository.GetShuffledSong(db, nil)
|
|
|
|
|
+ Expect(result).NotTo(BeNil())
|
|
|
|
|
+ Expect(result.Id).To(BeElementOf(ids))
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|