diff --git a/pubspec.lock b/pubspec.lock index 5631eadd..19332f51 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -197,6 +197,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.0.0" + coverage: + dependency: transitive + description: + name: coverage + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" crypto: dependency: transitive description: @@ -613,13 +620,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.11" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.3" meta: dependency: transitive description: @@ -655,6 +655,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.4.2" + node_preamble: + dependency: transitive + description: + name: node_preamble + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" normalize: dependency: transitive description: @@ -893,6 +900,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.4" + shelf_packages_handler: + dependency: transitive + description: + name: shelf_packages_handler + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" + shelf_static: + dependency: transitive + description: + name: shelf_static + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" shelf_web_socket: dependency: transitive description: @@ -940,6 +961,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + source_map_stack_trace: + dependency: transitive + description: + name: source_map_stack_trace + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" + source_maps: + dependency: transitive + description: + name: source_maps + url: "https://pub.dartlang.org" + source: hosted + version: "0.10.10" source_span: dependency: transitive description: @@ -982,13 +1017,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.2.0" + test: + dependency: "direct dev" + description: + name: test + url: "https://pub.dartlang.org" + source: hosted + version: "1.17.12" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.8" + version: "0.4.3" + test_core: + dependency: transitive + description: + name: test_core + url: "https://pub.dartlang.org" + source: hosted + version: "0.4.2" timezone: dependency: transitive description: @@ -1108,6 +1157,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.1" + vm_service: + dependency: transitive + description: + name: vm_service + url: "https://pub.dartlang.org" + source: hosted + version: "7.5.0" watcher: dependency: transitive description: @@ -1122,6 +1178,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + webkit_inspection_protocol: + dependency: transitive + description: + name: webkit_inspection_protocol + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" win32: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 57793334..c010283b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -50,6 +50,7 @@ dev_dependencies: flutter_test: sdk: flutter hive_generator: ^1.1.0 + test: ^1.14.4 flutter_icons: android: "launcher_icon" diff --git a/test/model_tests/beacon_test.dart b/test/model_tests/beacon_test.dart new file mode 100644 index 00000000..369b7711 --- /dev/null +++ b/test/model_tests/beacon_test.dart @@ -0,0 +1,59 @@ +import 'package:beacon/models/beacon/beacon.dart'; +import 'package:test/test.dart'; + +void main() { + //structered according to fetchBeaconDetail Query. + Map dummyJson = { + "_id": "61fd51b4f0c4c3219ce356f5", + "title": "new_beacon", + "leader": {"name": "test_leader"}, + "followers": [ + { + "_id": "61fd509bf0c4c3219ce356ed", + "name": "test_leader", + "location": {"lat": "10", "lon": "20"} + } + ], + "landmarks": [ + { + "title": "landmark", + "location": {"lat": "1", "lon": "2"} + } + ], + "location": {"lat": "1", "lon": "2"}, + "startsAt": 1669746600000, + "expiresAt": 1669746600001, + "shortcode": "WCQDUR" + }; + + test('Beacon.fromJson method works or not: ', () { + Beacon beacon = Beacon.fromJson(dummyJson); + //beacon id + expect("61fd51b4f0c4c3219ce356f5", beacon.id); + //title + expect("new_beacon", beacon.title); + //leader name + expect("test_leader", beacon.leader.name); + //follower id + expect("61fd509bf0c4c3219ce356ed", beacon.followers.first.id); + //follower name + expect("test_leader", beacon.followers.first.name); + //follower location + expect("10", beacon.followers.first.location.lat); + //longitude + expect("20", beacon.followers.first.location.lon); + //landmark + expect("landmark", beacon.landmarks.first.title); + expect("1", beacon.landmarks.first.location.lat); + expect("2", beacon.landmarks.first.location.lon); + //beacon location + expect("1", beacon.location.lat); + expect("2", beacon.location.lon); + //starts at + expect(1669746600000, beacon.startsAt); + //expires at + expect(1669746600001, beacon.expiresAt); + //short code + expect("WCQDUR", beacon.shortcode); + }); +} diff --git a/test/model_tests/user_test.dart b/test/model_tests/user_test.dart new file mode 100644 index 00000000..a69b26a6 --- /dev/null +++ b/test/model_tests/user_test.dart @@ -0,0 +1,162 @@ +import 'package:beacon/models/beacon/beacon.dart'; +import 'package:beacon/models/user/user_info.dart'; +import 'package:test/test.dart'; + +void main() { + //structered according to fetchBeaconDetail Query. + Map dummyJson = { + "_id": "61fd509bf0c4c3219ce356ed", + "name": "test_user", + "email": "test_user@gmail.com", + "location": {"lat": "10", "lon": "20"}, + "beacons": [ + { + "_id": "61fd51b4f0c4c3219ce356f5", + "title": "new_beacon", + "leader": {"name": "test_user"}, + "followers": [ + { + "_id": "61fd509bf0c4c3219ce356ed", + "name": "test_user", + "location": {"lat": "10", "lon": "20"} + } + ], + "landmarks": [ + { + "title": "landmark_one", + "location": {"lat": "1", "lon": "2"} + } + ], + "location": {"lat": "1", "lon": "2"}, + "startsAt": 1669746600000, + "expiresAt": 1669746600001, + "shortcode": "WCQDUR" + } + ], + }; + Map dummyJson2 = { + "_id": "61fd509bf0c4c3219ce356de", + "name": "test_user_two", + "email": "test_user_two@gmail.com", + "location": {"lat": "20", "lon": "10"}, + "beacons": [ + { + "_id": "61fd51b4f0c4c3219ce3565f", + "title": "beacon_two", + "leader": {"name": "test_user_two"}, + "followers": [ + { + "_id": "61fd509bf0c4c3219ce356de", + "name": "test_user_two", + "location": {"lat": "20", "lon": "10"} + } + ], + "landmarks": [ + { + "title": "landmark", + "location": {"lat": "2", "lon": "1"} + } + ], + "location": {"lat": "2", "lon": "1"}, + "startsAt": 1669746600001, + "expiresAt": 1669746600002, + "shortcode": "WCQDUK" + } + ], + }; + + group('Testing User Model', () { + test('User.fromJson method works or not: ', () { + User user = User.fromJson(dummyJson); + Beacon beacon = user.beacon.first; + //user id; + expect("61fd509bf0c4c3219ce356ed", user.id); + //name + expect("test_user", user.name); + //email + expect("test_user@gmail.com", user.email); + //isGuest + expect(false, user.isGuest); + //location + expect("10", user.location.lat); + expect("20", user.location.lon); + //beacon id + expect("61fd51b4f0c4c3219ce356f5", beacon.id); + //title + expect("new_beacon", beacon.title); + //leader name + expect("test_user", beacon.leader.name); + //follower id + expect("61fd509bf0c4c3219ce356ed", beacon.followers.first.id); + //follower name + expect("test_user", beacon.followers.first.name); + //follower location + expect("10", beacon.followers.first.location.lat); + //longitude + expect("20", beacon.followers.first.location.lon); + //landmark + expect("landmark_one", beacon.landmarks.first.title); + expect("1", beacon.landmarks.first.location.lat); + expect("2", beacon.landmarks.first.location.lon); + //beacon location + expect("1", beacon.location.lat); + expect("2", beacon.location.lon); + //starts at + expect(1669746600000, beacon.startsAt); + //expires at + expect(1669746600001, beacon.expiresAt); + //short code + expect("WCQDUR", beacon.shortcode); + }); + + test('Testing if update() method works', () { + User user = User.fromJson(dummyJson); + user.authToken = 'authTokenIntial'; + User updateToUser = User.fromJson(dummyJson2); + updateToUser.authToken = 'FinalAuthToken'; + updateToUser.isGuest = true; + user.update(updateToUser); + Beacon beacon = user.beacon.first; + //auth token + expect("FinalAuthToken", user.authToken); + //userID + expect("61fd509bf0c4c3219ce356ed", user.id); + //name + expect("test_user_two", user.name); + //email + expect("test_user_two@gmail.com", user.email); + //isGuest + expect(true, user.isGuest); + //location + expect("20", user.location.lat); + expect("10", user.location.lon); + //beacon id + expect("61fd51b4f0c4c3219ce3565f", beacon.id); + //title + expect("beacon_two", beacon.title); + //leader name + expect("test_user_two", beacon.leader.name); + //follower id + expect("61fd509bf0c4c3219ce356de", beacon.followers.first.id); + //follower name + expect("test_user_two", beacon.followers.first.name); + //follower location + expect("20", beacon.followers.first.location.lat); + //longitude + expect("10", beacon.followers.first.location.lon); + //landmark + expect("landmark", beacon.landmarks.first.title); + expect("2", beacon.landmarks.first.location.lat); + expect("1", beacon.landmarks.first.location.lon); + //beacon location + expect("2", beacon.location.lat); + expect("1", beacon.location.lon); + //starts at + expect(1669746600001, beacon.startsAt); + //expires at + expect(1669746600002, beacon.expiresAt); + //short code + expect("WCQDUK", beacon.shortcode); + }); + }); +} diff --git a/test/widget_test.dart b/test/widget_test.dart deleted file mode 100644 index 90a1f500..00000000 --- a/test/widget_test.dart +++ /dev/null @@ -1,7 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; - -void main() { - testWidgets('Empty test', (WidgetTester tester) async { - // Build our app and trigger a frame. - }); -}