forked from famedly/matrix-dart-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! fixup! fixup! fixup! fixup! fixup! TW-2165: Improve get/store …
…Participants
- Loading branch information
Showing
6 changed files
with
203 additions
and
21 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
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 |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import 'package:matrix/matrix.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'fake_client.dart'; | ||
|
||
void main() { | ||
late Client client; | ||
late Room room; | ||
group('Store user to Database test\n', () { | ||
setUp(() async { | ||
client = await getClient(); | ||
final heroes = [ | ||
'@alice:matrix.org', | ||
'@bob:example.com', | ||
'@charley:example.org' | ||
]; | ||
final id = '!localpart:server.abc'; | ||
final membership = Membership.join; | ||
room = Room( | ||
client: client, | ||
id: id, | ||
membership: membership, | ||
prev_batch: '', | ||
summary: RoomSummary.fromJson({ | ||
'm.joined_member_count': 2, | ||
'm.invited_member_count': 2, | ||
'm.heroes': heroes, | ||
}), | ||
roomAccountData: { | ||
'com.test.foo': BasicRoomEvent( | ||
type: 'com.test.foo', | ||
content: {'foo': 'bar'}, | ||
), | ||
'm.fully_read': BasicRoomEvent( | ||
type: 'm.fully_read', | ||
content: {'event_id': '\$event_id:example.com'}, | ||
), | ||
}, | ||
); | ||
}); | ||
|
||
test( | ||
'GIVE a user from server\n' | ||
'ADD add user to database\n' | ||
'THEN user added\n', () async { | ||
final userServer = User( | ||
'@bob:example.org', | ||
displayName: 'Bob', | ||
avatarUrl: 'mxc://example.com', | ||
room: room, | ||
); | ||
|
||
await room.handleStoreUserInDatabase(userServer); | ||
|
||
final userDataBase = await client.database?.getUser(userServer.id, room); | ||
|
||
expect(userDataBase != null, true); | ||
|
||
expect(userDataBase?.id, userServer.id); | ||
}); | ||
|
||
test( | ||
'GIVE users from server\n' | ||
'ADD add users to database\n' | ||
'THEN users added\n', () async { | ||
final usersServer = [ | ||
User( | ||
'@bob:example.org', | ||
displayName: 'Bob', | ||
avatarUrl: 'mxc://example.com', | ||
room: room, | ||
), | ||
User( | ||
'@bob2:example.org', | ||
displayName: 'Bob_2', | ||
avatarUrl: 'mxc://example.com', | ||
room: room, | ||
), | ||
User( | ||
'@bob3:example.org', | ||
displayName: 'Bob_3', | ||
avatarUrl: 'mxc://example.com', | ||
room: room, | ||
), | ||
]; | ||
|
||
final getUsersInitial = await client.database?.getUsers(room); | ||
|
||
expect(getUsersInitial?.isEmpty, true); | ||
|
||
for (final user in usersServer) { | ||
await room.handleStoreUserInDatabase(user); | ||
} | ||
|
||
final users = await client.database?.getUsers(room); | ||
|
||
expect(users?.length, 3); | ||
}); | ||
|
||
test( | ||
'GIVE users (Bob, Bob_2, Bob_3) from server\n' | ||
'ADD add users to database\n' | ||
'AND add same users (Bob, Bob_2, Bob_3) again\n' | ||
'THEN users (Bob, Bob_2, Bob_3) added\n', () async { | ||
final usersServer = [ | ||
User( | ||
'@bob:example.org', | ||
displayName: 'Bob', | ||
avatarUrl: 'mxc://example.com', | ||
room: room, | ||
), | ||
User( | ||
'@bob2:example.org', | ||
displayName: 'Bob_2', | ||
avatarUrl: 'mxc://example.com', | ||
room: room, | ||
), | ||
User( | ||
'@bob3:example.org', | ||
displayName: 'Bob_3', | ||
avatarUrl: 'mxc://example.com', | ||
room: room, | ||
), | ||
]; | ||
|
||
final getUsersInitial = await client.database?.getUsers(room); | ||
|
||
expect(getUsersInitial?.isEmpty, true); | ||
|
||
for (final user in usersServer) { | ||
await room.handleStoreUserInDatabase(user); | ||
} | ||
|
||
final usersAddFirstTime = await client.database?.getUsers(room); | ||
|
||
expect(usersAddFirstTime?.length, 3); | ||
|
||
for (final user in usersServer) { | ||
await room.handleStoreUserInDatabase(user); | ||
} | ||
|
||
final usersAddSecondTime = await client.database?.getUsers(room); | ||
|
||
expect(usersAddSecondTime?.length, 3); | ||
|
||
expect( | ||
usersAddSecondTime | ||
?.where((user) => user.stateKey == '@bob:example.org') | ||
.isNotEmpty, | ||
true, | ||
); | ||
|
||
expect( | ||
usersAddSecondTime | ||
?.where((user) => user.stateKey == '@bob2:example.org') | ||
.isNotEmpty, | ||
true, | ||
); | ||
|
||
expect( | ||
usersAddSecondTime | ||
?.where((user) => user.stateKey == '@bob3:example.org') | ||
.isNotEmpty, | ||
true, | ||
); | ||
}); | ||
}); | ||
} |