42 lines
1.7 KiB
Dart
42 lines
1.7 KiB
Dart
|
|
/// 认证域模型往返测试(P3 计划 Task 2)。
|
||
|
|
///
|
||
|
|
/// fixture 来源:openapi.yaml components.schemas.LoginResponse /
|
||
|
|
/// RefreshResponse(必返字段 sessionToken+expiresAt / expiresAt);
|
||
|
|
/// 时间形态取 auth.e2e-spec.ts 直种会话的「Date.now()+3_600_000」毫秒精度,
|
||
|
|
/// 此处用 Dart 规范形(整秒无小数)保证 toJson 往返逐字节一致,
|
||
|
|
/// 毫秒形(.000Z)解析另有冒烟断言。
|
||
|
|
library;
|
||
|
|
|
||
|
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
|
import 'package:photo_live/features/auth/models.dart';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
test('LoginResponse fromJson/toJson 往返', () {
|
||
|
|
final fixture = <String, dynamic>{
|
||
|
|
'sessionToken': 'f2a9c8b17d3e4f5a6b7c8d9e0f1a2b3c',
|
||
|
|
'expiresAt': '2026-09-19T12:30:00.000Z',
|
||
|
|
};
|
||
|
|
final model = LoginResponse.fromJson(fixture);
|
||
|
|
expect(model.sessionToken, 'f2a9c8b17d3e4f5a6b7c8d9e0f1a2b3c');
|
||
|
|
expect(model.expiresAt, DateTime.utc(2026, 9, 19, 12, 30));
|
||
|
|
expect(model.toJson(), equals(fixture));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('LoginResponse 解析毫秒精度时间(服务端 Date.toISOString 形态)', () {
|
||
|
|
final model = LoginResponse.fromJson({
|
||
|
|
'sessionToken': 't',
|
||
|
|
'expiresAt': '2026-09-19T12:30:00.500Z',
|
||
|
|
});
|
||
|
|
expect(model.expiresAt.millisecond, 500);
|
||
|
|
// toJson 规范化为 Dart ISO 输出(同值不同形,服务端 Date.parse 均可)。
|
||
|
|
expect(model.toJson()['expiresAt'], '2026-09-19T12:30:00.500Z');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('RefreshResponse fromJson/toJson 往返', () {
|
||
|
|
final fixture = <String, dynamic>{'expiresAt': '2026-09-20T08:00:00.000Z'};
|
||
|
|
final model = RefreshResponse.fromJson(fixture);
|
||
|
|
expect(model.expiresAt, DateTime.utc(2026, 9, 20, 8));
|
||
|
|
expect(model.toJson(), equals(fixture));
|
||
|
|
});
|
||
|
|
}
|