test: add test.

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2023-05-05 02:21:06 +05:30
committed by xsahil03x
parent 7cc8e9ea5a
commit ee62abdbc4
2 changed files with 14 additions and 0 deletions
@@ -90,6 +90,7 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
'disconnect the previous instance before connecting again.',
);
}
_logger.info('connect');
db = databaseProvider?.call(userId, _connectionMode) ??
await _defaultDatabaseProvider(userId, _connectionMode);
}
@@ -55,6 +55,15 @@ void main() {
expect(client.db, isNull);
});
test('client function throws stateError if db is not yet connected', () {
final client = StreamChatPersistenceClient(logLevel: Level.ALL);
expect(
// Running a function that requires db connection.
() => client.getReplies('testParentId'),
throwsA(isA<StateError>()),
);
});
group('client functions', () {
const userId = 'testUserId';
final mockDatabase = MockChatDatabase();
@@ -66,6 +75,10 @@ void main() {
await client.connect(userId, databaseProvider: _mockDatabaseProvider);
});
tearDown(() async {
await client.disconnect();
});
test('getReplies', () async {
const parentId = 'testParentId';
final replies = List.generate(3, (index) => Message(id: 'testId$index'));