import 'dart:async'; import 'dart:convert'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/servers/server_catalog.dart'; import 'package:pipelines_app/features/updates/app_updates.dart'; import 'package:shared_preferences/shared_preferences.dart'; void main() { test('a failed check names each machine and why it offered nothing', () async { SharedPreferences.setMockInitialValues({}); final tank = SavedServer.validated( id: 'tank', name: 'tank', endpoints: ['wss://tank.test/connect'], ); final mac = SavedServer.validated( id: 'mac', name: 'Mac', endpoints: ['wss://mac.test/connect'], ); await expectLater( newestServerUpdate( [tank, mac], read: (base, _) async => base.host == 'tank.test' ? throw const FormatException( 'The update feed is signed by a key this app does not trust.', ) : throw TimeoutException('slow'), ), throwsA( isA().having( (e) => e.message, 'message', allOf( contains( 'tank: The update feed is signed by a key this app does not trust.', ), contains('Mac: the server did not answer in time'), ), ), ), ); }); test('an HTTP failure keeps its own words without the exception noise', () { expect( updateProblem(_FakeHttpException('Sign in first (Settings → Sign in).')), 'Sign in first (Settings → Sign in).', ); }); test('another Android signing certificate is said plainly', () { final body = jsonEncode({ 'versionCode': 2, 'apk': 'pipelines.apk', 'signingCertificateSha256': 'a' * 64, }); expect( incompatibleUpdateReason( body, platform: 'android', installedSignature: 'B' * 64, ), contains('different certificate'), ); expect( incompatibleUpdateReason( body, platform: 'android', installedSignature: 'A' * 64, ), 'no compatible build is offered for this device', ); }); } class _FakeHttpException implements Exception { _FakeHttpException(this.message); final String message; @override String toString() => 'HttpException: $message, uri = https://tank.test/x'; }