From abbe72709e905632372d3d12bedad6fee7b899e9 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Fri, 19 Mar 2021 17:49:50 +0530 Subject: [PATCH] test(persistence): add return channel with pagination applies test in channel query dao Signed-off-by: Sahil Kumar --- .../test/src/dao/channel_query_dao_test.dart | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/packages/stream_chat_persistence/test/src/dao/channel_query_dao_test.dart b/packages/stream_chat_persistence/test/src/dao/channel_query_dao_test.dart index 8ee0e0c0..4566ca94 100644 --- a/packages/stream_chat_persistence/test/src/dao/channel_query_dao_test.dart +++ b/packages/stream_chat_persistence/test/src/dao/channel_query_dao_test.dart @@ -78,15 +78,17 @@ void main() { }); Future> _insertTestDataForGetChannel( - Map filter) async { + Map filter, { + int count = 3, + }) async { final now = DateTime.now(); final userDao = database.userDao; final channelDao = database.channelDao; - const cids = ['testCid0', 'testCid1', 'testCid2']; - final users = List.generate(3, (index) => User(id: 'testId$index')); + final cids = List.generate(count, (index) => 'testCid$index'); + final users = List.generate(count, (index) => User(id: 'testId$index')); final channels = List.generate( - 3, + count, (index) => ChannelModel( id: 'testId$index', type: 'testType$index', @@ -150,6 +152,30 @@ void main() { } }); + test( + 'should return all the inserted channels along with pagination applied', + () async { + const offset = 5; + const limit = 15; + const pagination = PaginationParams(offset: offset, limit: limit); + + // Inserting test data for get channels + final insertedChannels = await _insertTestDataForGetChannel( + filter, + count: 30, + ); + + // Should match with the inserted channels + final updatedChannels = await channelQueryDao.getChannels( + filter: filter, + paginationParams: pagination, + ); + expect(updatedChannels.length, limit); + expect(updatedChannels.first.id, 'testId24'); + expect(updatedChannels.first.cid, 'testCid24'); + }, + ); + test('should return sorted channels using member count', () async { int sortComparator(ChannelModel a, ChannelModel b) => b.memberCount.compareTo(a.memberCount);