From 72ee2360adacf38541f1b39c36f203a2837f2229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Sat, 29 Jul 2023 14:08:06 +0100 Subject: [PATCH] fix api schedule parser --- uni/lib/controller/parsers/parser_schedule.dart | 10 ++++++---- uni/test/integration/src/schedule_page_test.dart | 10 ++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/uni/lib/controller/parsers/parser_schedule.dart b/uni/lib/controller/parsers/parser_schedule.dart index e4d4c2845..89052b786 100644 --- a/uni/lib/controller/parsers/parser_schedule.dart +++ b/uni/lib/controller/parsers/parser_schedule.dart @@ -24,15 +24,17 @@ Future> parseSchedule(http.Response response) async { final json = jsonDecode(response.body) as Map; - final schedule = json['horario']; - - for (final lecture in schedule as List>) { + final schedule = json['horario'] as List; + for (var lecture in schedule) { + lecture = lecture as Map; final day = ((lecture['dia'] as int) - 2) % 7; // Api: monday = 2, Lecture.dart class: monday = 0 final secBegin = lecture['hora_inicio'] as int; final subject = lecture['ucurr_sigla'] as String; final typeClass = lecture['tipo'] as String; - final blocks = ((lecture['aula_duracao'] as double) * 2).round(); + // TODO(luisd): this was marked as a double on the develop branch but the tests' + // example api returns an integer. At the moment there are no classes so I can't test this. + final blocks = (lecture['aula_duracao'] as int) * 2; final room = (lecture['sala_sigla'] as String).replaceAll(RegExp(r'\+'), '\n'); final teacher = lecture['doc_sigla'] as String; diff --git a/uni/test/integration/src/schedule_page_test.dart b/uni/test/integration/src/schedule_page_test.dart index b4cfc9523..34d11deaa 100644 --- a/uni/test/integration/src/schedule_page_test.dart +++ b/uni/test/integration/src/schedule_page_test.dart @@ -14,6 +14,8 @@ import 'package:uni/model/entities/course.dart'; import 'package:uni/model/entities/profile.dart'; import 'package:uni/model/entities/session.dart'; import 'package:uni/model/providers/lazy/lecture_provider.dart'; +import 'package:uni/model/providers/startup/profile_provider.dart'; +import 'package:uni/model/providers/startup/session_provider.dart'; import 'package:uni/view/schedule/schedule.dart'; import '../../test_widget.dart'; @@ -23,6 +25,8 @@ class MockClient extends Mock implements http.Client {} class MockResponse extends Mock implements http.Response {} +class MockSessionProvider extends Mock implements SessionProvider {} + class UriMatcher extends CustomMatcher { UriMatcher(Matcher matcher) : super('Uri that has', 'string', matcher); @@ -46,11 +50,17 @@ void main() { when(badMockResponse.statusCode).thenReturn(500); final scheduleProvider = LectureProvider(); + final sessionProvider = MockSessionProvider(); + + when(sessionProvider.session).thenReturn( + Session(username: 'up1234', cookies: 'cookie', faculties: ['feup']), + ); const widget = SchedulePage(); final providers = [ ChangeNotifierProvider(create: (_) => scheduleProvider), + ChangeNotifierProvider(create: (_) => sessionProvider), ]; await tester.pumpWidget(testableWidget(widget, providers: providers));