72 lines
2.4 KiB
Dart
72 lines
2.4 KiB
Dart
// 推广归因单测:口令解析 / 推广文案 / 我的邀请模型
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:video_app/services/invite_service.dart';
|
|
|
|
void main() {
|
|
group('parseInviteCommand', () {
|
|
test('标准口令命中', () {
|
|
expect(
|
|
InviteService.parseInviteCommand('快下载 #短视频邀请码EYPCQSPA# 一起玩'),
|
|
'EYPCQSPA',
|
|
);
|
|
});
|
|
|
|
test('整段分享文案命中', () {
|
|
final text = InviteService.buildShareText(
|
|
inviteCode: 'ABCD2345',
|
|
inviteUrl: 'https://app.example.com/r/ABCD2345',
|
|
);
|
|
expect(InviteService.parseInviteCommand(text), 'ABCD2345');
|
|
});
|
|
|
|
test('无口令 / 空文本 / 格式不符均不命中', () {
|
|
expect(InviteService.parseInviteCommand('随便一段分享文字'), isNull);
|
|
expect(InviteService.parseInviteCommand(''), isNull);
|
|
expect(InviteService.parseInviteCommand(null), isNull);
|
|
// 小写或长度不符不匹配(邀请码固定 8 位大写)
|
|
expect(InviteService.parseInviteCommand('#短视频邀请码eypcqspa#'), isNull);
|
|
expect(InviteService.parseInviteCommand('#短视频邀请码ABC#'), isNull);
|
|
});
|
|
});
|
|
|
|
group('buildShareText', () {
|
|
test('包含链接与口令', () {
|
|
final text = InviteService.buildShareText(
|
|
inviteCode: 'ABCD2345',
|
|
inviteUrl: 'https://app.example.com/r/ABCD2345',
|
|
);
|
|
expect(text, contains('https://app.example.com/r/ABCD2345'));
|
|
expect(text, contains('#短视频邀请码ABCD2345#'));
|
|
});
|
|
});
|
|
|
|
group('ReferralInfo.fromJson', () {
|
|
test('完整字段解析', () {
|
|
final info = ReferralInfo.fromJson(const {
|
|
'invite_code': 'EYPCQSPA',
|
|
'invite_url': 'https://app.example.com/r/EYPCQSPA',
|
|
'eligible': true,
|
|
'total_invitees': 12,
|
|
'activated_count': 5,
|
|
'reward_points_total': 120,
|
|
'rebate_assets_total': 66.6,
|
|
});
|
|
expect(info.inviteCode, 'EYPCQSPA');
|
|
expect(info.eligible, isTrue);
|
|
expect(info.totalInvitees, 12);
|
|
expect(info.activatedCount, 5);
|
|
expect(info.rewardPointsTotal, 120);
|
|
expect(info.rebateAssetsTotal, 66.6);
|
|
});
|
|
|
|
test('缺省兜底', () {
|
|
final info = ReferralInfo.fromJson(const {});
|
|
expect(info.inviteCode, '');
|
|
expect(info.eligible, isFalse);
|
|
expect(info.totalInvitees, 0);
|
|
expect(info.rebateAssetsTotal, 0);
|
|
});
|
|
});
|
|
}
|