feat: warn on uncertain episode availability

This commit is contained in:
2026-06-27 19:04:13 +02:00
parent 34923212c5
commit b648afa471
8 changed files with 182 additions and 10 deletions

View File

@@ -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)
}
})
}
}