Skip to content

Commit

Permalink
fix api schedule parser
Browse files Browse the repository at this point in the history
  • Loading branch information
LuisDuarte1 committed Jul 29, 2023
1 parent 6a1324c commit 72ee236
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 6 additions & 4 deletions uni/lib/controller/parsers/parser_schedule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ Future<List<Lecture>> parseSchedule(http.Response response) async {

final json = jsonDecode(response.body) as Map<String, dynamic>;

final schedule = json['horario'];

for (final lecture in schedule as List<Map<String, dynamic>>) {
final schedule = json['horario'] as List<dynamic>;
for (var lecture in schedule) {
lecture = lecture as Map<String, dynamic>;
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;
Expand Down
10 changes: 10 additions & 0 deletions uni/test/integration/src/schedule_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);

Expand All @@ -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<SessionProvider>(create: (_) => sessionProvider),
];

await tester.pumpWidget(testableWidget(widget, providers: providers));
Expand Down

0 comments on commit 72ee236

Please sign in to comment.