Now Playing backend implemented
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func CreateMockNowPlayingRepo() *MockNowPlaying {
|
||||
return &MockNowPlaying{data: make(map[string]time.Time)}
|
||||
return &MockNowPlaying{}
|
||||
}
|
||||
|
||||
type MockNowPlaying struct {
|
||||
@@ -20,7 +20,7 @@ func (m *MockNowPlaying) SetError(err bool) {
|
||||
m.err = err
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) Add(id string) error {
|
||||
func (m *MockNowPlaying) Set(id string) error {
|
||||
if m.err {
|
||||
return errors.New("Error!")
|
||||
}
|
||||
@@ -28,3 +28,7 @@ func (m *MockNowPlaying) Add(id string) error {
|
||||
m.start = time.Now()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockNowPlaying) Current() (string, time.Time) {
|
||||
return m.id, m.start
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ type NowPlayingInfo struct {
|
||||
}
|
||||
|
||||
type NowPlayingRepository interface {
|
||||
Add(trackId string) error
|
||||
Set(trackId string) error
|
||||
}
|
||||
|
||||
+10
-1
@@ -41,5 +41,14 @@ func (s *scrobbler) Register(id string, playDate time.Time) (*domain.MediaFile,
|
||||
}
|
||||
|
||||
func (s *scrobbler) NowPlaying(id string) (*domain.MediaFile, error) {
|
||||
return nil, errors.New("Not implemented")
|
||||
mf, err := s.mfRepo.Get(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if mf == nil {
|
||||
return nil, errors.New(fmt.Sprintf(`Id "%s" not found`, id))
|
||||
}
|
||||
|
||||
return mf, s.npRepo.Set(id)
|
||||
}
|
||||
|
||||
@@ -53,6 +53,29 @@ func TestScrobbler(t *testing.T) {
|
||||
})
|
||||
})
|
||||
|
||||
Convey("When I inform the song that is now playing", func() {
|
||||
mf, err := scrobbler.NowPlaying("2")
|
||||
|
||||
Convey("Then I get the song for that id back", func() {
|
||||
So(err, ShouldBeNil)
|
||||
So(mf.Title, ShouldEqual, "Hands Of Time")
|
||||
})
|
||||
|
||||
Convey("And it saves the song as the one current playing", func() {
|
||||
id, start := npRepo.Current()
|
||||
So(id, ShouldEqual, "2")
|
||||
So(start, ShouldHappenBefore, time.Now())
|
||||
})
|
||||
|
||||
Convey("And iTunes is not notified", func() {
|
||||
So(itCtrl.played, ShouldNotContainKey, "2")
|
||||
})
|
||||
})
|
||||
|
||||
Reset(func() {
|
||||
itCtrl.played = make(map[string]time.Time)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user