79 lines
2.1 KiB
Dart
79 lines
2.1 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fruitshorts/core/data/remote/api_client.dart';
|
|
import 'package:fruitshorts/core/data/remote/catalog_api.dart';
|
|
|
|
import '../support/fake_http_adapter.dart';
|
|
|
|
void main() {
|
|
String envelope(Object? data) =>
|
|
jsonEncode({'code': 0, 'message': 'ok', 'data': data});
|
|
|
|
test('should_send_types_and_cursor_when_feed_query_has_filters', () async {
|
|
final adapter = FakeHttpAdapter(
|
|
(_) async => FakeHttpResponse(
|
|
envelope({
|
|
'list': [
|
|
{
|
|
'id': '11',
|
|
'title': 'Anime',
|
|
'cover': '/files/anime.png',
|
|
'preview': {
|
|
'id': '12',
|
|
'number': 1,
|
|
'title': 'Episode 1',
|
|
'isFree': true,
|
|
},
|
|
},
|
|
],
|
|
'nextCursor': 10,
|
|
'hasMore': true,
|
|
}),
|
|
),
|
|
);
|
|
final api = CatalogApi(
|
|
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
|
);
|
|
|
|
final page = await api.feed(
|
|
types: const ['ANIME', 'LIVE'],
|
|
cursor: '9',
|
|
size: 20,
|
|
);
|
|
|
|
expect(adapter.requests.single.uri.path, '/app/feed');
|
|
expect(adapter.requests.single.queryParameters, {
|
|
'types': 'ANIME,LIVE',
|
|
'cursor': '9',
|
|
'size': '20',
|
|
});
|
|
expect(page.dramas.single.id, '11');
|
|
expect(page.nextCursor, '10');
|
|
expect(page.hasMore, isTrue);
|
|
});
|
|
|
|
test(
|
|
'should_omit_empty_types_and_treat_null_cursor_string_as_empty',
|
|
() async {
|
|
final adapter = FakeHttpAdapter(
|
|
(_) async => FakeHttpResponse(
|
|
envelope({'list': [], 'nextCursor': 'null', 'hasMore': false}),
|
|
),
|
|
);
|
|
final api = CatalogApi(
|
|
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
|
);
|
|
|
|
final page = await api.feed();
|
|
|
|
expect(adapter.requests.single.queryParameters, {'size': '10'});
|
|
expect(page.dramas, isEmpty);
|
|
expect(page.nextCursor, isNull);
|
|
expect(page.hasMore, isFalse);
|
|
},
|
|
);
|
|
}
|