-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from mario-bermonti:mario-bermonti/issue79
Add unit tests for FirebaseDB methods
- Loading branch information
Showing
3 changed files
with
12 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1 @@ | ||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:cognitive_data/databases/firebase_db/firebase_db.dart'; | ||
import 'package:cognitive_data/models/session.dart'; | ||
import 'package:fake_cloud_firestore/fake_cloud_firestore.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
late FirebaseDB db; | ||
late String currentSessionPath; | ||
|
||
setUp(() { | ||
db = FirebaseDB( | ||
FakeFirebaseFirestore(), | ||
participantID: '101', | ||
sessionID: '001', | ||
taskName: 'dsb', | ||
); | ||
currentSessionPath = | ||
'participants/${db.participantID}/cognitive_tasks/${db.taskName}/sessions/${db.sessionID}'; | ||
}); | ||
|
||
test( | ||
"FirebaseDB.addSession correctly adds data to Firebase", | ||
() async { | ||
final Session sessionLocal = Session( | ||
participantID: db.participantID, | ||
sessionID: db.sessionID, | ||
startTime: DateTime.now(), | ||
endTime: DateTime.now(), | ||
); | ||
|
||
await db.addSession(session: sessionLocal); | ||
|
||
final DocumentSnapshot sessionFirebaseSnapshot = await db.db | ||
.doc('$currentSessionPath/sessionMetadata/sessionMetadata') | ||
.get(); | ||
|
||
Map<String, dynamic> sessionFirebaseData = | ||
sessionFirebaseSnapshot.data() as Map<String, dynamic>; | ||
|
||
expect(sessionFirebaseData, sessionLocal.toJson()); | ||
}, | ||
); | ||
} |