Offer platform-specific updates at startup and foreground return
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/updates/app_updates.dart';
|
||||
import 'package:pipelines_app/features/updates/launch_update.dart';
|
||||
|
||||
void main() {
|
||||
final page = Uri.parse('https://app.test/chat/a?hello=1#part');
|
||||
final endpoint = Uri.parse('wss://rpc.test/connect');
|
||||
final apk = AppUpdate(
|
||||
versionCode: 8,
|
||||
versionName: '8',
|
||||
apk: Uri.parse('https://rpc.test/updates/pipelines.apk'),
|
||||
);
|
||||
|
||||
test(
|
||||
'web reads page origin even when appearance and RPC host differ',
|
||||
() async {
|
||||
final checker = LaunchUpdateChecker();
|
||||
Uri? requested;
|
||||
final result = await checker.check(
|
||||
web: true,
|
||||
android: true,
|
||||
webBuildId: 'web-old',
|
||||
page: page,
|
||||
endpoint: endpoint,
|
||||
readWeb: (uri) async {
|
||||
requested = uri;
|
||||
return '{"schema":1,"platform":"web","buildId":"web-new"}';
|
||||
},
|
||||
installedVersion: () async =>
|
||||
throw StateError('Android API used on web'),
|
||||
readAndroid: (_) async => throw StateError('APK feed used on web'),
|
||||
);
|
||||
expect(requested, Uri.parse('https://app.test/release.json'));
|
||||
expect(result, isA<WebLaunchUpdate>());
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'one check per visit, dismissed version stays quiet, later version asks',
|
||||
() async {
|
||||
final checker = LaunchUpdateChecker();
|
||||
var reads = 0;
|
||||
var latest = 'web-two';
|
||||
Future<LaunchUpdate?> check() => checker.check(
|
||||
web: true,
|
||||
android: false,
|
||||
webBuildId: 'web-one',
|
||||
page: page,
|
||||
endpoint: null,
|
||||
readWeb: (_) async {
|
||||
reads++;
|
||||
return '{"schema":1,"platform":"web","buildId":"$latest"}';
|
||||
},
|
||||
installedVersion: () async => null,
|
||||
readAndroid: (_) async => apk,
|
||||
);
|
||||
final offered = await check();
|
||||
expect(offered, isA<WebLaunchUpdate>());
|
||||
checker.markOffered(offered!);
|
||||
expect(await check(), isNull);
|
||||
expect(reads, 1);
|
||||
checker.beginVisit();
|
||||
expect(await check(), isNull);
|
||||
latest = 'web-three';
|
||||
checker.beginVisit();
|
||||
expect(await check(), isA<WebLaunchUpdate>());
|
||||
expect(reads, 3);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'Android defers until endpoint exists and uses its update feed',
|
||||
() async {
|
||||
final checker = LaunchUpdateChecker();
|
||||
Uri? feed;
|
||||
Future<LaunchUpdate?> check(Uri? server) => checker.check(
|
||||
web: false,
|
||||
android: true,
|
||||
webBuildId: '',
|
||||
page: page,
|
||||
endpoint: server,
|
||||
readWeb: (_) async => throw StateError('web feed used on Android'),
|
||||
installedVersion: () async => 7,
|
||||
readAndroid: (uri) async {
|
||||
feed = uri;
|
||||
return apk;
|
||||
},
|
||||
);
|
||||
expect(await check(null), isNull);
|
||||
expect(await check(endpoint), isA<AndroidLaunchUpdate>());
|
||||
expect(feed, Uri.parse('https://rpc.test/updates/'));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'unknown installed version skips APK feed; blank web identity skips web',
|
||||
() async {
|
||||
final checker = LaunchUpdateChecker();
|
||||
var reads = 0;
|
||||
Future<LaunchUpdate?> check(bool web) => checker.check(
|
||||
web: web,
|
||||
android: true,
|
||||
webBuildId: '',
|
||||
page: page,
|
||||
endpoint: endpoint,
|
||||
readWeb: (_) async {
|
||||
reads++;
|
||||
return null;
|
||||
},
|
||||
installedVersion: () async => null,
|
||||
readAndroid: (_) async {
|
||||
reads++;
|
||||
return apk;
|
||||
},
|
||||
);
|
||||
expect(await check(false), isNull);
|
||||
expect(await check(true), isNull);
|
||||
expect(reads, 0);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/updates/app_updates.dart';
|
||||
import 'package:pipelines_app/features/updates/launch_update.dart';
|
||||
|
||||
void main() {
|
||||
test('web compares release identity and ignores Android metadata', () {
|
||||
expect(
|
||||
webUpdateFor('web-current',
|
||||
'{"schema":1,"platform":"web","buildId":"web-current"}'),
|
||||
isNull,
|
||||
);
|
||||
expect(
|
||||
webUpdateFor('web-current',
|
||||
'{"schema":1,"platform":"web","buildId":"web-new"}'),
|
||||
isA<WebLaunchUpdate>(),
|
||||
);
|
||||
expect(
|
||||
webUpdateFor('web-current',
|
||||
'{"schema":1,"platform":"android","buildId":"web-new"}'),
|
||||
isNull,
|
||||
);
|
||||
expect(webUpdateFor('', '{"buildId":"web-new"}'), isNull);
|
||||
});
|
||||
|
||||
test('Android compares version code and never prompts for an older feed', () {
|
||||
final update = AppUpdate(
|
||||
versionCode: 8,
|
||||
versionName: '8',
|
||||
apk: Uri.parse('https://example.test/app.apk'),
|
||||
);
|
||||
expect(androidUpdateFor(update, 7), isA<AndroidLaunchUpdate>());
|
||||
expect(androidUpdateFor(update, 8), isNull);
|
||||
expect(androidUpdateFor(update, null), isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user