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 all 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 @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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_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);
});
}
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": "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<String, dynamic> 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);
});
});
}
7 changes: 0 additions & 7 deletions test/widget_test.dart

This file was deleted.