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.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sepot/core/services/messaging_service.dart';
|
||||
|
||||
/// Čas zprávy musí pocházet od odesílatele, ne z okamžiku doručení.
|
||||
/// Regrese: bez `ts` na drátě dostal každý příjemce vlastní `DateTime.now()`,
|
||||
/// takže po vyzvednutí offline fronty uskočila celá konverzace na „teď"
|
||||
/// a každý člen skupiny viděl u téže zprávy jiný čas.
|
||||
void main() {
|
||||
test('čas odesílatele z drátu se použije beze změny', () {
|
||||
final odeslano = DateTime(2026, 8, 10, 14, 30);
|
||||
final t = MessagingService.wireSentAt(odeslano.millisecondsSinceEpoch);
|
||||
expect(t, odeslano);
|
||||
});
|
||||
|
||||
test('starý klient bez ts → fallback na čas doručení', () {
|
||||
final pred = DateTime.now();
|
||||
final t = MessagingService.wireSentAt(null);
|
||||
expect(t.isBefore(pred.subtract(const Duration(seconds: 5))), isFalse);
|
||||
});
|
||||
|
||||
test('netypové ts (string z drátu) → fallback, nespadne', () {
|
||||
final pred = DateTime.now();
|
||||
final t = MessagingService.wireSentAt('2026-08-10T14:30:00Z');
|
||||
expect(t.isBefore(pred.subtract(const Duration(seconds: 5))), isFalse);
|
||||
});
|
||||
|
||||
test('rozejité hodiny v toleranci se přijmou', () {
|
||||
// Přes drát jde epocha v ms, takže mikrosekundy z DateTime.now() padnou
|
||||
// pod stůl — porovnáváme na milisekundy, ne na identitu objektu.
|
||||
final skoroTed = DateTime.now().add(const Duration(minutes: 3));
|
||||
final t = MessagingService.wireSentAt(skoroTed.millisecondsSinceEpoch);
|
||||
expect(t.millisecondsSinceEpoch, skoroTed.millisecondsSinceEpoch);
|
||||
});
|
||||
|
||||
test('čas z budoucnosti nad strop → čas doručení', () {
|
||||
final budoucnost = DateTime.now().add(const Duration(days: 365));
|
||||
final t = MessagingService.wireSentAt(budoucnost.millisecondsSinceEpoch);
|
||||
expect(t.isBefore(budoucnost), isTrue);
|
||||
});
|
||||
|
||||
test('absurdně starý čas → čas doručení', () {
|
||||
final t = MessagingService.wireSentAt(
|
||||
DateTime(1999).millisecondsSinceEpoch,
|
||||
);
|
||||
expect(t.year, greaterThan(2020));
|
||||
});
|
||||
|
||||
test('pořadí zpráv drží čas odeslání, ne pořadí doručení', () {
|
||||
// Fronta se vylije naráz, ale starší zpráva musí zůstat starší.
|
||||
final prvni = DateTime(2026, 8, 10, 9, 0);
|
||||
final druha = DateTime(2026, 8, 10, 9, 5);
|
||||
final a = MessagingService.wireSentAt(prvni.millisecondsSinceEpoch);
|
||||
final b = MessagingService.wireSentAt(druha.millisecondsSinceEpoch);
|
||||
expect(a.isBefore(b), isTrue);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user