Skip to content

Commit

Permalink
test(booking_collection): add test cases for serializable methods
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed Jan 15, 2023
1 parent 978e908 commit 68ba0d9
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
132 changes: 132 additions & 0 deletions test/model/booking_collection_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import 'dart:collection';

import 'package:cabin_booking/model.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('BookingCollection', () {
group('.fromJson()', () {
test('should create a new BookingCollection from two JSON arrays', () {
const rawBookingCollection = {
'b': [
{
'id': 'booking-1-id',
'cd': '1969-07-20T20:18:04.000Z',
'md': '1969-07-20T20:18:04.000Z',
'mc': 1,
'sd': '2022-12-04T09:00:00.000Z',
'ed': '2022-12-04T10:30:00.000Z',
'de': 'Student 1',
'il': true,
},
{
'id': 'booking-2-id',
'cd': '1969-07-20T20:18:04.000Z',
'md': '1969-07-20T20:18:04.000Z',
'mc': 1,
'sd': '2022-12-05T20:00:00.000Z',
'ed': '2022-12-05T21:00:00.000Z',
'de': 'Student 2',
'il': false,
},
],
'rb': [
{
'id': 'recurring-booking-id',
'cd': '1969-07-20T20:18:04.000Z',
'md': '1969-07-20T20:18:04.000Z',
'mc': 1,
'sd': '2022-12-04T09:00:00.000Z',
'ed': '2022-12-04T10:30:00.000Z',
'de': 'Student 3',
'il': false,
'p': 1,
're': 1,
'red': '2023-02-04T00:00:00.000Z',
},
],
};
expect(
BookingCollection.fromJson(rawBookingCollection),
BookingCollection(
bookings: SplayTreeSet.of({
SingleBooking(
id: 'booking-1-id',
startDate: DateTime.utc(2022, 12, 4, 9),
endDate: DateTime.utc(2022, 12, 4, 10, 30),
description: 'Student 1',
isLocked: true,
),
SingleBooking(
id: 'booking-2-id',
startDate: DateTime.utc(2022, 12, 5, 20),
endDate: DateTime.utc(2022, 12, 5, 21),
description: 'Student 2',
),
}),
recurringBookings: SplayTreeSet.of({
RecurringBooking(
id: 'recurring-booking-id',
startDate: DateTime.utc(2022, 12, 4, 9),
endDate: DateTime.utc(2022, 12, 4, 10, 30),
description: 'Student 3',
recurringEndDate: DateTime.utc(2023, 2, 4),
),
}),
),
);
});
});

group('.toJson()', () {
test(
'should return a JSON object representation of this BookingCollection',
() {
const rawBookingCollection = {
'b': [
{
'id': 'booking-1-id',
'cd': '1969-07-20T20:18:04.000Z',
'md': '1969-07-20T20:18:04.000Z',
'mc': 1,
'sd': '2022-12-04T09:00:00.000Z',
'ed': '2022-12-04T10:30:00.000Z',
'de': 'Student 1',
'il': true,
},
{
'id': 'booking-2-id',
'cd': '1969-07-20T20:18:04.000Z',
'md': '1969-07-20T20:18:04.000Z',
'mc': 1,
'sd': '2022-12-05T20:00:00.000Z',
'ed': '2022-12-05T21:00:00.000Z',
'de': 'Student 2',
'il': false,
},
],
'rb': [
{
'id': 'recurring-booking-id',
'cd': '1969-07-20T20:18:04.000Z',
'md': '1969-07-20T20:18:04.000Z',
'mc': 1,
'sd': '2022-12-04T09:00:00.000Z',
'ed': '2022-12-04T10:30:00.000Z',
'de': 'Student 3',
'il': false,
'p': 1,
're': 1,
'red': '2023-02-04T00:00:00.000Z',
},
],
};
expect(
BookingCollection.fromJson(rawBookingCollection).toJson(),
rawBookingCollection,
);
},
);
});
});
}
2 changes: 2 additions & 0 deletions test/model/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'booking/recurring_booking_test.dart' as recurring_booking_test;
import 'booking/single_booking_test.dart' as single_booking_test;
import 'booking_collection_test.dart' as booking_collection_test;
import 'cabin/cabin_elements_test.dart' as cabin_elements_test;
import 'cabin/cabin_test.dart' as cabin_test;
import 'cabin/piano_test.dart' as piano_test;
Expand All @@ -13,6 +14,7 @@ import 'school_year/school_year_test.dart' as school_year_test;
void main() {
recurring_booking_test.main();
single_booking_test.main();
booking_collection_test.main();
cabin_elements_test.main();
cabin_test.main();
piano_test.main();
Expand Down

0 comments on commit 68ba0d9

Please sign in to comment.