Skip to content

Commit 60e7676

Browse files
authored
Update README.md
1 parent 59ded6d commit 60e7676

File tree

1 file changed

+37
-10
lines changed

1 file changed

+37
-10
lines changed

README.md

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ class UserRepository {
1414
FirebaseDatabase firebaseDatabase;
1515
1616
Future<String> getUserName(String userId) async {
17-
final userNode =
18-
firebaseDatabase.reference().child('users').child('$userId/name');
17+
final userNameReference =
18+
firebaseDatabase.reference().child('users').child(userId).child('name');
19+
final dataSnapshot = await userNameReference.once();
20+
return dataSnapshot.value;
21+
}
22+
23+
Future<Map<String, dynamic>> getUser(String userId) async {
24+
final userNode = firebaseDatabase.reference().child('users/$userId');
1925
final dataSnapshot = await userNode.once();
2026
return dataSnapshot.value;
2127
}
@@ -27,20 +33,41 @@ void main() {
2733
// Put fake data
2834
const userId = 'userId';
2935
const userName = 'Elon musk';
30-
MockFirebaseDatabase.instance
31-
.reference()
32-
.child('users')
33-
.child(userId)
34-
.child('name')
35-
.set(userName);
36+
const fakeData = {
37+
'users': {
38+
userId: {
39+
'name': userName,
40+
'email': '[email protected]',
41+
'photoUrl': 'url-to-photo.jpg',
42+
},
43+
'otherUserId': {
44+
'name': 'userName',
45+
'email': '[email protected]',
46+
'photoUrl': 'other_url-to-photo.jpg',
47+
}
48+
}
49+
};
50+
MockFirebaseDatabase.instance.reference().set(fakeData);
3651
setUp(() {
3752
firebaseDatabase = MockFirebaseDatabase.instance;
3853
userRepository = UserRepository(firebaseDatabase);
3954
});
40-
test('Should contain value', () async {
41-
final userNameFromFakeDatabase = userRepository.getUserName(userId);
55+
test('Should get userName ...', () async {
56+
final userNameFromFakeDatabase = await userRepository.getUserName(userId);
4257
expect(userNameFromFakeDatabase, equals(userName));
4358
});
59+
60+
test('Should get user ...', () async {
61+
final userNameFromFakeDatabase = await userRepository.getUser(userId);
62+
expect(
63+
userNameFromFakeDatabase,
64+
equals({
65+
'name': userName,
66+
'email': '[email protected]',
67+
'photoUrl': 'url-to-photo.jpg',
68+
}),
69+
);
70+
});
4471
}
4572
4673
```

0 commit comments

Comments
 (0)