Files
sepot/app/test/app_info_test.dart
Julius Joska 79ad411d7e fix(app): read the version from the installed package
The version was a hand-written constant that had to be kept in sync with
`version:` in pubspec.yaml. It was not: the constant still said 1.1.0 while
the shipped build was 1.1.2+22, so every abuse report carried a version that
no build ever had — and reports could not be traced back to a build.

AppInfo reads versionName / CFBundleShortVersionString, which Flutter derives
from the pubspec, so the two cannot drift apart again. Reports now carry the
build number as well; when the version is not known yet the field is omitted
rather than guessed.

Also adds the timestamp regression test that covers MessagingService.wireSentAt,
which shipped in 1.1.2 without its test.
2026-09-04 10:18:37 +02:00

57 lines
1.9 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:sepot/core/app_info.dart';
/// Verzi appky nesmí nikdo psát ručně. Regrese: konstanta zůstala po releasu
/// na „1.1.0", takže všechna hlášení zneužití z produkční 1.1.2+22 byla
/// označená špatnou verzí a nešlo podle nich dohledat build.
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
PackageInfo mock({required String version, required String buildNumber}) =>
PackageInfo(
appName: 'Šepot',
packageName: 'cz.sepot.app',
version: version,
buildNumber: buildNumber,
buildSignature: '',
);
void nastavBalicek(PackageInfo info) => PackageInfo.setMockInitialValues(
appName: info.appName,
packageName: info.packageName,
version: info.version,
buildNumber: info.buildNumber,
buildSignature: info.buildSignature,
);
// Pořadí testů záleží: PackageInfo si první načtení nacachuje napořád,
// takže stav „ještě se nenačetlo" jde ověřit jen před prvním init().
test('před inicializací nepředstírá verzi', () {
expect(AppInfo.version, AppInfo.unknownVersion);
expect(AppInfo.versionWithBuild, isNull);
});
test('hlášení nese verzi včetně build čísla', () async {
nastavBalicek(mock(version: '1.1.2', buildNumber: '22'));
await AppInfo.init();
expect(AppInfo.version, '1.1.2');
expect(AppInfo.versionWithBuild, '1.1.2+22');
});
test('iOS bez CFBundleVersion nezdvojí verzi', () async {
nastavBalicek(mock(version: '1.1.2', buildNumber: '1.1.2'));
await AppInfo.init();
expect(AppInfo.versionWithBuild, '1.1.2');
});
test('prázdné build číslo → jen verze', () async {
nastavBalicek(mock(version: '2.0.0', buildNumber: ''));
await AppInfo.init();
expect(AppInfo.versionWithBuild, '2.0.0');
});
}