diff --git a/packages/stream_chat_persistence/test/src/converter/map_converter_test.dart b/packages/stream_chat_persistence/test/src/converter/map_converter_test.dart new file mode 100644 index 00000000..4727cb0d --- /dev/null +++ b/packages/stream_chat_persistence/test/src/converter/map_converter_test.dart @@ -0,0 +1,64 @@ +import 'dart:convert'; + +import 'package:test/test.dart'; +import 'package:stream_chat_persistence/src/converter/map_converter.dart'; + +void main() { + group('mapToDart', () { + final mapConverter = MapConverter(); + + 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()), + ); + }); + + 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.mapToDart(jsonEncode(json)), + throwsA(isA()), + ); + }, + ); + + 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); + }); + }); + + group('mapToSql', () { + final mapConverter = MapConverter(); + + test('should return null if nothing is provided', () { + final res = mapConverter.mapToSql(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.mapToSql(data); + expect(res, jsonEncode(data)); + }); + }); +}