ScoreboardCadence.Due(phase, lastAnalytics, lastSubscribers, now) is the creator's rule as a pure function: watch hours ONLY during a live stream, every 30 minutes (Analytics answers in days and test/record sessions have no public audience, so querying then is pure waste); subscribers whenever the app is working, every 60 s; and nothing at all when idle. Deliberately returns 'no poll' rather than 'analytics only' — a poll kind the poller cannot perform is a bug waiting for a caller. Remaining for the scoreboard: the HTTP providers behind this policy (watch hours via Analytics reports.query, subscribers via channels.list) and the timer that calls Due(). Recorded in HANDOFF.
40 lines
1.7 KiB
C#
40 lines
1.7 KiB
C#
using System;
|
|
using Xunit;
|
|
using ytLive.Models;
|
|
|
|
namespace ytLive.Tests;
|
|
|
|
/// <summary>The quiet-by-default rule: watch hours only during a live stream (Analytics is a daily
|
|
/// figure and test/record sessions have no public audience), subscribers whenever the app is
|
|
/// working, and silence when idle.</summary>
|
|
public class ScoreboardCadenceTests
|
|
{
|
|
[Fact]
|
|
public void Analytics_polls_only_when_live_and_subscribers_poll_during_any_session()
|
|
{
|
|
var now = new DateTime(2026, 10, 30, 12, 0, 0, DateTimeKind.Utc);
|
|
var old = now.AddHours(-2);
|
|
|
|
// Idle: silent, even if everything is stale.
|
|
Assert.Equal(ScoreboardPoll.None, ScoreboardCadence.Due(SessionPhase.Idle, old, old, now));
|
|
|
|
// Live with stale figures: both.
|
|
Assert.Equal(ScoreboardPoll.Both, ScoreboardCadence.Due(SessionPhase.Live, old, old, now));
|
|
|
|
// Test / recording: subscribers only — no public audience, so no analytics.
|
|
Assert.Equal(ScoreboardPoll.SubscribersOnly, ScoreboardCadence.Due(SessionPhase.Test, old, old, now));
|
|
Assert.Equal(ScoreboardPoll.SubscribersOnly, ScoreboardCadence.Due(SessionPhase.Recording, old, old, now));
|
|
|
|
// Fresh figures: nothing is due.
|
|
Assert.Equal(ScoreboardPoll.None, ScoreboardCadence.Due(SessionPhase.Live, now, now, now));
|
|
|
|
// Analytics alone never polls (it is not a kind the poller knows).
|
|
Assert.Equal(ScoreboardPoll.None,
|
|
ScoreboardCadence.Due(SessionPhase.Live, old, now.AddSeconds(-10), now));
|
|
|
|
// Subscribers alone mid-window.
|
|
Assert.Equal(ScoreboardPoll.SubscribersOnly,
|
|
ScoreboardCadence.Due(SessionPhase.Live, now, old, now));
|
|
}
|
|
}
|