chore: minor fix, add test
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -272,17 +272,14 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
|
||||
channels.map((e) => getChannelStateByCid(e.cid)),
|
||||
);
|
||||
|
||||
// Only sort the channel states if the channels are not already sorted.
|
||||
if (channelStateSort == null) {
|
||||
// Sort the channel states
|
||||
var comparator = _defaultChannelStateComparator;
|
||||
if (channelStateSort != null && channelStateSort.isNotEmpty) {
|
||||
comparator = _combineComparators(
|
||||
channelStateSort.map((it) => it.comparator).withNullifyer,
|
||||
);
|
||||
}
|
||||
|
||||
channelStates.sort(comparator);
|
||||
}
|
||||
|
||||
final offset = paginationParams?.offset;
|
||||
if (offset != null && offset > 0 && channelStates.isNotEmpty) {
|
||||
|
||||
@@ -245,7 +245,22 @@ void main() {
|
||||
.called(1);
|
||||
});
|
||||
|
||||
test('getChannelStates', () async {
|
||||
group('getChannelState', () {
|
||||
test('should throw if sort is provided without comparator', () async {
|
||||
final sort = [
|
||||
const SortOption<ChannelState>(
|
||||
'testField',
|
||||
direction: SortOption.ASC,
|
||||
),
|
||||
];
|
||||
|
||||
expect(
|
||||
() => client.getChannelStates(channelStateSort: sort),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('should work fine', () async {
|
||||
const cid = 'testType:testId';
|
||||
final channels = List.generate(3, (index) => ChannelModel(cid: cid));
|
||||
final messages = List.generate(3, (index) => Message());
|
||||
@@ -291,7 +306,8 @@ void main() {
|
||||
final fetched = fetchedChannelStates[i];
|
||||
expect(fetched.members?.length, original.members?.length);
|
||||
expect(fetched.messages?.length, original.messages?.length);
|
||||
expect(fetched.pinnedMessages?.length, original.pinnedMessages?.length);
|
||||
expect(
|
||||
fetched.pinnedMessages?.length, original.pinnedMessages?.length);
|
||||
expect(fetched.read?.length, original.read?.length);
|
||||
expect(fetched.channel!.cid, original.channel!.cid);
|
||||
}
|
||||
@@ -304,6 +320,7 @@ void main() {
|
||||
verify(() => mockDatabase.pinnedMessageDao.getMessagesByCid(cid))
|
||||
.called(3);
|
||||
});
|
||||
});
|
||||
|
||||
test('updateChannelQueries', () async {
|
||||
final filter = Filter.in_('members', const ['testUserId']);
|
||||
|
||||
Reference in New Issue
Block a user