feat: warn on uncertain episode availability
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package playback
|
||||
|
||||
import (
|
||||
"mal/internal/domain"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestFallbackModes(t *testing.T) {
|
||||
@@ -33,3 +35,57 @@ func TestFallbackModes(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEpisodeAvailabilityWarning(t *testing.T) {
|
||||
now := time.Date(2026, time.June, 27, 11, 0, 0, 0, time.UTC)
|
||||
tests := []struct {
|
||||
name string
|
||||
list domain.CanonicalEpisodeList
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "fresh availability does not warn",
|
||||
list: domain.CanonicalEpisodeList{
|
||||
Episodes: []domain.CanonicalEpisode{{Number: 1, HasSub: true}},
|
||||
LastSuccessAt: "2026-06-27T10:00:00Z",
|
||||
NextRefreshAt: "2026-06-27T12:00:00Z",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "stale availability warns",
|
||||
list: domain.CanonicalEpisodeList{
|
||||
Episodes: []domain.CanonicalEpisode{{Number: 1, HasSub: true}},
|
||||
LastSuccessAt: "2026-06-27T09:00:00Z",
|
||||
NextRefreshAt: "2026-06-27T10:00:00Z",
|
||||
},
|
||||
want: episodeAvailabilityUncertainWarning,
|
||||
},
|
||||
{
|
||||
name: "retrying availability warns",
|
||||
list: domain.CanonicalEpisodeList{
|
||||
Episodes: []domain.CanonicalEpisode{{Number: 1, HasSub: true}},
|
||||
NextRefreshAt: "2026-06-27T11:05:00Z",
|
||||
RetryUntilAt: "2026-06-27T11:30:00Z",
|
||||
FailureCount: 1,
|
||||
},
|
||||
want: episodeAvailabilityUncertainWarning,
|
||||
},
|
||||
{
|
||||
name: "failed availability warns",
|
||||
list: domain.CanonicalEpisodeList{
|
||||
Episodes: []domain.CanonicalEpisode{{Number: 1, HasSub: true}},
|
||||
FailureCount: 3,
|
||||
},
|
||||
want: episodeAvailabilityUncertainWarning,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := episodeAvailabilityWarning(tt.list, now)
|
||||
if got != tt.want {
|
||||
t.Fatalf("episodeAvailabilityWarning() = %q, want %q", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user