// Author: fruit.com.cn import 'package:flutter_test/flutter_test.dart'; import 'package:fruitshorts/core/data/remote/api_client.dart'; import 'package:fruitshorts/core/data/remote/auth_api.dart'; /// 联调测试:直连本机客户端接口服务(8081)验证 **POST + JSON body + 错误码映射**。 /// /// 特意用"不存在的邮箱"登录:既能走完整的 POST 链路,又不会在库里留下测试数据。 /// 服务没启动时自动跳过,不影响日常 `flutter test`。 void main() { final client = ApiClient(baseUrl: 'http://127.0.0.1:8081'); final api = AuthApi(client); tearDownAll(client.close); test('should_surface_business_error_when_sign_in_uses_unknown_email', () async { try { await api.login( email: 'no-such-user-for-dio-check@example.com', password: 'abcd1234', deviceId: 'dio-check-device', ); fail('不存在的邮箱不应该登录成功'); } on ApiException catch (error) { // 关键点:错误码来自响应体(不是 HTTP 状态码),说明统一解包生效 expect(error.code, isNot(0)); expect(error.message, isNotEmpty); } catch (_) { markTestSkipped('客户端接口服务未启动,已跳过联调测试'); } }); }