Files
reelbox/test/comments_removed_test.dart
T

58 lines
1.9 KiB
Dart

import 'package:dio/dio.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:reelbox/data/api_service.dart';
import 'package:reelbox/data/content_policy.dart';
import 'api_service_test.dart' as fixtures;
void main() {
test('public comments compatibility never sends a request', () async {
final adapter = fixtures.StubAdapter((_) => fixtures.jsonBody([]));
final api = ApiService(dio: Dio()..httpClientAdapter = adapter);
expect(await api.comments(7), isEmpty);
expect(adapter.requests, isEmpty);
});
test(
'raw comment paths and reply actions are blocked before transport',
() async {
final adapter = fixtures.StubAdapter((_) => fixtures.jsonBody([]));
final api = ApiService(dio: Dio()..httpClientAdapter = adapter);
for (final path in [
'comments/by/poster/7/key/',
'comment/add/',
'/api/%63omments/by/poster/7/key/',
'/api-user/newapi/comments.php',
'/api-user/filmahang/star.php?action=pasokh&cid=7',
'/api-user/newapi/comments_list.php',
'/api-user/newapi/star.php?action=comments&action=search',
]) {
expect(
ContentPolicy.allowsApiPath(Uri.parse(path)),
isFalse,
reason: path,
);
await expectLater(api.get(path), throwsA(isA<ApiException>()));
}
for (final action in ['comments', 'add-comment', 'pasokh', 'reply']) {
await expectLater(
api.get('/api-user/filmahang/star.php', query: {'action': action}),
throwsA(isA<ApiException>()),
);
await expectLater(
api.post('/api-user/filmahang/star.php', {'action': action}),
throwsA(isA<ApiException>()),
);
}
await expectLater(
api.get(
'/api-user/filmahang/star.php?action=comments',
query: {'action': 'search'},
),
throwsA(isA<ApiException>()),
);
expect(adapter.requests, isEmpty);
},
);
}