番組登録を追加(登録時の過去回の選択、一時停止・再開・解除、既知の回の記録)
This commit is contained in:
@@ -11,12 +11,19 @@ import (
|
||||
|
||||
type fakeJobStore struct {
|
||||
jobs map[string]store.Job
|
||||
subscriptions map[string]store.Subscription
|
||||
nextID int64
|
||||
lastEpisode store.Episode
|
||||
enqueueCalls, statusCalls int
|
||||
statusIDs []string
|
||||
listStatuses []string
|
||||
listLimits []int
|
||||
registerCalls int
|
||||
registerEpisodes []store.Episode
|
||||
registerDownload bool
|
||||
registerErr error
|
||||
subscribedCalls int
|
||||
subscribedIDs []string
|
||||
err error
|
||||
}
|
||||
|
||||
@@ -130,3 +137,78 @@ func (f *fakeJobStore) CancelQueued(ctx context.Context, id int64) error {
|
||||
}
|
||||
|
||||
var _ JobStore = (*fakeJobStore)(nil)
|
||||
|
||||
func (f *fakeJobStore) SubscribedSeries(_ context.Context, ids []string) (map[string]bool, error) {
|
||||
f.subscribedCalls++
|
||||
f.subscribedIDs = append([]string(nil), ids...)
|
||||
if f.err != nil {
|
||||
return nil, f.err
|
||||
}
|
||||
result := make(map[string]bool)
|
||||
for _, id := range ids {
|
||||
_, result[id] = f.subscriptions[id]
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (f *fakeJobStore) RegisterSubscription(_ context.Context, seriesID, title string, episodes []store.Episode, download bool) (bool, error) {
|
||||
f.registerCalls++
|
||||
f.registerEpisodes = append([]store.Episode(nil), episodes...)
|
||||
f.registerDownload = download
|
||||
if f.registerErr != nil {
|
||||
return false, f.registerErr
|
||||
}
|
||||
if f.err != nil {
|
||||
return false, f.err
|
||||
}
|
||||
if f.subscriptions == nil {
|
||||
f.subscriptions = make(map[string]store.Subscription)
|
||||
}
|
||||
if _, exists := f.subscriptions[seriesID]; exists {
|
||||
return false, nil
|
||||
}
|
||||
var count int64
|
||||
if download {
|
||||
count = int64(len(episodes))
|
||||
}
|
||||
checked := time.Date(2026, 10, 3, 0, 0, 0, 0, time.UTC)
|
||||
f.subscriptions[seriesID] = store.Subscription{SeriesID: seriesID, SeriesTitle: title,
|
||||
Enabled: true, CreatedAt: checked, LastCheckedAt: &checked, JobCount: count}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (f *fakeJobStore) ListSubscriptions(_ context.Context) ([]store.Subscription, error) {
|
||||
if f.err != nil {
|
||||
return nil, f.err
|
||||
}
|
||||
var result []store.Subscription
|
||||
for _, sub := range f.subscriptions {
|
||||
result = append(result, sub)
|
||||
}
|
||||
sort.Slice(result, func(i, j int) bool { return result[i].SeriesID < result[j].SeriesID })
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (f *fakeJobStore) SetSubscriptionEnabled(_ context.Context, seriesID string, enabled bool) error {
|
||||
if f.err != nil {
|
||||
return f.err
|
||||
}
|
||||
sub, exists := f.subscriptions[seriesID]
|
||||
if !exists {
|
||||
return store.ErrInvalidTransition
|
||||
}
|
||||
sub.Enabled = enabled
|
||||
f.subscriptions[seriesID] = sub
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fakeJobStore) DeleteSubscription(_ context.Context, seriesID string) (bool, error) {
|
||||
if f.err != nil {
|
||||
return false, f.err
|
||||
}
|
||||
if _, exists := f.subscriptions[seriesID]; !exists {
|
||||
return false, nil
|
||||
}
|
||||
delete(f.subscriptions, seriesID)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user