@@ -4,50 +4,89 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:stream_chat_persistence/src/converter/list_converter.dart';
|
||||
|
||||
void main() {
|
||||
group('mapToDart', () {
|
||||
group('ListConverter', () {
|
||||
final listConverter = ListConverter<String>();
|
||||
|
||||
test('should return null if nothing is provided', () {
|
||||
final res = listConverter.mapToDart(null);
|
||||
expect(res, isNull);
|
||||
group('fromSql', () {
|
||||
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 throw type error if the provided json is not a list', () {
|
||||
final json = {'test_key': 'testData'};
|
||||
expect(
|
||||
() => listConverter.mapToDart(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.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('toSql', () {
|
||||
test('should return json string if data list is provided', () {
|
||||
final data = ['data1', 'data2', 'data3'];
|
||||
final res = listConverter.toSql(data);
|
||||
expect(res, jsonEncode(data));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
group('mapToSql', () {
|
||||
final listConverter = ListConverter<String>();
|
||||
group('NullableListConverter', () {
|
||||
final listConverter = NullableListConverter<String>();
|
||||
|
||||
test('should return null if nothing is provided', () {
|
||||
final res = listConverter.mapToSql(null);
|
||||
expect(res, isNull);
|
||||
group('fromSql', () {
|
||||
test('should return null if nothing is provided', () {
|
||||
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', () {
|
||||
final data = ['data1', 'data2', 'data3'];
|
||||
final res = listConverter.mapToSql(data);
|
||||
expect(res, jsonEncode(data));
|
||||
group('toSql', () {
|
||||
test('should return null if nothing is provided', () {
|
||||
final res = listConverter.toSql(null);
|
||||
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';
|
||||
|
||||
void main() {
|
||||
group('mapToDart', () {
|
||||
group('MapConverter', () {
|
||||
final mapConverter = MapConverter<String>();
|
||||
|
||||
test('should return null if nothing is provided', () {
|
||||
final res = mapConverter.mapToDart(null);
|
||||
expect(res, isNull);
|
||||
});
|
||||
|
||||
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};
|
||||
group('fromSql', () {
|
||||
test('should throw type error if the provided json is not a map', () {
|
||||
const json = ['testData1', 'testData2', 'testData3'];
|
||||
expect(
|
||||
() => mapConverter.mapToDart(jsonEncode(json)),
|
||||
() => 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.mapToDart(jsonEncode(data));
|
||||
expect(res, data);
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
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', () {
|
||||
final mapConverter = MapConverter<String>();
|
||||
group('NullableMapConverter', () {
|
||||
final mapConverter = NullableMapConverter<String>();
|
||||
|
||||
test('should return null if nothing is provided', () {
|
||||
final res = mapConverter.mapToSql(null);
|
||||
expect(res, isNull);
|
||||
group('fromSql', () {
|
||||
test('should return null if nothing is provided', () {
|
||||
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', () {
|
||||
const data = {
|
||||
'test_key': 'testValue',
|
||||
'test_key2': 'testValue2',
|
||||
'test_key3': 'testValue3',
|
||||
};
|
||||
final res = mapConverter.mapToSql(data);
|
||||
expect(res, jsonEncode(data));
|
||||
group('toSql', () {
|
||||
test('should return null if nothing is provided', () {
|
||||
final res = mapConverter.toSql(null);
|
||||
expect(res, isNull);
|
||||
});
|
||||
|
||||
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));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
+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';
|
||||
|
||||
void main() {
|
||||
group('mapToDart', () {
|
||||
group('fromSql', () {
|
||||
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', () {
|
||||
final res = statusConverter.mapToDart(3);
|
||||
final res = statusConverter.fromSql(3);
|
||||
expect(res, MessageSendingStatus.updating);
|
||||
});
|
||||
});
|
||||
|
||||
group('mapToSql', () {
|
||||
group('toSql', () {
|
||||
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', () {
|
||||
final res = statusConverter.mapToSql(MessageSendingStatus.updating);
|
||||
final res = statusConverter.toSql(MessageSendingStatus.updating);
|
||||
expect(res, 3);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ void main() {
|
||||
final isolate = await DriftIsolate.spawn(_backgroundConnection);
|
||||
final connection = DatabaseConnection.delayed(isolate.connect());
|
||||
|
||||
final database = DriftChatDatabase.connect(userId, connection);
|
||||
final database = DriftChatDatabase(userId, connection);
|
||||
expect(database, isNotNull);
|
||||
expect(database.userId, userId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user