为什么:a) 应用对外名称要统一成 FruitShorts(产品名,nontonki 是原型代号); b) 首发市场是印尼,界面必须有印尼语;c) 归档要求"新增 id-ID 与改名合并生成一次 l10n,别分两次"。 改名: - pubspec name: nontonki → fruitshorts(Dart 包名),description 同步;28 个文件的 package: 导入前缀替换 - Android android:label、iOS CFBundleDisplayName/CFBundleName → FruitShorts - 图标资源 assets/icon/nontonki.png → fruitshorts.png(含 pubspec 两处引用) - README 同步(补印尼语说明,顺带修掉写错的模块名 reelshort-app-api → fruitshorts-app-api) 文案: - 三份 arb 的 appName → FruitShorts、brandMark → FRUITSHORTS、shareFooter → FruitShorts(不留 demo 标记) - 新增 lib/l10n/app_id.arb:174 个值键与 en/zh 完全一致,按印尼语习惯翻译(Coin→Koin、Episode→Episode) - 一次性 flutter gen-l10n 生成 app_localizations_id.dart;id 自动进入 supportedLocales,默认 locale 未改 - 新增 test/config/l10n_id_test.dart:钉住 id 文案、supportedLocales 含 id、品牌文案无 demo 标记、占位符渲染 不动:applicationId / bundle id(lumadrama 遗留,等裁定)、目录名、业务逻辑与页面结构、语言选择页(仍只有 en/zh) 门禁:dart analyze lib test 零告警;flutter test 159 全过(基线 155 + 新增 4);残留扫描 0 命中; 三份 arb 键集一致(174/174/174);真机(iPhone iOS 26.6.1)构建安装启动成功,devicectl 列出显示名 FruitShorts
108 lines
3.7 KiB
Dart
108 lines
3.7 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 '../support/fake_http_adapter.dart';
|
|
|
|
/// 网络层换 dio 之后,把「对外契约」逐条钉住:解包、错误码映射、请求头、查询参数、跳过重试。
|
|
void main() {
|
|
String envelope(Object? data, {int code = 0, String message = 'ok'}) {
|
|
return jsonEncode({'code': code, 'message': message, 'data': data});
|
|
}
|
|
|
|
test('should_return_data_field_when_envelope_code_is_zero', () async {
|
|
final adapter = FakeHttpAdapter(
|
|
(_) async => FakeHttpResponse(envelope({'id': 7})),
|
|
);
|
|
final client = ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter);
|
|
|
|
final data = await client.get('/app/dramas/7');
|
|
expect((data as Map)['id'], 7);
|
|
});
|
|
|
|
test('should_throw_api_exception_with_server_message_when_envelope_code_is_not_zero', () async {
|
|
final adapter = FakeHttpAdapter(
|
|
(_) async => FakeHttpResponse(
|
|
envelope(null, code: 40001, message: '邮箱格式不正确'),
|
|
),
|
|
);
|
|
final client = ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter);
|
|
|
|
await expectLater(
|
|
client.post('/app/auth/register', body: {'target': 'bad'}),
|
|
throwsA(
|
|
isA<ApiException>()
|
|
.having((e) => e.code, 'code', 40001)
|
|
.having((e) => e.message, 'message', '邮箱格式不正确'),
|
|
),
|
|
);
|
|
});
|
|
|
|
test('should_map_to_api_exception_with_http_status_when_body_has_no_envelope', () async {
|
|
final adapter = FakeHttpAdapter((_) async => FakeHttpResponse('oops', 502));
|
|
final client = ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter);
|
|
|
|
await expectLater(
|
|
client.get('/app/home/feed'),
|
|
throwsA(
|
|
isA<ApiException>().having((e) => e.code, 'code', 502),
|
|
),
|
|
);
|
|
});
|
|
|
|
test('should_send_bearer_token_and_device_header_when_both_are_available', () async {
|
|
final adapter = FakeHttpAdapter((_) async => FakeHttpResponse(envelope(null)));
|
|
final client = ApiClient(
|
|
baseUrl: 'http://127.0.0.1:8081',
|
|
adapter: adapter,
|
|
accessTokenReader: () => 'token-1',
|
|
deviceIdReader: () async => 'device-9',
|
|
);
|
|
|
|
await client.get('/app/me');
|
|
|
|
final request = adapter.requests.single;
|
|
expect(request.headers['Authorization'], 'Bearer token-1');
|
|
expect(request.headers['X-Device-Id'], 'device-9');
|
|
expect(request.headers['Accept'], 'application/json');
|
|
});
|
|
|
|
test('should_put_query_map_into_request_uri_when_query_is_given', () async {
|
|
final adapter = FakeHttpAdapter((_) async => FakeHttpResponse(envelope(null)));
|
|
final client = ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter);
|
|
|
|
await client.get('/app/search', query: {'keyword': '短剧', 'page': '2'});
|
|
|
|
final uri = adapter.requests.single.uri;
|
|
expect(uri.path, '/app/search');
|
|
expect(uri.queryParameters['keyword'], '短剧');
|
|
expect(uri.queryParameters['page'], '2');
|
|
});
|
|
|
|
test('should_skip_refresh_when_call_opts_out_of_auth_retry', () async {
|
|
var refreshed = false;
|
|
final adapter = FakeHttpAdapter(
|
|
(_) async => FakeHttpResponse(envelope(null, code: 401, message: '登录已过期')),
|
|
);
|
|
final client = ApiClient(
|
|
baseUrl: 'http://127.0.0.1:8081',
|
|
adapter: adapter,
|
|
tokenRefresher: () async {
|
|
refreshed = true;
|
|
return true;
|
|
},
|
|
);
|
|
|
|
await expectLater(
|
|
client.post('/app/auth/refresh', body: {'refreshToken': 'r1'}, skipAuthRetry: true),
|
|
throwsA(isA<ApiException>().having((e) => e.code, 'code', 401)),
|
|
);
|
|
expect(refreshed, isFalse);
|
|
expect(adapter.requests, hasLength(1));
|
|
});
|
|
}
|