72 lines
2.3 KiB
Dart
72 lines
2.3 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:app_upgrade_plugin/models/upgrade_info.dart';
|
|
import 'package:app_upgrade_plugin/models/app_market.dart';
|
|
|
|
void main() {
|
|
group('UpgradeInfo', () {
|
|
test('fromJson parses correct JSON', () {
|
|
final json = {
|
|
'versionBuildNumber': 20,
|
|
'versionName': '2.0.0',
|
|
'isForceUpdate': true,
|
|
'updateContent': 'New features',
|
|
'downloadUrl': 'http://example.com/app.apk',
|
|
'apkSize': 1024,
|
|
'apkMd5': 'md5hash',
|
|
'appMarkets': [
|
|
{
|
|
'market': 'googleplay',
|
|
'packageName': 'com.android.vending',
|
|
'url': 'market://details?id=com.example'
|
|
}
|
|
]
|
|
};
|
|
|
|
final info = UpgradeInfo.fromJson(
|
|
json,
|
|
currentBuildNumber: 10,
|
|
currentVersionName: '1.0.0',
|
|
);
|
|
|
|
expect(info.hasUpdate, isTrue); // 20 != 10
|
|
expect(info.isForceUpdate, isTrue);
|
|
expect(info.versionBuildNumber, 20);
|
|
expect(info.versionName, '2.0.0');
|
|
expect(info.updateContent, 'New features');
|
|
expect(info.downloadUrl, 'http://example.com/app.apk');
|
|
expect(info.apkSize, 1024);
|
|
expect(info.apkMd5, 'md5hash');
|
|
expect(info.appMarkets, isNotNull);
|
|
expect(info.appMarkets!.length, 1);
|
|
expect(info.appMarkets!.first.market, AppMarket.googlePlay);
|
|
});
|
|
|
|
test('hasUpdate logic works correctly', () {
|
|
// Case 1: Different build number
|
|
final info1 = UpgradeInfo.fromJson(
|
|
{'versionBuildNumber': 11, 'versionName': '1.0.0', 'isForceUpdate': false},
|
|
currentBuildNumber: 10,
|
|
currentVersionName: '1.0.0',
|
|
);
|
|
expect(info1.hasUpdate, isTrue);
|
|
|
|
// Case 2: Same build number, different version name
|
|
final info2 = UpgradeInfo.fromJson(
|
|
{'versionBuildNumber': 10, 'versionName': '1.0.1', 'isForceUpdate': false},
|
|
currentBuildNumber: 10,
|
|
currentVersionName: '1.0.0',
|
|
);
|
|
expect(info2.hasUpdate, isTrue);
|
|
|
|
// Case 3: Same build number and version name
|
|
final info3 = UpgradeInfo.fromJson(
|
|
{'versionBuildNumber': 10, 'versionName': '1.0.0', 'isForceUpdate': false},
|
|
currentBuildNumber: 10,
|
|
currentVersionName: '1.0.0',
|
|
);
|
|
expect(info3.hasUpdate, isFalse);
|
|
});
|
|
});
|
|
}
|
|
|