feat: import Chinese-localized Buzz source snapshot
Docker image / Build (linux/amd64) (push) Has been cancelled
Docker image / Build (linux/arm64) (push) Has been cancelled
Docker image / Merge release multi-arch manifest (push) Has been cancelled
Docker image / Merge debug multi-arch manifest (push) Has been cancelled
Docker image / Build public push gateway (linux/amd64) (push) Has been cancelled
Docker image / Build public push gateway (linux/arm64) (push) Has been cancelled
Docker image / Publish public push gateway image (push) Has been cancelled
Sprig image / Build (linux/amd64) (push) Has been cancelled
Sprig image / Build (linux/arm64) (push) Has been cancelled
Sprig image / Merge multi-arch manifest (push) Has been cancelled
Harbor Buzz Orchestra / Python tests and lint (push) Has been cancelled
CI / Detect Changed Paths (push) Has been cancelled
CI / Rust Lint (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Desktop Core (push) Has been cancelled
CI / Desktop Smoke E2E (1) (push) Has been cancelled
CI / Desktop Smoke E2E (2) (push) Has been cancelled
CI / Desktop Smoke E2E (3) (push) Has been cancelled
CI / Desktop Smoke E2E (4) (push) Has been cancelled
CI / Desktop (push) Has been cancelled
CI / Desktop E2E Relay (push) Has been cancelled
CI / Desktop E2E Integration (1/2) (push) Has been cancelled
CI / Desktop E2E Integration (2/2) (push) Has been cancelled
CI / Desktop E2E Integration (push) Has been cancelled
CI / Backend Integration (relay e2e) (push) Has been cancelled
CI / Relay E2E (push) Has been cancelled
CI / Web (push) Has been cancelled
CI / Mobile (push) Has been cancelled
CI / Security (push) Has been cancelled
CI / Dead Token Reference Guard (push) Has been cancelled
CI / Server Cross-Compile (aarch64-unknown-linux-musl) (push) Has been cancelled
CI / Server Cross-Compile (x86_64-unknown-linux-musl) (push) Has been cancelled
CI / Windows Rust (x86_64-pc-windows-msvc) (push) Has been cancelled
CI / Desktop Build (macOS) (push) Has been cancelled
helm chart / lint + unittest + render matrix (push) Has been cancelled
helm chart / install on kind (gated) (push) Has been cancelled
helm chart / publish chart to GHCR (push) Has been cancelled
Mesh Lifecycle / Relay-Driven Mesh Lifecycle Smoke (push) Has been cancelled
Sprig / Build (aarch64-unknown-linux-musl) (push) Has been cancelled
Sprig / Build (x86_64-unknown-linux-musl) (push) Has been cancelled
Sprig / Publish rolling release (push) Has been cancelled
Sprig / Publish tagged release (push) Has been cancelled
Docker image / Build (linux/amd64) (push) Has been cancelled
Docker image / Build (linux/arm64) (push) Has been cancelled
Docker image / Merge release multi-arch manifest (push) Has been cancelled
Docker image / Merge debug multi-arch manifest (push) Has been cancelled
Docker image / Build public push gateway (linux/amd64) (push) Has been cancelled
Docker image / Build public push gateway (linux/arm64) (push) Has been cancelled
Docker image / Publish public push gateway image (push) Has been cancelled
Sprig image / Build (linux/amd64) (push) Has been cancelled
Sprig image / Build (linux/arm64) (push) Has been cancelled
Sprig image / Merge multi-arch manifest (push) Has been cancelled
Harbor Buzz Orchestra / Python tests and lint (push) Has been cancelled
CI / Detect Changed Paths (push) Has been cancelled
CI / Rust Lint (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Desktop Core (push) Has been cancelled
CI / Desktop Smoke E2E (1) (push) Has been cancelled
CI / Desktop Smoke E2E (2) (push) Has been cancelled
CI / Desktop Smoke E2E (3) (push) Has been cancelled
CI / Desktop Smoke E2E (4) (push) Has been cancelled
CI / Desktop (push) Has been cancelled
CI / Desktop E2E Relay (push) Has been cancelled
CI / Desktop E2E Integration (1/2) (push) Has been cancelled
CI / Desktop E2E Integration (2/2) (push) Has been cancelled
CI / Desktop E2E Integration (push) Has been cancelled
CI / Backend Integration (relay e2e) (push) Has been cancelled
CI / Relay E2E (push) Has been cancelled
CI / Web (push) Has been cancelled
CI / Mobile (push) Has been cancelled
CI / Security (push) Has been cancelled
CI / Dead Token Reference Guard (push) Has been cancelled
CI / Server Cross-Compile (aarch64-unknown-linux-musl) (push) Has been cancelled
CI / Server Cross-Compile (x86_64-unknown-linux-musl) (push) Has been cancelled
CI / Windows Rust (x86_64-pc-windows-msvc) (push) Has been cancelled
CI / Desktop Build (macOS) (push) Has been cancelled
helm chart / lint + unittest + render matrix (push) Has been cancelled
helm chart / install on kind (gated) (push) Has been cancelled
helm chart / publish chart to GHCR (push) Has been cancelled
Mesh Lifecycle / Relay-Driven Mesh Lifecycle Smoke (push) Has been cancelled
Sprig / Build (aarch64-unknown-linux-musl) (push) Has been cancelled
Sprig / Build (x86_64-unknown-linux-musl) (push) Has been cancelled
Sprig / Publish rolling release (push) Has been cancelled
Sprig / Publish tagged release (push) Has been cancelled
Signed-off-by: cls_宁波本机 <908705107@qq.com>
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import 'package:buzz/shared/community/community_icon_provider.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:http/testing.dart' as http_testing;
|
||||
|
||||
void main() {
|
||||
test('fetches the NIP-11 icon over the relay HTTP URL', () async {
|
||||
late http.Request capturedRequest;
|
||||
final client = http_testing.MockClient((request) async {
|
||||
capturedRequest = request;
|
||||
return http.Response('{"icon":"data:image/png;base64,icon-bytes"}', 200);
|
||||
});
|
||||
final container = ProviderContainer(
|
||||
overrides: [communityIconHttpClientProvider.overrideWithValue(client)],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
|
||||
final icon = await container.read(
|
||||
communityIconProvider('wss://relay.example.com').future,
|
||||
);
|
||||
|
||||
expect(capturedRequest.url, Uri.parse('https://relay.example.com'));
|
||||
expect(capturedRequest.headers['Accept'], 'application/nostr+json');
|
||||
expect(icon, 'data:image/png;base64,icon-bytes');
|
||||
});
|
||||
|
||||
test('returns null when the relay has no usable icon', () async {
|
||||
final client = http_testing.MockClient(
|
||||
(_) async => http.Response('{"icon":""}', 200),
|
||||
);
|
||||
final container = ProviderContainer(
|
||||
overrides: [communityIconHttpClientProvider.overrideWithValue(client)],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
|
||||
final icon = await container.read(
|
||||
communityIconProvider('https://relay.example.com').future,
|
||||
);
|
||||
|
||||
expect(icon, isNull);
|
||||
});
|
||||
|
||||
test('returns null when relay information cannot be loaded', () async {
|
||||
final client = http_testing.MockClient(
|
||||
(_) async => http.Response('unavailable', 503),
|
||||
);
|
||||
final container = ProviderContainer(
|
||||
overrides: [communityIconHttpClientProvider.overrideWithValue(client)],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
|
||||
final icon = await container.read(
|
||||
communityIconProvider('https://relay.example.com').future,
|
||||
);
|
||||
|
||||
expect(icon, isNull);
|
||||
});
|
||||
|
||||
test('refreshes a transient failure when explicitly invalidated', () async {
|
||||
var requestCount = 0;
|
||||
final client = http_testing.MockClient((_) async {
|
||||
requestCount++;
|
||||
if (requestCount == 1) {
|
||||
return http.Response('unavailable', 503);
|
||||
}
|
||||
return http.Response(
|
||||
'{"icon":"https://relay.example.com/icon.png"}',
|
||||
200,
|
||||
);
|
||||
});
|
||||
final container = ProviderContainer(
|
||||
overrides: [communityIconHttpClientProvider.overrideWithValue(client)],
|
||||
);
|
||||
final provider = communityIconProvider('https://relay.example.com');
|
||||
final subscription = container.listen(provider, (_, _) {});
|
||||
addTearDown(() {
|
||||
subscription.close();
|
||||
container.dispose();
|
||||
});
|
||||
|
||||
expect(await container.read(provider.future), isNull);
|
||||
expect(requestCount, 1);
|
||||
|
||||
container.invalidate(provider);
|
||||
|
||||
expect(
|
||||
await container.read(provider.future),
|
||||
'https://relay.example.com/icon.png',
|
||||
);
|
||||
expect(requestCount, 2);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.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_storage_test.dart';
|
||||
|
||||
void main() {
|
||||
late FakeSecureStorage fakeSecure;
|
||||
late CommunityStorage communityStorage;
|
||||
late ProviderContainer container;
|
||||
|
||||
setUp(() {
|
||||
fakeSecure = FakeSecureStorage();
|
||||
communityStorage = CommunityStorage(secure: fakeSecure);
|
||||
});
|
||||
|
||||
tearDown(() => container.dispose());
|
||||
|
||||
ProviderContainer createContainer() {
|
||||
return ProviderContainer(
|
||||
overrides: [communityStorageProvider.overrideWithValue(communityStorage)],
|
||||
);
|
||||
}
|
||||
|
||||
group('CommunityListNotifier', () {
|
||||
test('loads empty list initially', () async {
|
||||
container = createContainer();
|
||||
final communities = await container.read(communityListProvider.future);
|
||||
expect(communities, isEmpty);
|
||||
});
|
||||
|
||||
test('addCommunity adds to list', () async {
|
||||
container = createContainer();
|
||||
await container.read(communityListProvider.future);
|
||||
|
||||
final ws = Community.create(
|
||||
name: 'Test',
|
||||
relayUrl: 'https://test.example.com',
|
||||
);
|
||||
await container.read(communityListProvider.notifier).addCommunity(ws);
|
||||
|
||||
final communities = await container.read(communityListProvider.future);
|
||||
expect(communities, hasLength(1));
|
||||
expect(communities.first.name, 'Test');
|
||||
});
|
||||
|
||||
test('removeCommunity removes from list', () async {
|
||||
container = createContainer();
|
||||
await container.read(communityListProvider.future);
|
||||
|
||||
final ws = Community.create(
|
||||
name: 'Test',
|
||||
relayUrl: 'https://test.example.com',
|
||||
);
|
||||
await container.read(communityListProvider.notifier).addCommunity(ws);
|
||||
await container
|
||||
.read(communityListProvider.notifier)
|
||||
.removeCommunity(ws.id);
|
||||
|
||||
final communities = await container.read(communityListProvider.future);
|
||||
expect(communities, isEmpty);
|
||||
});
|
||||
|
||||
test('renameCommunity updates name', () async {
|
||||
container = createContainer();
|
||||
await container.read(communityListProvider.future);
|
||||
|
||||
final ws = Community.create(
|
||||
name: 'Original',
|
||||
relayUrl: 'https://test.example.com',
|
||||
);
|
||||
await container.read(communityListProvider.notifier).addCommunity(ws);
|
||||
await container
|
||||
.read(communityListProvider.notifier)
|
||||
.renameCommunity(ws.id, 'Renamed');
|
||||
|
||||
final communities = await container.read(communityListProvider.future);
|
||||
expect(communities.first.name, 'Renamed');
|
||||
});
|
||||
|
||||
test('switchCommunity updates active ID', () async {
|
||||
container = createContainer();
|
||||
await container.read(communityListProvider.future);
|
||||
|
||||
final ws1 = Community.create(
|
||||
name: 'One',
|
||||
relayUrl: 'https://one.example.com',
|
||||
);
|
||||
final ws2 = Community.create(
|
||||
name: 'Two',
|
||||
relayUrl: 'https://two.example.com',
|
||||
);
|
||||
|
||||
final notifier = container.read(communityListProvider.notifier);
|
||||
await notifier.addCommunity(ws1);
|
||||
await notifier.addCommunity(ws2);
|
||||
await notifier.switchCommunity(ws2.id);
|
||||
|
||||
final activeId = await communityStorage.loadActiveId();
|
||||
expect(activeId, ws2.id);
|
||||
});
|
||||
});
|
||||
|
||||
group('activeCommunityProvider', () {
|
||||
test('returns null when no communities', () async {
|
||||
container = createContainer();
|
||||
final active = await container.read(activeCommunityProvider.future);
|
||||
expect(active, isNull);
|
||||
});
|
||||
|
||||
test('returns community matching active ID', () async {
|
||||
container = createContainer();
|
||||
await container.read(communityListProvider.future);
|
||||
|
||||
final ws = Community.create(
|
||||
name: 'Test',
|
||||
relayUrl: 'https://test.example.com',
|
||||
);
|
||||
final notifier = container.read(communityListProvider.notifier);
|
||||
await notifier.addCommunity(ws);
|
||||
await notifier.switchCommunity(ws.id);
|
||||
|
||||
final active = await container.read(activeCommunityProvider.future);
|
||||
expect(active, isNotNull);
|
||||
expect(active!.id, ws.id);
|
||||
expect(active.name, 'Test');
|
||||
});
|
||||
|
||||
test('falls back to first community if active ID is invalid', () async {
|
||||
container = createContainer();
|
||||
await container.read(communityListProvider.future);
|
||||
|
||||
final ws = Community.create(
|
||||
name: 'Fallback',
|
||||
relayUrl: 'https://test.example.com',
|
||||
);
|
||||
final notifier = container.read(communityListProvider.notifier);
|
||||
await notifier.addCommunity(ws);
|
||||
|
||||
// Set an invalid active ID.
|
||||
await communityStorage.saveActiveId('nonexistent-id');
|
||||
|
||||
// Re-read — should fall back.
|
||||
container.invalidate(activeCommunityProvider);
|
||||
final active = await container.read(activeCommunityProvider.future);
|
||||
expect(active, isNotNull);
|
||||
expect(active!.id, ws.id);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,237 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:buzz/shared/community/community.dart';
|
||||
import 'package:buzz/shared/community/community_storage.dart';
|
||||
|
||||
/// In-memory fake that extends Fake to satisfy all FlutterSecureStorage
|
||||
/// interface methods, but implements the core read/write/delete with real
|
||||
/// in-memory logic.
|
||||
class FakeSecureStorage extends Fake implements FlutterSecureStorage {
|
||||
final Map<String, String> _data = {};
|
||||
|
||||
@override
|
||||
Future<String?> read({
|
||||
required String key,
|
||||
AppleOptions? iOptions,
|
||||
AndroidOptions? aOptions,
|
||||
LinuxOptions? lOptions,
|
||||
WebOptions? webOptions,
|
||||
AppleOptions? mOptions,
|
||||
WindowsOptions? wOptions,
|
||||
}) async => _data[key];
|
||||
|
||||
@override
|
||||
Future<void> write({
|
||||
required String key,
|
||||
required String? value,
|
||||
AppleOptions? iOptions,
|
||||
AndroidOptions? aOptions,
|
||||
LinuxOptions? lOptions,
|
||||
WebOptions? webOptions,
|
||||
AppleOptions? mOptions,
|
||||
WindowsOptions? wOptions,
|
||||
}) async {
|
||||
if (value != null) {
|
||||
_data[key] = value;
|
||||
} else {
|
||||
_data.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> delete({
|
||||
required String key,
|
||||
AppleOptions? iOptions,
|
||||
AndroidOptions? aOptions,
|
||||
LinuxOptions? lOptions,
|
||||
WebOptions? webOptions,
|
||||
AppleOptions? mOptions,
|
||||
WindowsOptions? wOptions,
|
||||
}) async => _data.remove(key);
|
||||
|
||||
@override
|
||||
Future<Map<String, String>> readAll({
|
||||
AppleOptions? iOptions,
|
||||
AndroidOptions? aOptions,
|
||||
LinuxOptions? lOptions,
|
||||
WebOptions? webOptions,
|
||||
AppleOptions? mOptions,
|
||||
WindowsOptions? wOptions,
|
||||
}) async => Map.from(_data);
|
||||
|
||||
@override
|
||||
Future<void> deleteAll({
|
||||
AppleOptions? iOptions,
|
||||
AndroidOptions? aOptions,
|
||||
LinuxOptions? lOptions,
|
||||
WebOptions? webOptions,
|
||||
AppleOptions? mOptions,
|
||||
WindowsOptions? wOptions,
|
||||
}) async => _data.clear();
|
||||
|
||||
@override
|
||||
Future<bool> containsKey({
|
||||
required String key,
|
||||
AppleOptions? iOptions,
|
||||
AndroidOptions? aOptions,
|
||||
LinuxOptions? lOptions,
|
||||
WebOptions? webOptions,
|
||||
AppleOptions? mOptions,
|
||||
WindowsOptions? wOptions,
|
||||
}) async => _data.containsKey(key);
|
||||
|
||||
// Convenience for setting up test data.
|
||||
String? operator [](String key) => _data[key];
|
||||
void operator []=(String key, String value) => _data[key] = value;
|
||||
}
|
||||
|
||||
void main() {
|
||||
late FakeSecureStorage fakeSecure;
|
||||
late CommunityStorage storage;
|
||||
|
||||
setUp(() {
|
||||
fakeSecure = FakeSecureStorage();
|
||||
storage = CommunityStorage(secure: fakeSecure);
|
||||
});
|
||||
|
||||
group('CommunityStorage', () {
|
||||
test('loadAll returns empty list when no data', () async {
|
||||
final result = await storage.loadAll();
|
||||
expect(result, isEmpty);
|
||||
});
|
||||
|
||||
test('save and loadAll round-trips a community', () async {
|
||||
final ws = Community.create(
|
||||
name: 'Test',
|
||||
relayUrl: 'https://relay.example.com',
|
||||
pubkey: 'abc123',
|
||||
);
|
||||
|
||||
await storage.save(ws);
|
||||
final loaded = await storage.loadAll();
|
||||
|
||||
expect(loaded, hasLength(1));
|
||||
expect(loaded.first.id, ws.id);
|
||||
expect(loaded.first.name, 'Test');
|
||||
expect(loaded.first.relayUrl, 'https://relay.example.com');
|
||||
expect(loaded.first.pubkey, 'abc123');
|
||||
});
|
||||
|
||||
test('save updates existing community with same id', () async {
|
||||
final ws = Community.create(
|
||||
name: 'Original',
|
||||
relayUrl: 'https://relay.example.com',
|
||||
);
|
||||
|
||||
await storage.save(ws);
|
||||
await storage.save(ws.copyWith(name: 'Updated'));
|
||||
|
||||
final loaded = await storage.loadAll();
|
||||
expect(loaded, hasLength(1));
|
||||
expect(loaded.first.name, 'Updated');
|
||||
});
|
||||
|
||||
test('remove deletes a community', () async {
|
||||
final ws1 = Community.create(
|
||||
name: 'One',
|
||||
relayUrl: 'https://one.example.com',
|
||||
);
|
||||
final ws2 = Community.create(
|
||||
name: 'Two',
|
||||
relayUrl: 'https://two.example.com',
|
||||
);
|
||||
|
||||
await storage.save(ws1);
|
||||
await storage.save(ws2);
|
||||
await storage.remove(ws1.id);
|
||||
|
||||
final loaded = await storage.loadAll();
|
||||
expect(loaded, hasLength(1));
|
||||
expect(loaded.first.id, ws2.id);
|
||||
});
|
||||
|
||||
test('active community ID persists', () async {
|
||||
await storage.saveActiveId('ws-123');
|
||||
final id = await storage.loadActiveId();
|
||||
expect(id, 'ws-123');
|
||||
});
|
||||
|
||||
test('clearActiveId removes active ID', () async {
|
||||
await storage.saveActiveId('ws-123');
|
||||
await storage.clearActiveId();
|
||||
final id = await storage.loadActiveId();
|
||||
expect(id, isNull);
|
||||
});
|
||||
|
||||
group('migration', () {
|
||||
test('migrates saved workspaces to communities', () async {
|
||||
final legacy = Community.create(
|
||||
name: 'Legacy',
|
||||
relayUrl: 'https://legacy.example.com',
|
||||
);
|
||||
fakeSecure['buzz_workspaces'] = jsonEncode([legacy.toJson()]);
|
||||
fakeSecure['buzz_active_workspace_id'] = legacy.id;
|
||||
|
||||
final loaded = await storage.loadAll();
|
||||
|
||||
expect(loaded.single.id, legacy.id);
|
||||
expect(await storage.loadActiveId(), legacy.id);
|
||||
expect(fakeSecure['buzz_communities'], isNotNull);
|
||||
expect(fakeSecure['buzz_workspaces'], isNull);
|
||||
expect(fakeSecure['buzz_active_workspace_id'], isNull);
|
||||
});
|
||||
|
||||
test('migrates legacy keys to community on first load', () async {
|
||||
fakeSecure['buzz_relay_url'] = 'https://legacy.example.com';
|
||||
fakeSecure['buzz_token'] = 'legacy_token';
|
||||
fakeSecure['buzz_pubkey'] = 'legacy_pub';
|
||||
fakeSecure['buzz_nsec'] = 'legacy_nsec';
|
||||
|
||||
final loaded = await storage.loadAll();
|
||||
|
||||
expect(loaded, hasLength(1));
|
||||
expect(loaded.first.relayUrl, 'https://legacy.example.com');
|
||||
expect(loaded.first.pubkey, 'legacy_pub');
|
||||
expect(loaded.first.nsec, 'legacy_nsec');
|
||||
expect(loaded.first.name, isNotEmpty);
|
||||
|
||||
// Legacy keys should be deleted.
|
||||
expect(fakeSecure['buzz_relay_url'], isNull);
|
||||
expect(fakeSecure['buzz_token'], isNull);
|
||||
expect(fakeSecure['buzz_pubkey'], isNull);
|
||||
expect(fakeSecure['buzz_nsec'], isNull);
|
||||
|
||||
// Active ID should be set.
|
||||
final activeId = await storage.loadActiveId();
|
||||
expect(activeId, loaded.first.id);
|
||||
});
|
||||
|
||||
test('does not migrate when no legacy keys exist', () async {
|
||||
final loaded = await storage.loadAll();
|
||||
expect(loaded, isEmpty);
|
||||
});
|
||||
|
||||
test('does not re-migrate after first load', () async {
|
||||
fakeSecure['buzz_relay_url'] = 'https://legacy.example.com';
|
||||
fakeSecure['buzz_token'] = 'legacy_token';
|
||||
|
||||
final first = await storage.loadAll();
|
||||
expect(first, hasLength(1));
|
||||
|
||||
final second = await storage.loadAll();
|
||||
expect(second, hasLength(1));
|
||||
expect(second.first.id, first.first.id);
|
||||
});
|
||||
|
||||
test('migration generates name from localhost URL', () async {
|
||||
fakeSecure['buzz_relay_url'] = 'http://localhost:3000';
|
||||
fakeSecure['buzz_token'] = 'tok';
|
||||
|
||||
final loaded = await storage.loadAll();
|
||||
expect(loaded.first.name, 'Local Dev');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user