Fix punteggio broadcast iOS: decodifica score e aggiornamento UI.

ScoreStateDto non leggeva home_points con convertFromSnakeCase; ScoreController assegna sempre lo stato, aggiornamento ottimistico e refresh overlay.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Emiliano Frascaro
2026-06-15 07:37:27 +02:00
parent 80813b390b
commit 594853ed04
10 changed files with 364 additions and 286 deletions

View File

@@ -105,7 +105,7 @@ final class MatchScoringRulesTests: XCTestCase {
"data": { "home_score": 42, "away_score": 38, "period": 3, "overtime": false }
}
""".data(using: .utf8)!
let dto = try JSONDecoder().decode(ScoreStateDto.self, from: json)
let dto = try ApiInstant.decoder.decode(ScoreStateDto.self, from: json)
let score = dto.toDomain()
XCTAssertEqual(score.boardType, "basket")
XCTAssertEqual(score.homePoints, 42)

View File

@@ -0,0 +1,36 @@
import XCTest
@testable import MatchLiveTv
final class ScoreActionDecodeTests: XCTestCase {
func testDecodesScoreActionResponse() 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": "volley",
"home_sets": 0,
"away_sets": 0,
"home_points": 1,
"away_points": 0,
"current_set": 1,
"set_partials": [],
"timeout_home": false,
"timeout_away": false,
"period": null,
"data": {}
},
"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.homePoints, 1)
XCTAssertEqual(score.boardType, "volley")
}
}

View File

@@ -0,0 +1,28 @@
import XCTest
@testable import MatchLiveTv
@MainActor
final class ScoreControllerTests: XCTestCase {
func testIncrementHomeUpdatesPublishedScore() {
let controller = ScoreController(
scoreRepository: ScoreRepository(api: MatchLiveAPI()),
sessionCable: SessionCableService()
)
controller.bind(sessionId: "session-1", initial: ScoreState())
controller.incrementHome()
XCTAssertEqual(controller.score.homePoints, 1)
}
func testApplyBoardActionOptimisticThenConfirm() async {
let api = MatchLiveAPI()
let controller = ScoreController(
scoreRepository: ScoreRepository(api: api),
sessionCable: SessionCableService()
)
controller.bind(sessionId: "session-1", initial: ScoreState())
// Senza backend: fallisce e ripristina ma l'ottimistico deve almeno scattare durante la chiamata.
// Verifichiamo solo che applyOptimistic funzioni via applyAction locale.
controller.applyAction("home_point")
XCTAssertEqual(controller.score.homePoints, 1)
}
}