diff --git a/lib/data/models/show.dart b/lib/data/models/show.dart index 144ef64a..4d8d6826 100644 --- a/lib/data/models/show.dart +++ b/lib/data/models/show.dart @@ -1,18 +1,17 @@ -import 'package:meta/meta.dart'; -import 'package:xml/xml.dart' as xml; import 'package:inkino/utils/xml_utils.dart'; +import 'package:xml/xml.dart' as xml; class Show { Show({ - @required this.id, - @required this.eventId, - @required this.title, - @required this.originalTitle, - @required this.url, - @required this.presentationMethod, - @required this.theaterAndAuditorium, - @required this.start, - @required this.end, + this.id, + this.eventId, + this.title, + this.originalTitle, + this.url, + this.presentationMethod, + this.theaterAndAuditorium, + this.start, + this.end, }); final String id; diff --git a/lib/data/networking/finnkino_api.dart b/lib/data/networking/finnkino_api.dart index 4f3593e5..382ab735 100644 --- a/lib/data/networking/finnkino_api.dart +++ b/lib/data/networking/finnkino_api.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:inkino/data/models/show.dart'; import 'package:inkino/data/models/theater.dart'; import 'package:inkino/data/networking/http_utils.dart'; import 'package:intl/intl.dart'; @@ -12,15 +13,16 @@ class FinnkinoApi { static final Uri kEventsBaseUrl = new Uri.https('www.finnkino.fi', '/en/xml/Events'); - Future getSchedule(Theater theater, DateTime date) async { + Future> getSchedule(Theater theater, DateTime date) async { var dt = ddMMyyyy.format(date ?? new DateTime.now()); - - return getRequest( + var response = await getRequest( kScheduleBaseUrl.replace(queryParameters: { 'area': theater.id, 'dt': dt, }), ); + + return Show.parseAll(response); } Future getNowInTheatersEvents(Theater theater) async { diff --git a/lib/redux/show/show_middleware.dart b/lib/redux/show/show_middleware.dart index a5b11b62..80eb6f47 100644 --- a/lib/redux/show/show_middleware.dart +++ b/lib/redux/show/show_middleware.dart @@ -52,8 +52,7 @@ class ShowMiddleware extends MiddlewareClass { DateTime currentDate, NextDispatcher next, ) async { - var showsXml = await api.getSchedule(newTheater, currentDate); - var shows = Show.parseAll(showsXml); + var shows = await api.getSchedule(newTheater, currentDate); var now = Clock.getCurrentTime(); // Return only show times that haven't started yet. diff --git a/test/redux/show/show_middleware_test.dart b/test/redux/show/show_middleware_test.dart index d22f9ac5..befbd5af 100644 --- a/test/redux/show/show_middleware_test.dart +++ b/test/redux/show/show_middleware_test.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'dart:io'; +import 'package:inkino/data/models/show.dart'; import 'package:inkino/data/models/theater.dart'; import 'package:inkino/redux/app/app_state.dart'; import 'package:inkino/redux/common_actions.dart'; @@ -15,7 +16,7 @@ import '../../mocks.dart'; void main() { group('ShowMiddleware', () { - final DateTime fakeDateTime = new DateTime(2018); + final DateTime startOf2018 = new DateTime(2018); final Theater theater = new Theater(id: 'abc123', name: 'Test Theater'); final List actionLog = []; final Function(dynamic) next = (action) => actionLog.add(action); @@ -32,9 +33,6 @@ void main() { ); } - Future _scheduleXml() => - new File('test_assets/schedule.xml').readAsString(); - setUp(() { mockFinnkinoApi = new MockFinnkinoApi(); mockStore = new MockStore(); @@ -42,8 +40,6 @@ void main() { // Given when(mockStore.state).thenReturn(_theaterState(currentTheater: theater)); - when(mockFinnkinoApi.getSchedule(theater, any)) - .thenReturn(_scheduleXml()); }); tearDown(() { @@ -57,7 +53,12 @@ void main() { // The middleware filters shows based on if the showtime has already // passed. As new DateTime(2018) will mean the very first hour and minute // in January, all the show times in test assets will be after this date. - Clock.getCurrentTime = () => fakeDateTime; + Clock.getCurrentTime = () => startOf2018; + when(mockFinnkinoApi.getSchedule(theater, any)).thenReturn([ + new Show(start: new DateTime(2018, 02, 21)), + new Show(start: new DateTime(2018, 02, 21)), + new Show(start: new DateTime(2018, 03, 21)), + ]); // When await sut.call(mockStore, new InitCompleteAction(null, theater), next); @@ -79,21 +80,23 @@ void main() { () async { // Given Clock.getCurrentTime = () => new DateTime(2018, 3); + when(mockFinnkinoApi.getSchedule(theater, any)).thenReturn([ + new Show(start: new DateTime(2018, 02, 21)), + new Show(start: new DateTime(2018, 02, 21)), + new Show(start: new DateTime(2018, 03, 21)), + ]); // When await sut.call( - mockStore, new ChangeCurrentDateAction(fakeDateTime), next); + mockStore, new ChangeCurrentDateAction(startOf2018), next); // Then - verify(mockFinnkinoApi.getSchedule(theater, fakeDateTime)); + verify(mockFinnkinoApi.getSchedule(theater, startOf2018)); expect(actionLog.length, 3); expect(actionLog[0], new isInstanceOf()); expect(actionLog[1], new isInstanceOf()); - // As there's only show in test_assets/schedule.xml that has a start - // time in 3rd month (or May) of 2018, the ReceivedShowsAction should - // be dispatched with only that show. final ReceivedShowsAction receivedShowsAction = actionLog[2]; expect(receivedShowsAction.shows.length, 1); },