84 lines
2.4 KiB
Dart
84 lines
2.4 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:pj_supermarket_cloud/common/index.dart';
|
|
|
|
/// 验证部门人脸同步默认调度、V3 契约、MQ 专用模型和脱敏结果摘要。
|
|
void main() {
|
|
test('本部门人脸同步默认每天零点四十分且仅空闲执行', () {
|
|
final config = SyncCheckTool.defaultConfigs.singleWhere(
|
|
(item) => item.type == ScheduledTaskType.departmentFaceSync,
|
|
);
|
|
|
|
expect(config.enabled, isTrue);
|
|
expect(config.cron, '0 40 0 * * *');
|
|
expect(config.idleOnly, isTrue);
|
|
});
|
|
|
|
test('V3 快照兼容数字和字符串标识', () {
|
|
final snapshot = ServiceFaceSyncSnapshot.fromJson(const {
|
|
'records': [
|
|
{
|
|
'id': 101,
|
|
'sampleId': '202',
|
|
'userId': 303,
|
|
'username': '测试用户',
|
|
'deptId': '404',
|
|
'deptName': '测试部门',
|
|
'faceImg': '/face/test.jpg',
|
|
'sourceUpdatedAt': '2026-08-17T00:40:00',
|
|
},
|
|
],
|
|
'nextAfterId': 101,
|
|
'hasMore': false,
|
|
'snapshotMaxId': '101',
|
|
});
|
|
|
|
expect(snapshot.records.single.id, '101');
|
|
expect(snapshot.records.single.sampleId, '202');
|
|
expect(snapshot.records.single.userId, '303');
|
|
expect(snapshot.records.single.deptId, '404');
|
|
expect(snapshot.nextAfterId, '101');
|
|
expect(snapshot.snapshotMaxId, '101');
|
|
});
|
|
|
|
test('V3 快照缺少必填标识时在反序列化边界失败', () {
|
|
expect(
|
|
() => ServiceFaceSyncRecord.fromJson(const {
|
|
'id': null,
|
|
'sampleId': 2,
|
|
'userId': 3,
|
|
'deptId': 4,
|
|
}),
|
|
throwsA(isA<FormatException>()),
|
|
);
|
|
});
|
|
|
|
test('FACE 消息使用专用模型兼容数字用户标识', () {
|
|
final message = MqttFaceChangeMsg.fromJson(const {
|
|
'action': 'FACE',
|
|
'userId': 9527,
|
|
});
|
|
|
|
expect(message.action, MqtActionEnum.FACE);
|
|
expect(message.userId, '9527');
|
|
});
|
|
|
|
test('部分失败汇总只包含脱敏样本标识', () {
|
|
const summary = FaceSyncSummary(
|
|
mode: FaceSyncMode.departmentSnapshot,
|
|
scanned: 100,
|
|
added: 98,
|
|
updated: 1,
|
|
deleted: 0,
|
|
skipped: 0,
|
|
failed: 1,
|
|
maskedFailedSampleIds: ['1***003'],
|
|
);
|
|
|
|
expect(summary.hasFailures, isTrue);
|
|
expect(summary.changed, 99);
|
|
expect(summary.message, contains('失败 1'));
|
|
expect(summary.message, contains('1***003'));
|
|
});
|
|
}
|