68 lines
2.0 KiB
Dart
68 lines
2.0 KiB
Dart
// Author: fruit.com.cn
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:fruitshorts/core/data/models/interaction.dart';
|
|
import 'package:fruitshorts/core/data/remote/api_client.dart';
|
|
import 'package:fruitshorts/core/data/remote/interaction_api.dart';
|
|
|
|
import '../support/fake_http_adapter.dart';
|
|
|
|
void main() {
|
|
String envelope(Object? data) =>
|
|
jsonEncode({'code': 0, 'message': 'ok', 'data': data});
|
|
|
|
test('should_send_like_target_and_parse_string_count_when_toggled', () async {
|
|
final adapter = FakeHttpAdapter(
|
|
(_) async => FakeHttpResponse(
|
|
envelope({'liked': true, 'count': '2111012753262120962'}),
|
|
),
|
|
);
|
|
final api = InteractionApi(
|
|
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
|
);
|
|
|
|
final result = await api.toggleLike(
|
|
targetType: InteractionTargetType.drama,
|
|
targetId: '5',
|
|
);
|
|
|
|
expect(adapter.requests.single.method, 'POST');
|
|
expect(adapter.requests.single.uri.path, '/app/likes/toggle');
|
|
expect(adapter.requests.single.data, {
|
|
'targetType': 'DRAMA',
|
|
'targetId': '5',
|
|
});
|
|
expect(result.liked, isTrue);
|
|
expect(result.count, 2111012753262120962);
|
|
});
|
|
|
|
test('should_submit_fixed_reason_code_and_optional_description_when_reporting', () async {
|
|
final adapter = FakeHttpAdapter(
|
|
(_) async => FakeHttpResponse(envelope('2111012753262120999')),
|
|
);
|
|
final api = InteractionApi(
|
|
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
|
);
|
|
|
|
final reportId = await api.report(
|
|
const ReportRequest(
|
|
targetType: InteractionTargetType.comment,
|
|
targetId: '7',
|
|
reasonCode: 'SPAM',
|
|
description: 'Repeated advertising',
|
|
),
|
|
);
|
|
|
|
expect(adapter.requests.single.uri.path, '/app/reports');
|
|
expect(adapter.requests.single.data, {
|
|
'targetType': 'COMMENT',
|
|
'targetId': '7',
|
|
'reasonCode': 'SPAM',
|
|
'description': 'Repeated advertising',
|
|
});
|
|
expect(reportId, '2111012753262120999');
|
|
});
|
|
}
|