Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Model test (Beacon and User model). #114

Merged
merged 5 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 71 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -606,13 +613,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:
Expand Down Expand Up @@ -648,6 +648,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:
Expand Down Expand Up @@ -886,6 +893,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:
Expand Down Expand Up @@ -933,6 +954,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:
Expand Down Expand Up @@ -975,13 +1010,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:
Expand Down Expand Up @@ -1101,6 +1150,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:
Expand All @@ -1115,6 +1171,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:
Expand Down
7 changes: 4 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ dependencies:
fluttertoast: ^8.0.3
data_connection_checker: ^0.3.4
geocoder:
git:
url: https://github.com/nguyenxdat/flutter_geocoder.git
ref: 443b875d8ec80ce525cc6e8f17dfbbbbe7fa3028
git:
url: https://github.com/nguyenxdat/flutter_geocoder.git
ref: 443b875d8ec80ce525cc6e8f17dfbbbbe7fa3028
geolocator: ^7.0.1
get_it: ^7.2.0
google_maps_flutter: ^2.0.6
Expand All @@ -49,6 +49,7 @@ dev_dependencies:
flutter_test:
sdk: flutter
hive_generator: ^1.1.0
test: ^1.14.4

flutter_icons:
android: "launcher_icon"
Expand Down
59 changes: 59 additions & 0 deletions test/model_tests/beacon_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'package:beacon/models/beacon/beacon.dart';
import 'package:test/test.dart';

void main() {
//structered according to fetchBeaconDetail Query.
Map<String, dynamic> dummyJson = {
"_id": "61fd51b4f0c4c3219ce356f5",
"title": "new",
"leader": {"name": "asdasd"},
"followers": [
{
"_id": "61fd509bf0c4c3219ce356ed",
"name": "asdasd",
"location": {"lat": "10", "lon": "20"}
}
],
"landmarks": [
{
"title": "land",
"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.title);
//leader name
expect("asdasd", beacon.leader.name);
//follower id
expect("61fd509bf0c4c3219ce356ed", beacon.followers.first.id);
//follower name
expect("asdasd", beacon.followers.first.name);
//follower location
expect("10", beacon.followers.first.location.lat);
//longitude
expect("20", beacon.followers.first.location.lon);
//landmark
expect("land", 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);
});
}
162 changes: 162 additions & 0 deletions test/model_tests/user_test.dart
Original file line number Diff line number Diff line change
@@ -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<String, dynamic> dummyJson = {
"_id": "61fd509bf0c4c3219ce356ed",
"name": "asdasd",
"email": "asdf@g.com",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding random alphabets, I think it would be better to be more generic, like change it to "test_name"
And also since you've written the model tests it would be better to add validation check too. For ex: _id can't be null (similarly for other fields in user and beacon model)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do the needful!

"location": {"lat": "10", "lon": "20"},
"beacons": [
{
"_id": "61fd51b4f0c4c3219ce356f5",
"title": "new",
"leader": {"name": "asdasd"},
"followers": [
{
"_id": "61fd509bf0c4c3219ce356ed",
"name": "asdasd",
"location": {"lat": "10", "lon": "20"}
}
],
"landmarks": [
{
"title": "land",
"location": {"lat": "1", "lon": "2"}
}
],
"location": {"lat": "1", "lon": "2"},
"startsAt": 1669746600000,
"expiresAt": 1669746600001,
"shortcode": "WCQDUR"
}
],
};
Map<String, dynamic> dummyJson2 = {
"_id": "61fd509bf0c4c3219ce356de",
"name": "asd",
"email": "as@g.com",
"location": {"lat": "20", "lon": "10"},
"beacons": [
{
"_id": "61fd51b4f0c4c3219ce3565f",
"title": "newer",
"leader": {"name": "asd"},
"followers": [
{
"_id": "61fd509bf0c4c3219ce356de",
"name": "asd",
"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("asdasd", user.name);
//email
expect("asdf@g.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.title);
//leader name
expect("asdasd", beacon.leader.name);
//follower id
expect("61fd509bf0c4c3219ce356ed", beacon.followers.first.id);
//follower name
expect("asdasd", beacon.followers.first.name);
//follower location
expect("10", beacon.followers.first.location.lat);
//longitude
expect("20", beacon.followers.first.location.lon);
//landmark
expect("land", 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("asd", user.name);
//email
expect("as@g.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("newer", beacon.title);
//leader name
expect("asd", beacon.leader.name);
//follower id
expect("61fd509bf0c4c3219ce356de", beacon.followers.first.id);
//follower name
expect("asd", 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);
});
});
}
7 changes: 0 additions & 7 deletions test/widget_test.dart

This file was deleted.