navidrome/tests/mock_scrobble_repo.go
Kendall Garner 4998ac2c59
feat(server): add scrobble history Native API (#5761)
* initial scrobble api

* feat: add scrobble retrieval api

* address feedback (1)

* fix spelling

* be explicit about get

* add primary key field, update index, remove rowid references

* use unix timestamp for input and output

---------

Co-authored-by: Deluan Quintão <deluan@navidrome.org>
2026-07-13 11:32:03 -04:00

46 lines
1.1 KiB
Go

package tests
import (
"context"
"strconv"
"time"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/model/request"
)
type MockScrobbleRepo struct {
RecordedScrobbles []model.Scrobble
ctx context.Context
}
func (m *MockScrobbleRepo) Get(id string) (*model.Scrobble, error) {
for idx := range m.RecordedScrobbles {
if strconv.FormatInt(m.RecordedScrobbles[idx].ID, 10) == id {
return &m.RecordedScrobbles[idx], nil
}
}
return nil, model.ErrNotFound
}
func (m *MockScrobbleRepo) GetAll(options ...model.QueryOptions) (model.Scrobbles, error) {
return m.RecordedScrobbles, nil
}
func (m *MockScrobbleRepo) CountAll(options ...model.QueryOptions) (int64, error) {
return int64(len(m.RecordedScrobbles)), nil
}
func (m *MockScrobbleRepo) RecordScrobble(fileID string, submissionTime time.Time) error {
user, _ := request.UserFrom(m.ctx)
m.RecordedScrobbles = append(m.RecordedScrobbles, model.Scrobble{
MediaFileID: fileID,
UserID: user.ID,
SubmissionTime: submissionTime.Unix(),
})
return nil
}
var _ model.ScrobbleRepository = (*MockScrobbleRepo)(nil)