mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Signed-off-by: Wes <wesbillman@users.noreply.github.com> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
62 lines
2.1 KiB
Dart
62 lines
2.1 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:nostr/nostr.dart' as nostr;
|
|
import 'package:buzz/shared/auth/auth_provider.dart';
|
|
import 'package:buzz/shared/community/community.dart';
|
|
import 'package:buzz/shared/community/community_provider.dart';
|
|
import 'package:buzz/shared/community/community_storage.dart';
|
|
|
|
import '../community/community_storage_test.dart';
|
|
|
|
void main() {
|
|
test(
|
|
'removes an invalid saved community instead of authenticating',
|
|
() async {
|
|
final storage = CommunityStorage(secure: FakeSecureStorage());
|
|
final invalid = Community.create(
|
|
name: 'Invalid',
|
|
relayUrl: 'https://relay.example',
|
|
nsec: 'not-an-nsec',
|
|
);
|
|
await storage.save(invalid);
|
|
await storage.saveActiveId(invalid.id);
|
|
final container = ProviderContainer(
|
|
overrides: [communityStorageProvider.overrideWithValue(storage)],
|
|
);
|
|
addTearDown(container.dispose);
|
|
|
|
final auth = await container.read(authProvider.future);
|
|
|
|
expect(auth.status, AuthStatus.unauthenticated);
|
|
expect(await storage.loadAll(), isEmpty);
|
|
expect(await storage.loadActiveId(), isNull);
|
|
},
|
|
);
|
|
|
|
test('falls through to the next valid saved community', () async {
|
|
final storage = CommunityStorage(secure: FakeSecureStorage());
|
|
final invalid = Community.create(
|
|
name: 'Invalid',
|
|
relayUrl: 'https://invalid.example',
|
|
);
|
|
final valid = Community.create(
|
|
name: 'Valid',
|
|
relayUrl: 'https://valid.example',
|
|
nsec: nostr.Keys.generate().nsec,
|
|
);
|
|
await storage.save(invalid);
|
|
await storage.save(valid);
|
|
await storage.saveActiveId(invalid.id);
|
|
final container = ProviderContainer(
|
|
overrides: [communityStorageProvider.overrideWithValue(storage)],
|
|
);
|
|
addTearDown(container.dispose);
|
|
|
|
final auth = await container.read(authProvider.future);
|
|
|
|
expect(auth.status, AuthStatus.authenticated);
|
|
expect(auth.community?.id, valid.id);
|
|
expect(await storage.loadActiveId(), valid.id);
|
|
});
|
|
}
|