88 lines
2.6 KiB
Dart
88 lines
2.6 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/commerce_api.dart';
|
|
|
|
import '../support/fake_http_adapter.dart';
|
|
|
|
void main() {
|
|
test('should_request_coin_packs_when_type_is_given', () async {
|
|
final adapter = FakeHttpAdapter(
|
|
(options) async => FakeHttpResponse(
|
|
jsonEncode({
|
|
'code': 0,
|
|
'message': 'ok',
|
|
'data': [
|
|
{
|
|
'id': '2111012753262120962',
|
|
'code': 'coin_550',
|
|
'name': '550 Coins',
|
|
'type': 'COIN_PACK',
|
|
'coinAmount': '500',
|
|
'bonusCoin': '50',
|
|
'totalCoin': '550',
|
|
'displayPrice': 'Rp 15.000',
|
|
'currency': 'IDR',
|
|
'vipDays': 0,
|
|
},
|
|
],
|
|
}),
|
|
),
|
|
);
|
|
final api = CommerceApi(
|
|
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
|
);
|
|
|
|
final products = await api.products(type: 'COIN_PACK');
|
|
|
|
final request = adapter.requests.single;
|
|
expect(request.method, 'GET');
|
|
expect(request.uri.path, '/app/products');
|
|
expect(request.queryParameters['type'], 'COIN_PACK');
|
|
expect(products.single.id, '2111012753262120962');
|
|
expect(products.single.coinAmount, 500);
|
|
expect(products.single.bonusCoin, 50);
|
|
expect(products.single.displayPrice, 'Rp 15.000');
|
|
});
|
|
|
|
test('should_post_product_id_when_creating_an_order', () async {
|
|
final adapter = FakeHttpAdapter(
|
|
(options) async => FakeHttpResponse(
|
|
jsonEncode({
|
|
'code': 0,
|
|
'message': 'ok',
|
|
'data': {
|
|
'id': '2111012753262120999',
|
|
'orderNo': 'ORD20261020001',
|
|
'productId': '2111012753262120962',
|
|
'productName': '550 Coins',
|
|
'type': 'COIN_PACK',
|
|
'coinAmount': '550',
|
|
'status': 'CREATED',
|
|
'createdAt': '2026-10-20 10:00:00',
|
|
},
|
|
}),
|
|
),
|
|
);
|
|
final api = CommerceApi(
|
|
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
|
);
|
|
|
|
final order = await api.createOrder('2111012753262120962');
|
|
|
|
final request = adapter.requests.single;
|
|
expect(request.method, 'POST');
|
|
expect(request.uri.path, '/app/orders');
|
|
final body = request.data is String
|
|
? jsonDecode(request.data as String)
|
|
: request.data;
|
|
expect(body, {'productId': '2111012753262120962'});
|
|
expect(order.orderNo, 'ORD20261020001');
|
|
expect(order.coinAmount, 550);
|
|
expect(order.status, 'CREATED');
|
|
});
|
|
}
|