Added test for user retrieval from firestore

This commit is contained in:
Mariano Uvalle 2019-02-25 16:19:36 -06:00
parent 7e8b0b074a
commit 4aadfbde8c
3 changed files with 73 additions and 27 deletions

View file

@ -14,17 +14,26 @@ class SummaryModel {
int addedFriday;
SummaryModel({
this.completedMonday,
this.addedMonday,
this.completedTuesday,
this.addedTuesday,
this.completedWednesday,
this.addedWednesday,
this.completedThursday,
this.addedThursday,
this.completedFriday,
this.addedFriday,
});
int completedMonday,
int addedMonday,
int completedTuesday,
int addedTuesday,
int completedWednesday,
int addedWednesday,
int completedThursday,
int addedThursday,
int completedFriday,
int addedFriday,
}) : completedMonday = completedMonday ?? 0,
addedMonday = addedMonday ?? 0,
completedTuesday = completedTuesday ?? 0,
addedTuesday = addedTuesday ?? 0,
completedWednesday = completedWednesday ?? 0,
addedWednesday = addedWednesday ?? 0,
completedThursday = completedThursday ?? 0,
addedThursday = addedThursday ?? 0,
completedFriday = completedFriday ?? 0,
addedFriday = addedFriday ?? 0;
/// Returns a [SummaryModel] from a map.
SummaryModel.fromMap(Map<String, dynamic> map) {

View file

@ -1,3 +1,4 @@
import 'package:meta/meta.dart';
import 'summary_model.dart';
/// An app user.
@ -6,43 +7,49 @@ import 'summary_model.dart';
class UserModel {
final String id;
final String username;
final List<int> tasks;
final List<String> tasks;
final SummaryModel summary;
final int userId;
final int pendingHigh;
final int pendingMedium;
final int pendingLow;
UserModel({
this.id,
this.username,
this.tasks,
this.summary,
this.userId,
this.pendingHigh,
this.pendingMedium,
this.pendingLow,
@required this.username,
@required this.tasks,
@required this.summary,
@required this.pendingHigh,
@required this.pendingMedium,
@required this.pendingLow,
});
///Returns a [UserModel] from a map.
UserModel.fromFirestore(Map<String, dynamic> firestoreMap, {String id})
: id = id,
username = firestoreMap["username"],
tasks = firestoreMap["tasks"].cast<int>(),
tasks = firestoreMap["tasks"].cast<String>(),
summary =
SummaryModel.fromMap(firestoreMap["summary"].cast<String, int>()),
userId = firestoreMap["userId"],
pendingHigh = firestoreMap["pendingHigh"],
pendingMedium = firestoreMap["pendingMedium"],
pendingLow = firestoreMap["pendingLow"];
Map<String, dynamic> toFirestoreMap() {
return <String, dynamic>{
"username": username,
"tasks": tasks,
"summary": summary.toMap(),
"pendingHigh": pendingHigh,
"pendingMedium": pendingMedium,
"pendingLow": pendingLow,
};
}
@override
int get hashCode =>
id.hashCode ^
username.hashCode ^
tasks.hashCode ^
summary.hashCode ^
userId.hashCode ^
pendingHigh.hashCode ^
pendingMedium.hashCode ^
pendingLow.hashCode;
@ -54,9 +61,7 @@ class UserModel {
other is UserModel &&
id == other.id &&
username == other.username &&
tasks == other.tasks &&
summary == other.summary &&
userId == other.userId &&
pendingHigh == other.pendingHigh &&
pendingMedium == other.pendingMedium &&
pendingLow == other.pendingLow;