@@ -27,7 +27,7 @@ dependencies:
|
|||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
build_runner: ^2.3.3
|
build_runner: ^2.3.3
|
||||||
dart_code_metrics: ^5.7.0
|
dart_code_metrics: ^5.7.2
|
||||||
freezed: ^2.3.2
|
freezed: ^2.3.2
|
||||||
json_serializable: ^6.6.1
|
json_serializable: ^6.6.1
|
||||||
mocktail: ^0.3.0
|
mocktail: ^0.3.0
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ flutter:
|
|||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
dart_code_metrics: ^5.7.0
|
dart_code_metrics: ^5.7.2
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
golden_toolkit: ^0.15.0
|
golden_toolkit: ^0.15.0
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ dependencies:
|
|||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
build_runner: ^2.3.3
|
build_runner: ^2.3.3
|
||||||
dart_code_metrics: ^5.7.0
|
dart_code_metrics: ^5.7.2
|
||||||
fake_async: ^1.2.0
|
fake_async: ^1.2.0
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ dependencies:
|
|||||||
stream_chat_flutter: ^5.3.0
|
stream_chat_flutter: ^5.3.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
dart_code_metrics: ^4.16.0
|
dart_code_metrics: ^5.7.2
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ targets:
|
|||||||
builders:
|
builders:
|
||||||
drift_dev:
|
drift_dev:
|
||||||
options:
|
options:
|
||||||
generate_connect_constructor: true
|
|
||||||
data_class_to_companions: false
|
data_class_to_companions: false
|
||||||
apply_converters_on_variables: true
|
apply_converters_on_variables: true
|
||||||
generate_values_in_copy_with: true
|
generate_values_in_copy_with: true
|
||||||
|
|||||||
@@ -6,7 +6,21 @@ import 'package:drift/drift.dart';
|
|||||||
/// by the sqlite backend.
|
/// by the sqlite backend.
|
||||||
class ListConverter<T> extends TypeConverter<List<T>, String> {
|
class ListConverter<T> extends TypeConverter<List<T>, String> {
|
||||||
@override
|
@override
|
||||||
List<T>? mapToDart(String? fromDb) {
|
List<T> fromSql(String fromDb) {
|
||||||
|
return List<T>.from(jsonDecode(fromDb) ?? []);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toSql(List<T> value) {
|
||||||
|
return jsonEncode(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Maps a nullable [List] of type [T] into a nullable [String] understood
|
||||||
|
/// by the sqlite backend.
|
||||||
|
class NullableListConverter<T> extends TypeConverter<List<T>?, String?> {
|
||||||
|
@override
|
||||||
|
List<T>? fromSql(String? fromDb) {
|
||||||
if (fromDb == null) {
|
if (fromDb == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -14,7 +28,7 @@ class ListConverter<T> extends TypeConverter<List<T>, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String? mapToSql(List<T>? value) {
|
String? toSql(List<T>? value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,21 @@ import 'package:drift/drift.dart';
|
|||||||
/// by the sqlite backend.
|
/// by the sqlite backend.
|
||||||
class MapConverter<T> extends TypeConverter<Map<String, T>, String> {
|
class MapConverter<T> extends TypeConverter<Map<String, T>, String> {
|
||||||
@override
|
@override
|
||||||
Map<String, T>? mapToDart(String? fromDb) {
|
Map<String, T> fromSql(String fromDb) {
|
||||||
|
return Map<String, T>.from(jsonDecode(fromDb) ?? {});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toSql(Map<String, T> value) {
|
||||||
|
return jsonEncode(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Maps a nullable [Map] of type [String], [T] into a nullable [String]
|
||||||
|
/// understood by the sqlite backend.
|
||||||
|
class NullableMapConverter<T> extends TypeConverter<Map<String, T>?, String?> {
|
||||||
|
@override
|
||||||
|
Map<String, T>? fromSql(String? fromDb) {
|
||||||
if (fromDb == null) {
|
if (fromDb == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -14,7 +28,7 @@ class MapConverter<T> extends TypeConverter<Map<String, T>, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String? mapToSql(Map<String, T>? value) {
|
String? toSql(Map<String, T>? value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-6
@@ -6,7 +6,7 @@ import 'package:stream_chat/stream_chat.dart';
|
|||||||
class MessageSendingStatusConverter
|
class MessageSendingStatusConverter
|
||||||
extends TypeConverter<MessageSendingStatus, int> {
|
extends TypeConverter<MessageSendingStatus, int> {
|
||||||
@override
|
@override
|
||||||
MessageSendingStatus? mapToDart(int? fromDb) {
|
MessageSendingStatus fromSql(int fromDb) {
|
||||||
switch (fromDb) {
|
switch (fromDb) {
|
||||||
case 0:
|
case 0:
|
||||||
return MessageSendingStatus.sending;
|
return MessageSendingStatus.sending;
|
||||||
@@ -22,13 +22,12 @@ class MessageSendingStatusConverter
|
|||||||
return MessageSendingStatus.deleting;
|
return MessageSendingStatus.deleting;
|
||||||
case 6:
|
case 6:
|
||||||
return MessageSendingStatus.failed_delete;
|
return MessageSendingStatus.failed_delete;
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return MessageSendingStatus.sending;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int? mapToSql(MessageSendingStatus? value) {
|
int toSql(MessageSendingStatus value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case MessageSendingStatus.sending:
|
case MessageSendingStatus.sending:
|
||||||
return 0;
|
return 0;
|
||||||
@@ -44,8 +43,6 @@ class MessageSendingStatusConverter
|
|||||||
return 5;
|
return 5;
|
||||||
case MessageSendingStatus.failed_delete:
|
case MessageSendingStatus.failed_delete:
|
||||||
return 6;
|
return 6;
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
|
|
||||||
part of 'channel_dao.dart';
|
part of 'channel_dao.dart';
|
||||||
|
|
||||||
// **************************************************************************
|
// ignore_for_file: type=lint
|
||||||
// DaoGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
mixin _$ChannelDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
mixin _$ChannelDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
||||||
$ChannelsTable get channels => attachedDatabase.channels;
|
$ChannelsTable get channels => attachedDatabase.channels;
|
||||||
$UsersTable get users => attachedDatabase.users;
|
$UsersTable get users => attachedDatabase.users;
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
|
|
||||||
part of 'channel_query_dao.dart';
|
part of 'channel_query_dao.dart';
|
||||||
|
|
||||||
// **************************************************************************
|
// ignore_for_file: type=lint
|
||||||
// DaoGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
mixin _$ChannelQueryDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
mixin _$ChannelQueryDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
||||||
$ChannelQueriesTable get channelQueries => attachedDatabase.channelQueries;
|
$ChannelQueriesTable get channelQueries => attachedDatabase.channelQueries;
|
||||||
$ChannelsTable get channels => attachedDatabase.channels;
|
$ChannelsTable get channels => attachedDatabase.channels;
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
|
|
||||||
part of 'connection_event_dao.dart';
|
part of 'connection_event_dao.dart';
|
||||||
|
|
||||||
// **************************************************************************
|
// ignore_for_file: type=lint
|
||||||
// DaoGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
mixin _$ConnectionEventDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
mixin _$ConnectionEventDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
||||||
$ConnectionEventsTable get connectionEvents =>
|
$ConnectionEventsTable get connectionEvents =>
|
||||||
attachedDatabase.connectionEvents;
|
attachedDatabase.connectionEvents;
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
|
|
||||||
part of 'member_dao.dart';
|
part of 'member_dao.dart';
|
||||||
|
|
||||||
// **************************************************************************
|
// ignore_for_file: type=lint
|
||||||
// DaoGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
mixin _$MemberDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
mixin _$MemberDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
||||||
$MembersTable get members => attachedDatabase.members;
|
$MembersTable get members => attachedDatabase.members;
|
||||||
$UsersTable get users => attachedDatabase.users;
|
$UsersTable get users => attachedDatabase.users;
|
||||||
|
|||||||
@@ -2,11 +2,9 @@
|
|||||||
|
|
||||||
part of 'message_dao.dart';
|
part of 'message_dao.dart';
|
||||||
|
|
||||||
// **************************************************************************
|
// ignore_for_file: type=lint
|
||||||
// DaoGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
mixin _$MessageDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
mixin _$MessageDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
||||||
|
$ChannelsTable get channels => attachedDatabase.channels;
|
||||||
$MessagesTable get messages => attachedDatabase.messages;
|
$MessagesTable get messages => attachedDatabase.messages;
|
||||||
$UsersTable get users => attachedDatabase.users;
|
$UsersTable get users => attachedDatabase.users;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,9 @@
|
|||||||
|
|
||||||
part of 'pinned_message_dao.dart';
|
part of 'pinned_message_dao.dart';
|
||||||
|
|
||||||
// **************************************************************************
|
// ignore_for_file: type=lint
|
||||||
// DaoGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
mixin _$PinnedMessageDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
mixin _$PinnedMessageDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
||||||
|
$ChannelsTable get channels => attachedDatabase.channels;
|
||||||
$PinnedMessagesTable get pinnedMessages => attachedDatabase.pinnedMessages;
|
$PinnedMessagesTable get pinnedMessages => attachedDatabase.pinnedMessages;
|
||||||
$UsersTable get users => attachedDatabase.users;
|
$UsersTable get users => attachedDatabase.users;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
|
|
||||||
part of 'pinned_message_reaction_dao.dart';
|
part of 'pinned_message_reaction_dao.dart';
|
||||||
|
|
||||||
// **************************************************************************
|
// ignore_for_file: type=lint
|
||||||
// DaoGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
mixin _$PinnedMessageReactionDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
mixin _$PinnedMessageReactionDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
||||||
$PinnedMessageReactionsTable get pinnedMessageReactions =>
|
$PinnedMessageReactionsTable get pinnedMessageReactions =>
|
||||||
attachedDatabase.pinnedMessageReactions;
|
attachedDatabase.pinnedMessageReactions;
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
|
|
||||||
part of 'reaction_dao.dart';
|
part of 'reaction_dao.dart';
|
||||||
|
|
||||||
// **************************************************************************
|
// ignore_for_file: type=lint
|
||||||
// DaoGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
mixin _$ReactionDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
mixin _$ReactionDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
||||||
$ReactionsTable get reactions => attachedDatabase.reactions;
|
$ReactionsTable get reactions => attachedDatabase.reactions;
|
||||||
$UsersTable get users => attachedDatabase.users;
|
$UsersTable get users => attachedDatabase.users;
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
|
|
||||||
part of 'read_dao.dart';
|
part of 'read_dao.dart';
|
||||||
|
|
||||||
// **************************************************************************
|
// ignore_for_file: type=lint
|
||||||
// DaoGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
mixin _$ReadDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
mixin _$ReadDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
||||||
$ReadsTable get reads => attachedDatabase.reads;
|
$ReadsTable get reads => attachedDatabase.reads;
|
||||||
$UsersTable get users => attachedDatabase.users;
|
$UsersTable get users => attachedDatabase.users;
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
|
|
||||||
part of 'user_dao.dart';
|
part of 'user_dao.dart';
|
||||||
|
|
||||||
// **************************************************************************
|
// ignore_for_file: type=lint
|
||||||
// DaoGenerator
|
|
||||||
// **************************************************************************
|
|
||||||
|
|
||||||
mixin _$UserDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
mixin _$UserDaoMixin on DatabaseAccessor<DriftChatDatabase> {
|
||||||
$UsersTable get users => attachedDatabase.users;
|
$UsersTable get users => attachedDatabase.users;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
import 'package:stream_chat/stream_chat.dart';
|
import 'package:stream_chat/stream_chat.dart';
|
||||||
|
|
||||||
import 'package:stream_chat_persistence/src/converter/converter.dart';
|
import 'package:stream_chat_persistence/src/converter/converter.dart';
|
||||||
import 'package:stream_chat_persistence/src/dao/dao.dart';
|
import 'package:stream_chat_persistence/src/dao/dao.dart';
|
||||||
import 'package:stream_chat_persistence/src/entity/entity.dart';
|
import 'package:stream_chat_persistence/src/entity/entity.dart';
|
||||||
@@ -37,18 +36,12 @@ part 'drift_chat_database.g.dart';
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
class DriftChatDatabase extends _$DriftChatDatabase {
|
class DriftChatDatabase extends _$DriftChatDatabase {
|
||||||
/// Creates a new moor chat database instance
|
/// Creates a new drift chat database instance
|
||||||
DriftChatDatabase(
|
DriftChatDatabase(
|
||||||
this._userId,
|
this._userId,
|
||||||
QueryExecutor executor,
|
QueryExecutor executor,
|
||||||
) : super(executor);
|
) : super(executor);
|
||||||
|
|
||||||
/// Instantiate a new database instance
|
|
||||||
DriftChatDatabase.connect(
|
|
||||||
this._userId,
|
|
||||||
DatabaseConnection connection,
|
|
||||||
) : super.connect(connection);
|
|
||||||
|
|
||||||
final String _userId;
|
final String _userId;
|
||||||
|
|
||||||
/// User id to which the database is connected
|
/// User id to which the database is connected
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -23,7 +23,7 @@ class SharedDB {
|
|||||||
}) async {
|
}) async {
|
||||||
final dbName = 'db_$userId';
|
final dbName = 'db_$userId';
|
||||||
if (connectionMode == ConnectionMode.background) {
|
if (connectionMode == ConnectionMode.background) {
|
||||||
return DriftChatDatabase.connect(
|
return DriftChatDatabase(
|
||||||
userId,
|
userId,
|
||||||
DatabaseConnection.delayed(Future(() async {
|
DatabaseConnection.delayed(Future(() async {
|
||||||
final isolate = await _createMoorIsolate(
|
final isolate = await _createMoorIsolate(
|
||||||
@@ -34,6 +34,7 @@ class SharedDB {
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return DriftChatDatabase(
|
return DriftChatDatabase(
|
||||||
userId,
|
userId,
|
||||||
LazyDatabase(
|
LazyDatabase(
|
||||||
@@ -68,7 +69,7 @@ class SharedDB {
|
|||||||
logStatements: request.logStatements,
|
logStatements: request.logStatements,
|
||||||
));
|
));
|
||||||
final moorIsolate = DriftIsolate.inCurrent(
|
final moorIsolate = DriftIsolate.inCurrent(
|
||||||
() => DatabaseConnection.fromExecutor(executor),
|
() => DatabaseConnection(executor),
|
||||||
);
|
);
|
||||||
request.sendMoorIsolate.send(moorIsolate);
|
request.sendMoorIsolate.send(moorIsolate);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import 'package:stream_chat_persistence/src/converter/list_converter.dart';
|
|||||||
import 'package:stream_chat_persistence/src/converter/map_converter.dart';
|
import 'package:stream_chat_persistence/src/converter/map_converter.dart';
|
||||||
import 'package:stream_chat_persistence/src/converter/message_sending_status_converter.dart';
|
import 'package:stream_chat_persistence/src/converter/message_sending_status_converter.dart';
|
||||||
|
|
||||||
|
import 'channels.dart';
|
||||||
|
|
||||||
/// Represents a [Messages] table in [MoorChatDatabase].
|
/// Represents a [Messages] table in [MoorChatDatabase].
|
||||||
@DataClassName('MessageEntity')
|
@DataClassName('MessageEntity')
|
||||||
class Messages extends Table {
|
class Messages extends Table {
|
||||||
@@ -78,10 +80,11 @@ class Messages extends Table {
|
|||||||
|
|
||||||
/// The channel cid of which this message is part of
|
/// The channel cid of which this message is part of
|
||||||
TextColumn get channelCid =>
|
TextColumn get channelCid =>
|
||||||
text().customConstraint('REFERENCES channels(cid) ON DELETE CASCADE')();
|
text().references(Channels, #cid, onDelete: KeyAction.cascade)();
|
||||||
|
|
||||||
/// A Map of [messageText] translations.
|
/// A Map of [messageText] translations.
|
||||||
TextColumn get i18n => text().nullable().map(MapConverter<String>())();
|
TextColumn get i18n =>
|
||||||
|
text().nullable().map(NullableMapConverter<String>())();
|
||||||
|
|
||||||
/// Message custom extraData
|
/// Message custom extraData
|
||||||
TextColumn get extraData => text().nullable().map(MapConverter<Object?>())();
|
TextColumn get extraData => text().nullable().map(MapConverter<Object?>())();
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// coverage:ignore-file
|
// coverage:ignore-file
|
||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
|
|
||||||
import 'package:stream_chat_persistence/src/entity/messages.dart';
|
import 'package:stream_chat_persistence/src/entity/messages.dart';
|
||||||
|
|
||||||
/// Represents a [PinnedMessages] table in [MoorChatDatabase].
|
/// Represents a [PinnedMessages] table in [MoorChatDatabase].
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ environment:
|
|||||||
flutter: ">=1.17.0"
|
flutter: ">=1.17.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
drift: ^1.7.1
|
drift: ^2.7.0
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
logging: ^1.0.1
|
logging: ^1.0.1
|
||||||
@@ -23,8 +23,8 @@ dependencies:
|
|||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
build_runner: ^2.3.3
|
build_runner: ^2.3.3
|
||||||
dart_code_metrics: ^4.18.0
|
dart_code_metrics: ^5.7.2
|
||||||
drift_dev: ^1.7.1
|
drift_dev: ^2.7.0
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
mocktail: ^0.3.0
|
mocktail: ^0.3.0
|
||||||
|
|||||||
@@ -4,50 +4,89 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
import 'package:stream_chat_persistence/src/converter/list_converter.dart';
|
import 'package:stream_chat_persistence/src/converter/list_converter.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('mapToDart', () {
|
group('ListConverter', () {
|
||||||
final listConverter = ListConverter<String>();
|
final listConverter = ListConverter<String>();
|
||||||
|
|
||||||
test('should return null if nothing is provided', () {
|
group('fromSql', () {
|
||||||
final res = listConverter.mapToDart(null);
|
test('should throw type error if the provided json is not a list', () {
|
||||||
expect(res, isNull);
|
final json = {'test_key': 'testData'};
|
||||||
|
expect(
|
||||||
|
() => listConverter.fromSql(jsonEncode(json)),
|
||||||
|
throwsA(isA<TypeError>()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'should throw type error if the provided json is not a list of String',
|
||||||
|
() {
|
||||||
|
final json = [22, 33, 44];
|
||||||
|
expect(
|
||||||
|
() => listConverter.fromSql(jsonEncode(json)),
|
||||||
|
throwsA(isA<TypeError>()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return list of String if json data list is provided', () {
|
||||||
|
final data = ['data1', 'data2', 'data3'];
|
||||||
|
final res = listConverter.fromSql(jsonEncode(data));
|
||||||
|
expect(res.length, data.length);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should throw type error if the provided json is not a list', () {
|
group('toSql', () {
|
||||||
final json = {'test_key': 'testData'};
|
test('should return json string if data list is provided', () {
|
||||||
expect(
|
final data = ['data1', 'data2', 'data3'];
|
||||||
() => listConverter.mapToDart(jsonEncode(json)),
|
final res = listConverter.toSql(data);
|
||||||
throwsA(isA<TypeError>()),
|
expect(res, jsonEncode(data));
|
||||||
);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
test('should throw type error if the provided json is not a list of String',
|
|
||||||
() {
|
|
||||||
final json = [22, 33, 44];
|
|
||||||
expect(
|
|
||||||
() => listConverter.mapToDart(jsonEncode(json)),
|
|
||||||
throwsA(isA<TypeError>()),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should return list of String if json data list is provided', () {
|
|
||||||
final data = ['data1', 'data2', 'data3'];
|
|
||||||
final res = listConverter.mapToDart(jsonEncode(data));
|
|
||||||
expect(res!.length, data.length);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('mapToSql', () {
|
group('NullableListConverter', () {
|
||||||
final listConverter = ListConverter<String>();
|
final listConverter = NullableListConverter<String>();
|
||||||
|
|
||||||
test('should return null if nothing is provided', () {
|
group('fromSql', () {
|
||||||
final res = listConverter.mapToSql(null);
|
test('should return null if nothing is provided', () {
|
||||||
expect(res, isNull);
|
final res = listConverter.fromSql(null);
|
||||||
|
expect(res, isNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should throw type error if the provided json is not a list', () {
|
||||||
|
final json = {'test_key': 'testData'};
|
||||||
|
expect(
|
||||||
|
() => listConverter.fromSql(jsonEncode(json)),
|
||||||
|
throwsA(isA<TypeError>()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'should throw type error if the provided json is not a list of String',
|
||||||
|
() {
|
||||||
|
final json = [22, 33, 44];
|
||||||
|
expect(
|
||||||
|
() => listConverter.fromSql(jsonEncode(json)),
|
||||||
|
throwsA(isA<TypeError>()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return list of String if json data list is provided', () {
|
||||||
|
final data = ['data1', 'data2', 'data3'];
|
||||||
|
final res = listConverter.fromSql(jsonEncode(data));
|
||||||
|
expect(res!.length, data.length);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return json string if data list is provided', () {
|
group('toSql', () {
|
||||||
final data = ['data1', 'data2', 'data3'];
|
test('should return null if nothing is provided', () {
|
||||||
final res = listConverter.mapToSql(data);
|
final res = listConverter.toSql(null);
|
||||||
expect(res, jsonEncode(data));
|
expect(res, isNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return json string if data list is provided', () {
|
||||||
|
final data = ['data1', 'data2', 'data3'];
|
||||||
|
final res = listConverter.toSql(data);
|
||||||
|
expect(res, jsonEncode(data));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,61 +4,109 @@ import 'package:flutter_test/flutter_test.dart';
|
|||||||
import 'package:stream_chat_persistence/src/converter/map_converter.dart';
|
import 'package:stream_chat_persistence/src/converter/map_converter.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('mapToDart', () {
|
group('MapConverter', () {
|
||||||
final mapConverter = MapConverter<String>();
|
final mapConverter = MapConverter<String>();
|
||||||
|
|
||||||
test('should return null if nothing is provided', () {
|
group('fromSql', () {
|
||||||
final res = mapConverter.mapToDart(null);
|
test('should throw type error if the provided json is not a map', () {
|
||||||
expect(res, isNull);
|
const json = ['testData1', 'testData2', 'testData3'];
|
||||||
});
|
|
||||||
|
|
||||||
test('should throw type error if the provided json is not a map', () {
|
|
||||||
const json = ['testData1', 'testData2', 'testData3'];
|
|
||||||
expect(
|
|
||||||
() => mapConverter.mapToDart(jsonEncode(json)),
|
|
||||||
throwsA(isA<TypeError>()),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test(
|
|
||||||
'should throw type error if the provided json is not a '
|
|
||||||
'map of String, String',
|
|
||||||
() {
|
|
||||||
const json = {'test_key': 22, 'test_key2': 33, 'test_key3': 44};
|
|
||||||
expect(
|
expect(
|
||||||
() => mapConverter.mapToDart(jsonEncode(json)),
|
() => mapConverter.fromSql(jsonEncode(json)),
|
||||||
throwsA(isA<TypeError>()),
|
throwsA(isA<TypeError>()),
|
||||||
);
|
);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
|
|
||||||
test('should return map of String, String if json data is provided', () {
|
test(
|
||||||
const data = {
|
'should throw type error if the provided json is not a '
|
||||||
'test_key': 'testValue',
|
'map of String, String',
|
||||||
'test_key2': 'testValue2',
|
() {
|
||||||
'test_key3': 'testValue3',
|
const json = {'test_key': 22, 'test_key2': 33, 'test_key3': 44};
|
||||||
};
|
expect(
|
||||||
final res = mapConverter.mapToDart(jsonEncode(data));
|
() => mapConverter.fromSql(jsonEncode(json)),
|
||||||
expect(res, data);
|
throwsA(isA<TypeError>()),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('should return map of String, String if json data is provided', () {
|
||||||
|
const data = {
|
||||||
|
'test_key': 'testValue',
|
||||||
|
'test_key2': 'testValue2',
|
||||||
|
'test_key3': 'testValue3',
|
||||||
|
};
|
||||||
|
final res = mapConverter.fromSql(jsonEncode(data));
|
||||||
|
expect(res, data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('toSql', () {
|
||||||
|
test('should return json string if data map is provided', () {
|
||||||
|
const data = {
|
||||||
|
'test_key': 'testValue',
|
||||||
|
'test_key2': 'testValue2',
|
||||||
|
'test_key3': 'testValue3',
|
||||||
|
};
|
||||||
|
final res = mapConverter.toSql(data);
|
||||||
|
expect(res, jsonEncode(data));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('mapToSql', () {
|
group('NullableMapConverter', () {
|
||||||
final mapConverter = MapConverter<String>();
|
final mapConverter = NullableMapConverter<String>();
|
||||||
|
|
||||||
test('should return null if nothing is provided', () {
|
group('fromSql', () {
|
||||||
final res = mapConverter.mapToSql(null);
|
test('should return null if nothing is provided', () {
|
||||||
expect(res, isNull);
|
final res = mapConverter.fromSql(null);
|
||||||
|
expect(res, isNull);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should throw type error if the provided json is not a map', () {
|
||||||
|
const json = ['testData1', 'testData2', 'testData3'];
|
||||||
|
expect(
|
||||||
|
() => mapConverter.fromSql(jsonEncode(json)),
|
||||||
|
throwsA(isA<TypeError>()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'should throw type error if the provided json is not a '
|
||||||
|
'map of String, String',
|
||||||
|
() {
|
||||||
|
const json = {'test_key': 22, 'test_key2': 33, 'test_key3': 44};
|
||||||
|
expect(
|
||||||
|
() => mapConverter.fromSql(jsonEncode(json)),
|
||||||
|
throwsA(isA<TypeError>()),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
test('should return map of String, String if json data is provided', () {
|
||||||
|
const data = {
|
||||||
|
'test_key': 'testValue',
|
||||||
|
'test_key2': 'testValue2',
|
||||||
|
'test_key3': 'testValue3',
|
||||||
|
};
|
||||||
|
final res = mapConverter.fromSql(jsonEncode(data));
|
||||||
|
expect(res, data);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return json string if data map is provided', () {
|
group('toSql', () {
|
||||||
const data = {
|
test('should return null if nothing is provided', () {
|
||||||
'test_key': 'testValue',
|
final res = mapConverter.toSql(null);
|
||||||
'test_key2': 'testValue2',
|
expect(res, isNull);
|
||||||
'test_key3': 'testValue3',
|
});
|
||||||
};
|
|
||||||
final res = mapConverter.mapToSql(data);
|
test('should return json string if data map is provided', () {
|
||||||
expect(res, jsonEncode(data));
|
const data = {
|
||||||
|
'test_key': 'testValue',
|
||||||
|
'test_key2': 'testValue2',
|
||||||
|
'test_key3': 'testValue3',
|
||||||
|
};
|
||||||
|
final res = mapConverter.toSql(data);
|
||||||
|
expect(res, jsonEncode(data));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-14
@@ -3,30 +3,20 @@ import 'package:stream_chat/stream_chat.dart';
|
|||||||
import 'package:stream_chat_persistence/src/converter/message_sending_status_converter.dart';
|
import 'package:stream_chat_persistence/src/converter/message_sending_status_converter.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('mapToDart', () {
|
group('fromSql', () {
|
||||||
final statusConverter = MessageSendingStatusConverter();
|
final statusConverter = MessageSendingStatusConverter();
|
||||||
|
|
||||||
test('should return null if nothing is provided', () {
|
|
||||||
final res = statusConverter.mapToDart(null);
|
|
||||||
expect(res, isNull);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should return expected status if status code is provided', () {
|
test('should return expected status if status code is provided', () {
|
||||||
final res = statusConverter.mapToDart(3);
|
final res = statusConverter.fromSql(3);
|
||||||
expect(res, MessageSendingStatus.updating);
|
expect(res, MessageSendingStatus.updating);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('mapToSql', () {
|
group('toSql', () {
|
||||||
final statusConverter = MessageSendingStatusConverter();
|
final statusConverter = MessageSendingStatusConverter();
|
||||||
|
|
||||||
test('should return null if nothing is provided', () {
|
|
||||||
final res = statusConverter.mapToSql(null);
|
|
||||||
expect(res, isNull);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should return expected code if the status is provided', () {
|
test('should return expected code if the status is provided', () {
|
||||||
final res = statusConverter.mapToSql(MessageSendingStatus.updating);
|
final res = statusConverter.toSql(MessageSendingStatus.updating);
|
||||||
expect(res, 3);
|
expect(res, 3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ void main() {
|
|||||||
final isolate = await DriftIsolate.spawn(_backgroundConnection);
|
final isolate = await DriftIsolate.spawn(_backgroundConnection);
|
||||||
final connection = DatabaseConnection.delayed(isolate.connect());
|
final connection = DatabaseConnection.delayed(isolate.connect());
|
||||||
|
|
||||||
final database = DriftChatDatabase.connect(userId, connection);
|
final database = DriftChatDatabase(userId, connection);
|
||||||
expect(database, isNotNull);
|
expect(database, isNotNull);
|
||||||
expect(database.userId, userId);
|
expect(database.userId, userId);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user