import 'package:flutter_test/flutter_test.dart'; import 'package:ikar/core/storage/startup_account.dart'; void main() { test( 'valid active account does not scan profiles or change accounts', () async { expect( await resolveStartupAccount( readActiveId: () async => 7, readToken: (id) async => id == 7 ? 'token' : null, readProfileIds: () async => throw StateError('unnecessary database scan'), activate: (_) async => fail('active account must remain unchanged'), ), 7, ); }, ); test('recovers an account with credentials before showing chats', () async { final activated = []; expect( await resolveStartupAccount( readActiveId: () async => 7, readToken: (id) async => id == 9 ? 'token' : null, readProfileIds: () async => [7, 8, 9], activate: (id) async => activated.add(id), ), 9, ); expect(activated, [9]); }); test('no credentials goes to login even with cached profiles', () async { expect( await resolveStartupAccount( readActiveId: () async => null, readToken: (_) async => null, readProfileIds: () async => [7, 8], activate: (_) async => fail('must not activate an unauthenticated account'), ), isNull, ); }); test('secure storage failure is not treated as a valid session', () async { await expectLater( resolveStartupAccount( readActiveId: () async => 7, readToken: (_) async => throw StateError('storage unavailable'), readProfileIds: () async => [7], activate: (_) async {}, ), throwsStateError, ); }); }