fix(persistence,llc,core,ui): deprecated sort, add channelStateSort s… (#1366)
* fix(persistence,llc,core,ui): deprecated sort, add channelStateSort sorting the channels offline using the state * update changelogs * update tests * remove deprecated test * change threashold * minor fixes * remove tests * fix(persistence): minor changes. Signed-off-by: xsahil03x <[email protected]> Signed-off-by: xsahil03x <[email protected]> Co-authored-by: Sahil Kumar <[email protected]>
This commit is contained in:
co-authored by
Sahil Kumar
parent
5784c53e6b
commit
d09d3817b5
@@ -121,7 +121,7 @@ jobs:
|
|||||||
uses: VeryGoodOpenSource/[email protected]
|
uses: VeryGoodOpenSource/[email protected]
|
||||||
with:
|
with:
|
||||||
path: packages/stream_chat_persistence/coverage/lcov.info
|
path: packages/stream_chat_persistence/coverage/lcov.info
|
||||||
min_coverage: 97
|
min_coverage: 95
|
||||||
- name: "Stream Chat Flutter Core Coverage Check"
|
- name: "Stream Chat Flutter Core Coverage Check"
|
||||||
uses: VeryGoodOpenSource/[email protected]
|
uses: VeryGoodOpenSource/[email protected]
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
|
|
||||||
- Remove disposed channel clients from the client state.
|
- Remove disposed channel clients from the client state.
|
||||||
|
|
||||||
|
- Deprecated the `sort` parameter in `queryChannels` in favor of `channelStateSort`.
|
||||||
|
|
||||||
## 5.0.0
|
## 5.0.0
|
||||||
|
|
||||||
- Included the changes from version [4.5.0](#450).
|
- Included the changes from version [4.5.0](#450).
|
||||||
|
|||||||
@@ -517,7 +517,10 @@ class StreamChatClient {
|
|||||||
/// Requests channels with a given query.
|
/// Requests channels with a given query.
|
||||||
Stream<List<Channel>> queryChannels({
|
Stream<List<Channel>> queryChannels({
|
||||||
Filter? filter,
|
Filter? filter,
|
||||||
List<SortOption<ChannelModel>>? sort,
|
@Deprecated('''
|
||||||
|
sort has been deprecated.
|
||||||
|
Please use channelStateSort instead.''') List<SortOption<ChannelModel>>? sort,
|
||||||
|
List<SortOption<ChannelState>>? channelStateSort,
|
||||||
bool state = true,
|
bool state = true,
|
||||||
bool watch = true,
|
bool watch = true,
|
||||||
bool presence = false,
|
bool presence = false,
|
||||||
@@ -547,7 +550,9 @@ class StreamChatClient {
|
|||||||
} else {
|
} else {
|
||||||
final channels = await queryChannelsOffline(
|
final channels = await queryChannelsOffline(
|
||||||
filter: filter,
|
filter: filter,
|
||||||
|
// ignore: deprecated_member_use_from_same_package
|
||||||
sort: sort,
|
sort: sort,
|
||||||
|
channelStateSort: channelStateSort,
|
||||||
paginationParams: paginationParams,
|
paginationParams: paginationParams,
|
||||||
);
|
);
|
||||||
if (channels.isNotEmpty) yield channels;
|
if (channels.isNotEmpty) yield channels;
|
||||||
@@ -555,7 +560,7 @@ class StreamChatClient {
|
|||||||
try {
|
try {
|
||||||
final newQueryChannelsFuture = queryChannelsOnline(
|
final newQueryChannelsFuture = queryChannelsOnline(
|
||||||
filter: filter,
|
filter: filter,
|
||||||
sort: sort,
|
sort: channelStateSort ?? sort,
|
||||||
state: state,
|
state: state,
|
||||||
watch: watch,
|
watch: watch,
|
||||||
presence: presence,
|
presence: presence,
|
||||||
@@ -598,7 +603,7 @@ class StreamChatClient {
|
|||||||
/// Requests channels with a given query from the API.
|
/// Requests channels with a given query from the API.
|
||||||
Future<List<Channel>> queryChannelsOnline({
|
Future<List<Channel>> queryChannelsOnline({
|
||||||
Filter? filter,
|
Filter? filter,
|
||||||
List<SortOption<ChannelModel>>? sort,
|
List<SortOption>? sort,
|
||||||
bool state = true,
|
bool state = true,
|
||||||
bool watch = true,
|
bool watch = true,
|
||||||
bool presence = false,
|
bool presence = false,
|
||||||
@@ -672,12 +677,17 @@ class StreamChatClient {
|
|||||||
/// Requests channels with a given query from the Persistence client.
|
/// Requests channels with a given query from the Persistence client.
|
||||||
Future<List<Channel>> queryChannelsOffline({
|
Future<List<Channel>> queryChannelsOffline({
|
||||||
Filter? filter,
|
Filter? filter,
|
||||||
List<SortOption<ChannelModel>>? sort,
|
@Deprecated('''
|
||||||
|
sort has been deprecated.
|
||||||
|
Please use channelStateSort instead.''') List<SortOption<ChannelModel>>? sort,
|
||||||
|
List<SortOption<ChannelState>>? channelStateSort,
|
||||||
PaginationParams paginationParams = const PaginationParams(),
|
PaginationParams paginationParams = const PaginationParams(),
|
||||||
}) async {
|
}) async {
|
||||||
final offlineChannels = (await _chatPersistenceClient?.getChannelStates(
|
final offlineChannels = (await _chatPersistenceClient?.getChannelStates(
|
||||||
filter: filter,
|
filter: filter,
|
||||||
|
// ignore: deprecated_member_use_from_same_package
|
||||||
sort: sort,
|
sort: sort,
|
||||||
|
channelStateSort: channelStateSort,
|
||||||
paginationParams: paginationParams,
|
paginationParams: paginationParams,
|
||||||
)) ??
|
)) ??
|
||||||
[];
|
[];
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import 'dart:convert';
|
|||||||
import 'package:stream_chat/src/core/api/requests.dart';
|
import 'package:stream_chat/src/core/api/requests.dart';
|
||||||
import 'package:stream_chat/src/core/api/responses.dart';
|
import 'package:stream_chat/src/core/api/responses.dart';
|
||||||
import 'package:stream_chat/src/core/http/stream_http_client.dart';
|
import 'package:stream_chat/src/core/http/stream_http_client.dart';
|
||||||
import 'package:stream_chat/src/core/models/channel_model.dart';
|
|
||||||
import 'package:stream_chat/src/core/models/channel_state.dart';
|
import 'package:stream_chat/src/core/models/channel_state.dart';
|
||||||
import 'package:stream_chat/src/core/models/event.dart';
|
import 'package:stream_chat/src/core/models/event.dart';
|
||||||
import 'package:stream_chat/src/core/models/filter.dart';
|
import 'package:stream_chat/src/core/models/filter.dart';
|
||||||
@@ -51,7 +50,7 @@ class ChannelApi {
|
|||||||
/// Requests channels with a given query from the API.
|
/// Requests channels with a given query from the API.
|
||||||
Future<QueryChannelsResponse> queryChannels({
|
Future<QueryChannelsResponse> queryChannels({
|
||||||
Filter? filter,
|
Filter? filter,
|
||||||
List<SortOption<ChannelModel>>? sort,
|
List<SortOption>? sort,
|
||||||
int? memberLimit,
|
int? memberLimit,
|
||||||
int? messageLimit,
|
int? messageLimit,
|
||||||
bool state = true,
|
bool state = true,
|
||||||
|
|||||||
@@ -94,7 +94,10 @@ abstract class ChatPersistenceClient {
|
|||||||
/// for filtering out states.
|
/// for filtering out states.
|
||||||
Future<List<ChannelState>> getChannelStates({
|
Future<List<ChannelState>> getChannelStates({
|
||||||
Filter? filter,
|
Filter? filter,
|
||||||
List<SortOption<ChannelModel>>? sort,
|
@Deprecated('''
|
||||||
|
sort has been deprecated.
|
||||||
|
Please use channelStateSort instead.''') List<SortOption<ChannelModel>>? sort,
|
||||||
|
List<SortOption<ChannelState>>? channelStateSort,
|
||||||
PaginationParams? paginationParams,
|
PaginationParams? paginationParams,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -618,7 +618,7 @@ void main() {
|
|||||||
|
|
||||||
when(() => persistence.getChannelStates(
|
when(() => persistence.getChannelStates(
|
||||||
filter: any(named: 'filter'),
|
filter: any(named: 'filter'),
|
||||||
sort: any(named: 'sort'),
|
channelStateSort: any(named: 'channelStateSort'),
|
||||||
paginationParams: any(named: 'paginationParams'),
|
paginationParams: any(named: 'paginationParams'),
|
||||||
)).thenAnswer((_) async => persistentChannelStates);
|
)).thenAnswer((_) async => persistentChannelStates);
|
||||||
|
|
||||||
@@ -674,7 +674,7 @@ void main() {
|
|||||||
|
|
||||||
verify(() => persistence.getChannelStates(
|
verify(() => persistence.getChannelStates(
|
||||||
filter: any(named: 'filter'),
|
filter: any(named: 'filter'),
|
||||||
sort: any(named: 'sort'),
|
channelStateSort: any(named: 'channelStateSort'),
|
||||||
paginationParams: any(named: 'paginationParams'),
|
paginationParams: any(named: 'paginationParams'),
|
||||||
)).called(1);
|
)).called(1);
|
||||||
|
|
||||||
@@ -715,7 +715,7 @@ void main() {
|
|||||||
|
|
||||||
when(() => persistence.getChannelStates(
|
when(() => persistence.getChannelStates(
|
||||||
filter: any(named: 'filter'),
|
filter: any(named: 'filter'),
|
||||||
sort: any(named: 'sort'),
|
channelStateSort: any(named: 'channelStateSort'),
|
||||||
paginationParams: any(named: 'paginationParams'),
|
paginationParams: any(named: 'paginationParams'),
|
||||||
)).thenAnswer((_) async => persistentChannelStates);
|
)).thenAnswer((_) async => persistentChannelStates);
|
||||||
|
|
||||||
@@ -757,7 +757,7 @@ void main() {
|
|||||||
|
|
||||||
verify(() => persistence.getChannelStates(
|
verify(() => persistence.getChannelStates(
|
||||||
filter: any(named: 'filter'),
|
filter: any(named: 'filter'),
|
||||||
sort: any(named: 'sort'),
|
channelStateSort: any(named: 'channelStateSort'),
|
||||||
paginationParams: any(named: 'paginationParams'),
|
paginationParams: any(named: 'paginationParams'),
|
||||||
)).called(1);
|
)).called(1);
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,10 @@ class TestPersistenceClient extends ChatPersistenceClient {
|
|||||||
@override
|
@override
|
||||||
Future<List<ChannelState>> getChannelStates(
|
Future<List<ChannelState>> getChannelStates(
|
||||||
{Filter? filter,
|
{Filter? filter,
|
||||||
List<SortOption<ChannelModel>>? sort,
|
@Deprecated('''
|
||||||
|
sort has been deprecated.
|
||||||
|
Please use channelStateSort instead.''') List<SortOption<ChannelModel>>? sort,
|
||||||
|
List<SortOption<ChannelState>>? channelStateSort,
|
||||||
PaginationParams? paginationParams}) =>
|
PaginationParams? paginationParams}) =>
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
|
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
|
|||||||
'members',
|
'members',
|
||||||
[StreamChat.of(context).currentUser!.id],
|
[StreamChat.of(context).currentUser!.id],
|
||||||
),
|
),
|
||||||
sort: const [SortOption('last_message_at')],
|
channelStateSort: const [SortOption('last_message_at')],
|
||||||
limit: 20,
|
limit: 20,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
|
|||||||
'members',
|
'members',
|
||||||
[StreamChat.of(context).currentUser!.id],
|
[StreamChat.of(context).currentUser!.id],
|
||||||
),
|
),
|
||||||
sort: const [SortOption('last_message_at')],
|
channelStateSort: const [SortOption('last_message_at')],
|
||||||
limit: 20,
|
limit: 20,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
|
|||||||
'members',
|
'members',
|
||||||
[StreamChat.of(context).currentUser!.id],
|
[StreamChat.of(context).currentUser!.id],
|
||||||
),
|
),
|
||||||
sort: const [SortOption('last_message_at')],
|
channelStateSort: const [SortOption('last_message_at')],
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
|
|||||||
'members',
|
'members',
|
||||||
[StreamChat.of(context).currentUser!.id],
|
[StreamChat.of(context).currentUser!.id],
|
||||||
),
|
),
|
||||||
sort: const [SortOption('last_message_at')],
|
channelStateSort: const [SortOption('last_message_at')],
|
||||||
limit: 20,
|
limit: 20,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
|
|||||||
'members',
|
'members',
|
||||||
[StreamChat.of(context).currentUser!.id],
|
[StreamChat.of(context).currentUser!.id],
|
||||||
),
|
),
|
||||||
sort: const [SortOption('last_message_at')],
|
channelStateSort: const [SortOption('last_message_at')],
|
||||||
limit: 20,
|
limit: 20,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
|
|||||||
'members',
|
'members',
|
||||||
[StreamChat.of(context).currentUser!.id],
|
[StreamChat.of(context).currentUser!.id],
|
||||||
),
|
),
|
||||||
sort: const [SortOption('last_message_at')],
|
channelStateSort: const [SortOption('last_message_at')],
|
||||||
limit: 20,
|
limit: 20,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ class _ChannelListPageState extends State<ChannelListPage> {
|
|||||||
'members',
|
'members',
|
||||||
[StreamChat.of(context).currentUser!.id],
|
[StreamChat.of(context).currentUser!.id],
|
||||||
),
|
),
|
||||||
sort: const [SortOption('last_message_at')],
|
channelStateSort: const [SortOption('last_message_at')],
|
||||||
limit: 20,
|
limit: 20,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
## Upcoming
|
||||||
|
|
||||||
|
- Deprecated the `sort` parameter in the `StreamChannelListController` in favor of `channelStateSort`.
|
||||||
|
|
||||||
## 5.0.0
|
## 5.0.0
|
||||||
|
|
||||||
- Included the changes from version [4.5.0](#450).
|
- Included the changes from version [4.5.0](#450).
|
||||||
|
|||||||
@@ -45,7 +45,10 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
required this.client,
|
required this.client,
|
||||||
StreamChannelListEventHandler? eventHandler,
|
StreamChannelListEventHandler? eventHandler,
|
||||||
this.filter,
|
this.filter,
|
||||||
this.sort,
|
@Deprecated('''
|
||||||
|
sort has been deprecated.
|
||||||
|
Please use channelStateSort instead.''') this.sort,
|
||||||
|
this.channelStateSort,
|
||||||
this.presence = true,
|
this.presence = true,
|
||||||
this.limit = defaultChannelPagedLimit,
|
this.limit = defaultChannelPagedLimit,
|
||||||
this.messageLimit,
|
this.messageLimit,
|
||||||
@@ -59,7 +62,10 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
required this.client,
|
required this.client,
|
||||||
StreamChannelListEventHandler? eventHandler,
|
StreamChannelListEventHandler? eventHandler,
|
||||||
this.filter,
|
this.filter,
|
||||||
this.sort,
|
this.channelStateSort,
|
||||||
|
@Deprecated('''
|
||||||
|
sort has been deprecated.
|
||||||
|
Please use channelStateSort instead.''') this.sort,
|
||||||
this.presence = true,
|
this.presence = true,
|
||||||
this.limit = defaultChannelPagedLimit,
|
this.limit = defaultChannelPagedLimit,
|
||||||
this.messageLimit,
|
this.messageLimit,
|
||||||
@@ -88,8 +94,22 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
/// created_at or member_count.
|
/// created_at or member_count.
|
||||||
///
|
///
|
||||||
/// Direction can be ascending or descending.
|
/// Direction can be ascending or descending.
|
||||||
|
@Deprecated('''
|
||||||
|
sort has been deprecated.
|
||||||
|
Please use channelStateSort instead.''')
|
||||||
final List<SortOption<ChannelModel>>? sort;
|
final List<SortOption<ChannelModel>>? sort;
|
||||||
|
|
||||||
|
/// The sorting used for the channels matching the filters.
|
||||||
|
///
|
||||||
|
/// Sorting is based on field and direction, multiple sorting options
|
||||||
|
/// can be provided.
|
||||||
|
///
|
||||||
|
/// You can sort based on last_updated, last_message_at, updated_at,
|
||||||
|
/// created_at or member_count.
|
||||||
|
///
|
||||||
|
/// Direction can be ascending or descending.
|
||||||
|
final List<SortOption<ChannelState>>? channelStateSort;
|
||||||
|
|
||||||
/// If true you’ll receive user presence updates via the websocket events
|
/// If true you’ll receive user presence updates via the websocket events
|
||||||
final bool presence;
|
final bool presence;
|
||||||
|
|
||||||
@@ -112,6 +132,8 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
try {
|
try {
|
||||||
await for (final channels in client.queryChannels(
|
await for (final channels in client.queryChannels(
|
||||||
filter: filter,
|
filter: filter,
|
||||||
|
channelStateSort: channelStateSort,
|
||||||
|
// ignore: deprecated_member_use, deprecated_member_use_from_same_package
|
||||||
sort: sort,
|
sort: sort,
|
||||||
memberLimit: memberLimit,
|
memberLimit: memberLimit,
|
||||||
messageLimit: messageLimit,
|
messageLimit: messageLimit,
|
||||||
@@ -141,7 +163,9 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
|
|||||||
try {
|
try {
|
||||||
await for (final channels in client.queryChannels(
|
await for (final channels in client.queryChannels(
|
||||||
filter: filter,
|
filter: filter,
|
||||||
|
// ignore: deprecated_member_use, deprecated_member_use_from_same_package
|
||||||
sort: sort,
|
sort: sort,
|
||||||
|
channelStateSort: channelStateSort,
|
||||||
memberLimit: memberLimit,
|
memberLimit: memberLimit,
|
||||||
messageLimit: messageLimit,
|
messageLimit: messageLimit,
|
||||||
presence: presence,
|
presence: presence,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
## Upcoming
|
## Upcoming
|
||||||
|
|
||||||
- Reintroduce support for experimental indexedDB on Web.
|
- Reintroduce support for experimental indexedDB on Web.
|
||||||
|
- Deprecated the `sort` parameter in the getChannelStates method in favor of `channelStateSort`.
|
||||||
|
- Use the comparator function to sort the channel states and not the channel models.
|
||||||
|
|
||||||
🐞 Fixed
|
🐞 Fixed
|
||||||
|
|
||||||
|
|||||||
@@ -263,19 +263,76 @@ class StreamChatPersistenceClient extends ChatPersistenceClient {
|
|||||||
@override
|
@override
|
||||||
Future<List<ChannelState>> getChannelStates({
|
Future<List<ChannelState>> getChannelStates({
|
||||||
Filter? filter,
|
Filter? filter,
|
||||||
List<SortOption<ChannelModel>>? sort,
|
@Deprecated('''
|
||||||
|
sort has been deprecated.
|
||||||
|
Please use channelStateSort instead.''') List<SortOption<ChannelModel>>? sort,
|
||||||
|
List<SortOption<ChannelState>>? channelStateSort,
|
||||||
PaginationParams? paginationParams,
|
PaginationParams? paginationParams,
|
||||||
}) {
|
}) {
|
||||||
assert(_debugIsConnected, '');
|
assert(_debugIsConnected, '');
|
||||||
|
assert(
|
||||||
|
sort == null || channelStateSort == null,
|
||||||
|
'sort and channelStateSort cannot be used together',
|
||||||
|
);
|
||||||
_logger.info('getChannelStates');
|
_logger.info('getChannelStates');
|
||||||
return _readProtected(
|
return _readProtected(
|
||||||
() async {
|
() async {
|
||||||
final channels = await db!.channelQueryDao.getChannels(
|
final channels = await db!.channelQueryDao.getChannels(
|
||||||
filter: filter,
|
filter: filter,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
paginationParams: paginationParams,
|
|
||||||
);
|
);
|
||||||
return Future.wait(channels.map((e) => getChannelStateByCid(e.cid)));
|
|
||||||
|
final channelStates = await Future.wait(
|
||||||
|
channels.map((e) => getChannelStateByCid(e.cid)),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Only sort the channel states if the channels are not already sorted.
|
||||||
|
if (sort == null) {
|
||||||
|
var chainedComparator = (ChannelState a, ChannelState b) {
|
||||||
|
final dateA = a.channel?.lastMessageAt ?? a.channel?.createdAt;
|
||||||
|
final dateB = b.channel?.lastMessageAt ?? b.channel?.createdAt;
|
||||||
|
|
||||||
|
if (dateA == null && dateB == null) {
|
||||||
|
return 0;
|
||||||
|
} else if (dateA == null) {
|
||||||
|
return 1;
|
||||||
|
} else if (dateB == null) {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return dateB.compareTo(dateA);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (channelStateSort != null && channelStateSort.isNotEmpty) {
|
||||||
|
chainedComparator = (a, b) {
|
||||||
|
int result;
|
||||||
|
for (final comparator in channelStateSort
|
||||||
|
.map((it) => it.comparator)
|
||||||
|
.withNullifyer) {
|
||||||
|
try {
|
||||||
|
result = comparator(a, b);
|
||||||
|
} catch (e) {
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
if (result != 0) return result;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
channelStates.sort(chainedComparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
final offset = paginationParams?.offset;
|
||||||
|
if (offset != null && offset > 0 && channelStates.isNotEmpty) {
|
||||||
|
channelStates.removeRange(0, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (paginationParams?.limit != null) {
|
||||||
|
return channelStates.take(paginationParams!.limit).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return channelStates;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,27 +137,6 @@ 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
|
|
||||||
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 {
|
test('should return sorted channels using member count', () async {
|
||||||
int sortComparator(ChannelModel a, ChannelModel b) =>
|
int sortComparator(ChannelModel a, ChannelModel b) =>
|
||||||
b.memberCount.compareTo(a.memberCount);
|
b.memberCount.compareTo(a.memberCount);
|
||||||
@@ -169,6 +148,7 @@ void main() {
|
|||||||
// Should match with the inserted channels
|
// Should match with the inserted channels
|
||||||
final updatedChannels = await channelQueryDao.getChannels(
|
final updatedChannels = await channelQueryDao.getChannels(
|
||||||
filter: filter,
|
filter: filter,
|
||||||
|
// ignore: deprecated_member_use_from_same_package
|
||||||
sort: [
|
sort: [
|
||||||
SortOption(
|
SortOption(
|
||||||
'member_count',
|
'member_count',
|
||||||
@@ -202,15 +182,6 @@ void main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should throw if comparator is not provided in sort list', () {
|
|
||||||
expect(
|
|
||||||
() => channelQueryDao.getChannels(
|
|
||||||
sort: [const SortOption('test_custom_field')],
|
|
||||||
),
|
|
||||||
throwsArgumentError,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should return sorted channels using custom field', () async {
|
test('should return sorted channels using custom field', () async {
|
||||||
int sortComparator(ChannelModel a, ChannelModel b) {
|
int sortComparator(ChannelModel a, ChannelModel b) {
|
||||||
final aData = int.parse(a.extraData['test_custom_field'].toString());
|
final aData = int.parse(a.extraData['test_custom_field'].toString());
|
||||||
@@ -225,6 +196,7 @@ void main() {
|
|||||||
// Should match with the inserted channels
|
// Should match with the inserted channels
|
||||||
final updatedChannels = await channelQueryDao.getChannels(
|
final updatedChannels = await channelQueryDao.getChannels(
|
||||||
filter: filter,
|
filter: filter,
|
||||||
|
// ignore: deprecated_member_use_from_same_package
|
||||||
sort: [SortOption('test_custom_field', comparator: sortComparator)],
|
sort: [SortOption('test_custom_field', comparator: sortComparator)],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user