Register skipped songs!
This commit is contained in:
@@ -27,7 +27,7 @@ func TestScrobbler(t *testing.T) {
|
||||
|
||||
Convey("When I scrobble an existing song", func() {
|
||||
now := time.Now()
|
||||
mf, err := scrobbler.Register("2", now)
|
||||
mf, err := scrobbler.Register(1, "2", now)
|
||||
|
||||
Convey("Then I get the scrobbled song back", func() {
|
||||
So(err, ShouldBeNil)
|
||||
@@ -42,7 +42,7 @@ func TestScrobbler(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("When the ID is not in the DB", func() {
|
||||
_, err := scrobbler.Register("3", time.Now())
|
||||
_, err := scrobbler.Register(1, "3", time.Now())
|
||||
|
||||
Convey("Then I receive an error", func() {
|
||||
So(err, ShouldNotBeNil)
|
||||
@@ -54,7 +54,7 @@ func TestScrobbler(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("When I inform the song that is now playing", func() {
|
||||
mf, err := scrobbler.NowPlaying("2", "deluan", "DSub")
|
||||
mf, err := scrobbler.NowPlaying(1, "2", "deluan", "DSub")
|
||||
|
||||
Convey("Then I get the song for that id back", func() {
|
||||
So(err, ShouldBeNil)
|
||||
@@ -79,13 +79,38 @@ func TestScrobbler(t *testing.T) {
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Convey("Given a DB with two songs", t, func() {
|
||||
mfRepo.SetData(`[{"Id":"1","Title":"Femme Fatale"},{"Id":"2","Title":"Here She Comes Now"}]`, 2)
|
||||
Convey("When I play one song", func() {
|
||||
scrobbler.NowPlaying(1, "1", "deluan", "DSub")
|
||||
Convey("And I start playing the other song without scrobbling the first one", func() {
|
||||
skip, err := scrobbler.DetectSkipped(1, "2", false)
|
||||
Convey("Then the first song should be marked as skipped", func() {
|
||||
So(skip, ShouldBeTrue)
|
||||
So(itCtrl.skipped, ShouldContainKey, "1")
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
})
|
||||
Convey("And I scrobble it before starting to play the other song", func() {
|
||||
skip, err := scrobbler.DetectSkipped(1, "1", true)
|
||||
Convey("Then the first song should NOT marked as skipped", func() {
|
||||
So(skip, ShouldBeFalse)
|
||||
So(itCtrl.skipped, ShouldBeEmpty)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
})
|
||||
Reset(func() {
|
||||
itCtrl.skipped = make(map[string]time.Time)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
type mockItunesControl struct {
|
||||
itunesbridge.ItunesControl
|
||||
played map[string]time.Time
|
||||
error bool
|
||||
played map[string]time.Time
|
||||
skipped map[string]time.Time
|
||||
error bool
|
||||
}
|
||||
|
||||
func (m *mockItunesControl) MarkAsPlayed(id string, playDate time.Time) error {
|
||||
@@ -98,3 +123,14 @@ func (m *mockItunesControl) MarkAsPlayed(id string, playDate time.Time) error {
|
||||
m.played[id] = playDate
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockItunesControl) MarkAsSkipped(id string, skipDate time.Time) error {
|
||||
if m.error {
|
||||
return errors.New("ID not found")
|
||||
}
|
||||
if m.skipped == nil {
|
||||
m.skipped = make(map[string]time.Time)
|
||||
}
|
||||
m.skipped[id] = skipDate
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user