From 3854bfcdc93b0d7b22150d48ae8a7337ddc42a3f Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Wed, 17 Mar 2021 14:01:39 +0530 Subject: [PATCH] test(persistence): add test for list converter Signed-off-by: Sahil Kumar --- .../src/converter/list_coverter_test.dart | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 packages/stream_chat_persistence/test/src/converter/list_coverter_test.dart diff --git a/packages/stream_chat_persistence/test/src/converter/list_coverter_test.dart b/packages/stream_chat_persistence/test/src/converter/list_coverter_test.dart new file mode 100644 index 00000000..a5bedd40 --- /dev/null +++ b/packages/stream_chat_persistence/test/src/converter/list_coverter_test.dart @@ -0,0 +1,53 @@ +import 'dart:convert'; + +import 'package:test/test.dart'; +import 'package:stream_chat_persistence/src/converter/list_converter.dart'; + +void main() { + group('mapToDart', () { + final listConverter = ListConverter(); + + test('should return null if nothing is provided', () { + final res = listConverter.mapToDart(null); + expect(res, isNull); + }); + + 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()), + ); + }); + + 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()), + ); + }); + + 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', () { + final listConverter = ListConverter(); + + test('should return null if nothing is provided', () { + final res = listConverter.mapToSql(null); + expect(res, isNull); + }); + + test('should return json string if data list is provided', () { + final data = ['data1', 'data2', 'data3']; + final res = listConverter.mapToSql(data); + expect(res, jsonEncode(data)); + }); + }); +}