chore: use isConnected flag instead of checking db value.
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -12,6 +12,9 @@ import 'package:stream_chat/src/db/chat_persistence_client.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
class TestPersistenceClient extends ChatPersistenceClient {
|
||||
@override
|
||||
bool get isConnected => throw UnimplementedError();
|
||||
|
||||
@override
|
||||
Future<void> connect(String userId) => throw UnimplementedError();
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
|
||||
|
||||
bool get _debugIsConnected {
|
||||
assert(() {
|
||||
if (db == null) {
|
||||
if (!isConnected) {
|
||||
throw StateError('''
|
||||
$runtimeType hasn't been connected yet or used after `disconnect`
|
||||
was called. Consider calling `connect` to create a connection.
|
||||
@@ -408,7 +408,7 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
|
||||
@override
|
||||
Future<void> disconnect({bool flush = false}) async {
|
||||
_logger.info('disconnect');
|
||||
if (db != null) {
|
||||
if (isConnected) {
|
||||
_logger.info('Disconnecting');
|
||||
if (flush) {
|
||||
_logger.info('Flushing');
|
||||
|
||||
@@ -16,9 +16,9 @@ void main() {
|
||||
const userId = 'testUserId';
|
||||
test('successfully connects with the Database', () async {
|
||||
final client = StreamChatPersistenceClient(logLevel: Level.ALL);
|
||||
expect(client.db, isNull);
|
||||
expect(client.isConnected, false);
|
||||
await client.connect(userId, databaseProvider: testDatabaseProvider);
|
||||
expect(client.db, isNotNull);
|
||||
expect(client.isConnected, true);
|
||||
expect(client.db, isA<DriftChatDatabase>());
|
||||
expect(client.db!.userId, userId);
|
||||
|
||||
@@ -29,10 +29,9 @@ void main() {
|
||||
|
||||
test('throws if already connected', () async {
|
||||
final client = StreamChatPersistenceClient(logLevel: Level.ALL);
|
||||
expect(client.db, isNull);
|
||||
expect(client.isConnected, false);
|
||||
await client.connect(userId, databaseProvider: testDatabaseProvider);
|
||||
expect(client.db, isNotNull);
|
||||
expect(client.db, isNotNull);
|
||||
expect(client.isConnected, true);
|
||||
expect(client.db, isA<DriftChatDatabase>());
|
||||
expect(client.db!.userId, userId);
|
||||
expect(
|
||||
@@ -50,9 +49,9 @@ void main() {
|
||||
const userId = 'testUserId';
|
||||
final client = StreamChatPersistenceClient(logLevel: Level.ALL);
|
||||
await client.connect(userId, databaseProvider: testDatabaseProvider);
|
||||
expect(client.db, isNotNull);
|
||||
expect(client.isConnected, true);
|
||||
await client.disconnect(flush: true);
|
||||
expect(client.db, isNull);
|
||||
expect(client.isConnected, false);
|
||||
});
|
||||
|
||||
test('client function throws stateError if db is not yet connected', () {
|
||||
|
||||
Reference in New Issue
Block a user