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)),
|
channels.map((e) => getChannelStateByCid(e.cid)),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Only sort the channel states if the channels are not already sorted.
|
// Sort the channel states
|
||||||
if (channelStateSort == null) {
|
|
||||||
var comparator = _defaultChannelStateComparator;
|
var comparator = _defaultChannelStateComparator;
|
||||||
if (channelStateSort != null && channelStateSort.isNotEmpty) {
|
if (channelStateSort != null && channelStateSort.isNotEmpty) {
|
||||||
comparator = _combineComparators(
|
comparator = _combineComparators(
|
||||||
channelStateSort.map((it) => it.comparator).withNullifyer,
|
channelStateSort.map((it) => it.comparator).withNullifyer,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
channelStates.sort(comparator);
|
channelStates.sort(comparator);
|
||||||
}
|
|
||||||
|
|
||||||
final offset = paginationParams?.offset;
|
final offset = paginationParams?.offset;
|
||||||
if (offset != null && offset > 0 && channelStates.isNotEmpty) {
|
if (offset != null && offset > 0 && channelStates.isNotEmpty) {
|
||||||
|
|||||||
@@ -245,7 +245,22 @@ void main() {
|
|||||||
.called(1);
|
.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';
|
const cid = 'testType:testId';
|
||||||
final channels = List.generate(3, (index) => ChannelModel(cid: cid));
|
final channels = List.generate(3, (index) => ChannelModel(cid: cid));
|
||||||
final messages = List.generate(3, (index) => Message());
|
final messages = List.generate(3, (index) => Message());
|
||||||
@@ -291,7 +306,8 @@ void main() {
|
|||||||
final fetched = fetchedChannelStates[i];
|
final fetched = fetchedChannelStates[i];
|
||||||
expect(fetched.members?.length, original.members?.length);
|
expect(fetched.members?.length, original.members?.length);
|
||||||
expect(fetched.messages?.length, original.messages?.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.read?.length, original.read?.length);
|
||||||
expect(fetched.channel!.cid, original.channel!.cid);
|
expect(fetched.channel!.cid, original.channel!.cid);
|
||||||
}
|
}
|
||||||
@@ -304,6 +320,7 @@ void main() {
|
|||||||
verify(() => mockDatabase.pinnedMessageDao.getMessagesByCid(cid))
|
verify(() => mockDatabase.pinnedMessageDao.getMessagesByCid(cid))
|
||||||
.called(3);
|
.called(3);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('updateChannelQueries', () async {
|
test('updateChannelQueries', () async {
|
||||||
final filter = Filter.in_('members', const ['testUserId']);
|
final filter = Filter.in_('members', const ['testUserId']);
|
||||||
|
|||||||
Reference in New Issue
Block a user