Orbit Companion phase 2: queue next, switch when this ends, Drive-In; Christmas stops at New Year
The phone can queue a channel (switches when the programme being watched ends) or a Catch Up programme (plays from its start), five at most, shown as Up next and removable. The Guide gains a Drive-In view with tonight's bills, tickets and Watch while one is showing. Orbit Christmas no longer books anything that starts from 1 January, and books nothing out of season. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import java.time.ZoneId
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
/** Orbit Christmas books nothing that starts from 1 January (Paul, 6 November 2026), and other channels plan a week as before. */
|
||||
class ChristmasSeasonTest {
|
||||
private val london = ZoneId.of("Europe/London")
|
||||
private val minute = 60_000L
|
||||
private fun at(month: Int, day: Int, hour: Int, year: Int = 2026) = ZonedDateTime.of(year, month, day, hour, 0, 0, 0, london).toInstant().toEpochMilli()
|
||||
private val newYear = at(1, 1, 0, 2027)
|
||||
private val films = (1..60).map { n -> PoolSeries("f$n", "Film $n", listOf(PoolEpisode("f$n-1", "src-f$n", EpisodeMark(0, 1), "Film $n", 100 * minute))) }
|
||||
|
||||
@Test fun christmasStopsAtNewYearAndOthersPlanAWeek() {
|
||||
assertEquals(newYear, seasonEndMs(CHRISTMAS_NUMBER, at(12, 28, 20), london))
|
||||
assertNull(seasonEndMs(101, at(12, 28, 20), london))
|
||||
val now = at(12, 28, 20)
|
||||
val christmas = topUpPlan(null, ScheduleCursor(), films, now, zone = london, seasonEndMs = seasonEndMs(CHRISTMAS_NUMBER, now, london))!!
|
||||
assertTrue(christmas.entries.isNotEmpty())
|
||||
assertTrue(christmas.entries.all { it.startMs < newYear })
|
||||
assertTrue(christmas.entries.last().endMs > newYear - 3 * 60 * minute) // it still runs up to New Year
|
||||
val other = topUpPlan(null, ScheduleCursor(), films, now, zone = london)!!
|
||||
assertTrue(other.endMs >= now + SCHEDULE_AHEAD_MS)
|
||||
// Topping up after New Year's Eve adds nothing more.
|
||||
val later = at(12, 31, 23)
|
||||
val topped = topUpPlan(christmas, ScheduleCursor(), films, later, zone = london, seasonEndMs = seasonEndMs(CHRISTMAS_NUMBER, later, london))!!
|
||||
assertEquals(christmas.entries.last(), topped.entries.last()) // only older ones dropped, nothing added
|
||||
assertTrue(topUpPlan(christmas, ScheduleCursor(), films, later, zone = london, seasonEndMs = seasonEndMs(CHRISTMAS_NUMBER, later, london))!!.entries.all { it.startMs < newYear })
|
||||
}
|
||||
|
||||
@Test fun outOfSeasonNothingIsBooked() {
|
||||
val now = at(3, 10, 12, 2027)
|
||||
val plan = topUpPlan(null, ScheduleCursor(), films, now, zone = london, seasonEndMs = seasonEndMs(CHRISTMAS_NUMBER, now, london))!!
|
||||
assertTrue(plan.entries.isEmpty())
|
||||
// From November it plans again.
|
||||
val november = at(11, 1, 9, 2027)
|
||||
assertTrue(topUpPlan(plan, ScheduleCursor(), films, november, zone = london, seasonEndMs = seasonEndMs(CHRISTMAS_NUMBER, november, london))!!.entries.isNotEmpty())
|
||||
}
|
||||
}
|
||||
@@ -177,6 +177,20 @@ class PhoneLinkTest {
|
||||
// Catch Up only from what's really in it: these channels have no committed plan, so nothing is offered.
|
||||
assertEquals(0, JSONObject(call("/api/catchup", cookie = cookie).body).getJSONArray("shelves").let { a -> (0 until a.length()).sumOf { a.getJSONObject(it).getJSONArray("entries").length() } })
|
||||
assertEquals(410, call("/api/catchup/watch", "POST", """{"number":101,"startMs":${now - 60 * minute}}""", cookie = cookie).status)
|
||||
// Phase 2: queue a channel for when the programme on now ends; five at most, and removable.
|
||||
OrbitCompanion.queue = emptyList()
|
||||
assertEquals(1, JSONObject(call("/api/queue", "POST", """{"number":101}""", cookie = cookie).body).getJSONArray("queue").length())
|
||||
assertEquals(404, call("/api/queue", "POST", """{"number":999}""", cookie = cookie).status)
|
||||
assertEquals(404, call("/api/queue", "POST", """{"number":101,"startMs":${now - 60 * minute}}""", cookie = cookie).status) // not in Catch Up
|
||||
repeat(4) { call("/api/queue", "POST", """{"number":308}""", cookie = cookie) }
|
||||
assertEquals(409, call("/api/queue", "POST", """{"number":308}""", cookie = cookie).status)
|
||||
assertEquals(4, JSONObject(call("/api/queue/remove", "POST", """{"index":0}""", cookie = cookie).body).getJSONArray("queue").length())
|
||||
assertEquals(4, JSONObject(call("/api/now", cookie = cookie).body).getJSONArray("queue").length())
|
||||
assertEquals(0, JSONObject(call("/api/queue/remove", "POST", """{"index":-1}""", cookie = cookie).body).getJSONArray("queue").length())
|
||||
// No Drive-In on this screen: nothing to show, ticket or watch.
|
||||
assertEquals(0, JSONObject(call("/api/drivein", cookie = cookie).body).getJSONArray("bills").length())
|
||||
assertEquals(404, call("/api/drivein/ticket", "POST", """{"startMs":1}""", cookie = cookie).status)
|
||||
assertEquals(409, call("/api/drivein/watch", "POST", "{}", cookie = cookie).status)
|
||||
// Titles and times only.
|
||||
val everything = call("/api/now", cookie = cookie).body + call("/api/guide", cookie = cookie).body + call("/api/rooms", cookie = cookie).body
|
||||
listOf("token", "api_key", "password", "X-Emby", "MediaBrowser", "s-a1", "a1").forEach { assertFalse(it, everything.contains("\"$it\"", ignoreCase = true)) }
|
||||
@@ -185,4 +199,29 @@ class PhoneLinkTest {
|
||||
assertEquals(409, call("/api/now", cookie = cookie).status)
|
||||
} finally { PhoneLink.screen = null; OrbitCompanion.inject = { } }
|
||||
}
|
||||
|
||||
@Test fun theQueuePlaysWhenTheProgrammeBeingWatchedEnds() {
|
||||
var watching = true; selected = 101; tuned.clear()
|
||||
val screen = CompanionScreen({ companionChannels }, { selected }, { watching }, { 0 }, { n, o -> tuned += n to o; selected = n })
|
||||
OrbitCompanion.queue = emptyList()
|
||||
val start = companionChannels[0].at(now).startMs; val end = companionChannels[0].at(now).endMs
|
||||
assertNotNull(OrbitCompanion.enqueue(screen, 308, null, now))
|
||||
// What 308 will be showing when 101's programme ends.
|
||||
assertEquals(guideTitleParts(companionChannels[1].at(end).media.item.title).first, OrbitCompanion.queue[0].title)
|
||||
var anchor = OrbitCompanion.follow(screen, null, now)
|
||||
assertEquals(101 to start, anchor)
|
||||
anchor = OrbitCompanion.follow(screen, anchor, end - 1_000); assertTrue(tuned.isEmpty())
|
||||
// Changing channel moves the wait to the new programme instead of playing.
|
||||
selected = 308; anchor = OrbitCompanion.follow(screen, anchor, end - 500); assertTrue(tuned.isEmpty())
|
||||
selected = 101; anchor = OrbitCompanion.follow(screen, anchor, end - 400); assertTrue(tuned.isEmpty())
|
||||
// Not watching: it waits.
|
||||
watching = false; anchor = OrbitCompanion.follow(screen, anchor, end + 1_000); assertTrue(tuned.isEmpty())
|
||||
watching = true; anchor = OrbitCompanion.follow(screen, anchor, end + 2_000); assertTrue(tuned.isEmpty())
|
||||
val nextEnd = companionChannels[0].at(end + 2_000).endMs
|
||||
OrbitCompanion.follow(screen, anchor, nextEnd + 1_000)
|
||||
assertEquals(listOf(308 to 0L), tuned); assertTrue(OrbitCompanion.queue.isEmpty())
|
||||
// Five at most.
|
||||
repeat(5) { assertNotNull(OrbitCompanion.enqueue(screen, 101, null, now)) }
|
||||
assertNull(OrbitCompanion.enqueue(screen, 101, null, now)); OrbitCompanion.queue = emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user