Files
SDKmuta/test/league_service_test.dart
2026-11-28 12:22:02 +01:00

32 lines
1.6 KiB
Dart

import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:sd_kovinar/services/league_service.dart';
// Shape of liga.bl3kunja.top/api/lestvica (trimmed, names made up)
const _json = '''
{"league":{"counted":4,"id":1,"name":"Liga 2026-2027","shots":2,"status":"active","targets":20},
"players":[
{"cells":[{"counted":true,"joker":false,"score":340,"tens":5},null,null,null,null],"club":"SD Kovinar Muta","final":340,"name":"B","played":1,"rank":2,"tens":5,"total":340},
{"cells":[{"counted":true,"joker":false,"score":364,"tens":13},null,null,null,null],"club":"SD Kamnik","final":364,"name":"A","played":1,"rank":1,"tens":13,"total":364}],
"rounds":[
{"ends_at":"2026-12-31T23:59","number":2,"starts_at":"2026-12-01T00:00","state":"upcoming","submissions":0},
{"ends_at":"2026-11-30T23:59","number":1,"starts_at":"2026-11-01T00:00","state":"open","submissions":4}]}
''';
void main() {
test('the league API is read: league, rounds in order, players by rank', () {
final d = LeagueStandings.fromJson(jsonDecode(_json) as Map<String, dynamic>);
expect(d.league.name, 'Liga 2026-2027');
expect(d.league.counted, 4);
expect([for (final r in d.rounds) r.number], [1, 2]);
expect(d.openRound?.number, 1);
expect(d.openRound?.endsAt, DateTime(2026, 11, 30, 23, 59));
expect(d.nextRound?.number, 2);
expect([for (final p in d.players) p.name], ['A', 'B']);
expect(d.players.first.cells.first?.score, 364);
expect(d.players.first.cells[1], isNull); // not shot yet
expect(d.players.first.finalScore, 364);
});
}