Fix regia basket e stabilità diretta iOS.

La regia remota non va più in 500 su basket/timed; iOS gestisce chiusura set, riconnessione RTMP e avanzamento quarti in modo affidabile.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Emiliano Frascaro
2026-06-20 12:30:34 +02:00
parent 731b43ea88
commit 270bf680a4
16 changed files with 665 additions and 441 deletions

View File

@@ -0,0 +1,25 @@
import XCTest
@testable import MatchLiveTv
@MainActor
final class LiveScoreDialogHostTests: XCTestCase {
func testResolveTrueCompletesShow() async {
let host = LiveScoreDialogHost()
let task = Task { await host.show(ScoreDialogState(kind: .setWon)) }
try? await Task.sleep(nanoseconds: 50_000_000)
host.resolve(true)
let result = await task.value
XCTAssertTrue(result)
XCTAssertNil(host.pending)
}
func testSecondResolveIsIgnored() async {
let host = LiveScoreDialogHost()
let task = Task { await host.show(ScoreDialogState(kind: .setWon)) }
try? await Task.sleep(nanoseconds: 50_000_000)
host.resolve(true)
host.resolve(false)
let result = await task.value
XCTAssertTrue(result)
}
}

View File

@@ -65,4 +65,38 @@ final class ScoreActionDecodeTests: XCTestCase {
XCTAssertEqual(score.setPartials[0].home, 25)
XCTAssertEqual(score.setPartials[0].away, 18)
}
func testDecodesBasketAdvancePeriodResponse() throws {
let json = """
{
"id": "821ddb81-9dc2-466a-9ad5-2555e78f4653",
"match_id": "e887ce1d-10ee-4680-8323-79bb8f11e0aa",
"status": "live",
"platform": "matchlivetv",
"score": {
"type": "score_update",
"board_type": "basket",
"home_points": 12,
"away_points": 10,
"current_set": 1,
"set_partials": [],
"timeout_home": false,
"timeout_away": false,
"period": "Q2",
"clock_secs": 600,
"clock_running": false,
"data": { "home_score": 12, "away_score": 10, "period": 2, "clock_secs": 600, "clock_running": false, "overtime": false }
},
"set_won": false,
"match_won": false,
"winner": null
}
""".data(using: .utf8)!
let dto = try ApiInstant.decoder.decode(StreamSessionDto.self, from: json)
let score = try XCTUnwrap(dto.score?.toDomain())
XCTAssertEqual(score.periodLabel, "Q2")
XCTAssertEqual(score.period, 2)
XCTAssertEqual(score.clockSecs, 600)
XCTAssertFalse(score.clockRunning)
}
}

View File

@@ -55,4 +55,30 @@ final class ScoreControllerTests: XCTestCase {
controller.applyAction("home_point")
XCTAssertEqual(controller.score.homePoints, 1)
}
func testAdvancePeriodOptimisticUpdatesQuarter() {
let controller = ScoreController(
scoreRepository: ScoreRepository(api: MatchLiveAPI()),
sessionCable: SessionCableService()
)
var initial = ScoreState()
initial.boardType = "basket"
initial.period = 1
initial.periodLabel = "Q1"
controller.bind(sessionId: "session-1", initial: initial)
controller.applyAction("advance_period")
XCTAssertEqual(controller.score.period, 2)
XCTAssertEqual(controller.score.periodLabel, "Q2")
XCTAssertFalse(controller.score.clockRunning)
}
func testProgressKeyChangesWhenPeriodAdvances() {
var q1 = ScoreState(boardType: "basket", period: 1, periodLabel: "Q1", clockSecs: 600)
var q2 = ScoreState(boardType: "basket", period: 2, periodLabel: "Q2", clockSecs: 600)
q1.homePoints = 10
q1.awayPoints = 8
q2.homePoints = 10
q2.awayPoints = 8
XCTAssertGreaterThan(q2.progressKey(), q1.progressKey())
}
}