platform/test/bounds_test.dart

58 lines
1.6 KiB
Dart
Raw Normal View History

2019-02-01 14:39:10 +00:00
import 'dart:convert';
2017-05-28 18:22:57 +00:00
import 'package:angel_framework/angel_framework.dart';
2019-02-01 14:39:10 +00:00
import 'package:angel_paginate/angel_paginate.dart';
2017-05-28 18:22:57 +00:00
import 'package:angel_test/angel_test.dart';
2019-02-01 14:39:10 +00:00
import 'package:logging/logging.dart';
2017-05-28 18:22:57 +00:00
import 'package:test/test.dart';
2019-02-01 14:39:10 +00:00
final List<Map<String, String>> mjAlbums = [
2017-05-28 18:22:57 +00:00
{'billie': 'jean'},
{'off': 'the_wall'},
{'michael': 'jackson'}
];
main() {
TestClient client;
setUp(() async {
2019-02-01 14:39:10 +00:00
var app = new Angel();
app.get('/api/songs', (req, res) {
var p = Paginator(mjAlbums, itemsPerPage: mjAlbums.length);
p.goToPage(int.parse(req.queryParameters['page'] ?? '1'));
return p.current;
});
2017-05-28 18:22:57 +00:00
client = await connectTo(app);
2019-02-01 14:39:10 +00:00
app.logger = Logger('angel_paginate')
..onRecord.listen((rec) {
print(rec);
if (rec.error != null) print(rec.error);
if (rec.stackTrace != null) print(rec.stackTrace);
});
2017-05-28 18:22:57 +00:00
});
tearDown(() => client.close());
test('limit exceeds size of collection', () async {
2019-02-01 14:39:10 +00:00
var response = await client.get(Uri(
path: '/api/songs',
queryParameters: {r'$limit': (mjAlbums.length + 1).toString()}));
var page = new PaginationResult<Map<String, dynamic>>.fromMap(
json.decode(response.body));
2017-05-28 18:22:57 +00:00
print('page: ${page.toJson()}');
2019-02-01 14:39:10 +00:00
expect(page.total, mjAlbums.length);
expect(page.itemsPerPage, mjAlbums.length);
2017-05-28 18:22:57 +00:00
expect(page.previousPage, -1);
expect(page.currentPage, 1);
expect(page.nextPage, -1);
expect(page.startIndex, 0);
2019-02-01 14:39:10 +00:00
expect(page.endIndex, mjAlbums.length - 1);
expect(page.data, mjAlbums);
2017-05-28 18:22:57 +00:00
});
}