0.3.49
This commit is contained in:
@@ -185,6 +185,47 @@ func TestWatchTimeIsAttributedByRecordedIdentityBeforeName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPriorWeekToDateMatchesThePointThisWeekHasReached(t *testing.T) {
|
||||
location := auckland(t)
|
||||
// Wednesday 19 August 2026, mid-evening.
|
||||
now := time.Date(2026, 8, 19, 21, 15, 0, 0, location)
|
||||
from, to := priorWeekToDate(now, location)
|
||||
if got, want := from.Format("2006-01-02 15:04"), "2026-08-10 00:00"; got != want {
|
||||
t.Fatalf("prior week from = %s, want %s", got, want)
|
||||
}
|
||||
if got, want := to.Format("2006-01-02 15:04"), "2026-08-12 21:15"; got != want {
|
||||
t.Fatalf("prior week to = %s, want %s (same weekday and time, a week back)", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeekOverWeek(t *testing.T) {
|
||||
minute := int64(60 * 1000)
|
||||
tests := []struct {
|
||||
name string
|
||||
current, prior int64
|
||||
wantDir string
|
||||
}{
|
||||
{"nothing either week", 0, 0, "none"},
|
||||
{"first watching this week", 90 * minute, 0, "up"},
|
||||
{"stopped watching", 0, 90 * minute, "down"},
|
||||
{"a few minutes more is still steady", 63 * minute, 60 * minute, "steady"},
|
||||
{"well up on last week", 180 * minute, 60 * minute, "up"},
|
||||
{"well down on last week", 20 * minute, 120 * minute, "down"},
|
||||
{"identical", 45 * minute, 45 * minute, "steady"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got := weekOverWeek(test.current, test.prior)
|
||||
if got.Direction != test.wantDir {
|
||||
t.Fatalf("weekOverWeek(%d, %d) = %q, want %q", test.current, test.prior, got.Direction, test.wantDir)
|
||||
}
|
||||
if got.Direction != "none" && got.DeltaMs != test.current-test.prior {
|
||||
t.Fatalf("delta = %d, want %d", got.DeltaMs, test.current-test.prior)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWatchTimeFallsBackToACaseInsensitiveName(t *testing.T) {
|
||||
accounts := []watchTimeAccount{{ID: "emby-1", Username: "Matt"}}
|
||||
totals := []store.WatchTimeTotals{{Username: "matt", WeekMs: 42}}
|
||||
@@ -202,7 +243,7 @@ func TestAnUnmatchedAccountIsAbsentRatherThanZero(t *testing.T) {
|
||||
if _, ok := got["emby-9"]; ok {
|
||||
t.Fatal("an unmatched account was attributed watch time")
|
||||
}
|
||||
if summary := summariseWatchTime(store.WatchTimeTotals{}, false); summary.Matched {
|
||||
if summary := summariseWatchTime(store.WatchTimeTotals{}, false, 0); summary.Matched {
|
||||
t.Fatal("an unmatched summary claimed a match")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user