mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 22:05:21 +00:00
* Add comprehensive test coverage for ChatViewModel and BLEService This commit adds 14 new tests to improve the safety net for future refactoring of ChatViewModel and BLEService: New test files: - ChatViewModelTorTests: Tor lifecycle notification handlers (8 tests) - ChatViewModelDeliveryStatusTests: Delivery status state machine (6 tests) - ChatViewModelRefactoringTests: Command routing and message handling (4 tests) - BLEServiceCoreTests: Packet deduplication and stale broadcast filtering (2 tests) - PublicMessagePipelineTests: Message ordering and deduplication (4 tests) - MessageRouterTests: Transport selection and outbox behavior (4 tests) - PrivateChatManagerTests: Chat selection and read receipts (2 tests) - UnifiedPeerServiceTests: Fingerprint resolution and blocking (2 tests) - RelayControllerTests: TTL, handshake, and fragment relay logic (4 tests) Modified files: - MockTransport: Added peer snapshot publishing on connect/disconnect - TestHelpers: Added waitUntil polling helper for async tests - MockIdentityManager: Extended for new test scenarios Total: 454 tests across 64 suites (was 440) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix flaky test by using waitUntil instead of fixed sleep Replace fixed 200ms sleep with waitUntil helper for more reliable async assertion in routing tests. This prevents timing issues on CI. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
118 lines
3.4 KiB
Swift
118 lines
3.4 KiB
Swift
//
|
|
// MockIdentityManager.swift
|
|
// bitchat
|
|
//
|
|
// This is free and unencumbered software released into the public domain.
|
|
// For more information, see <https://unlicense.org>
|
|
//
|
|
|
|
import Foundation
|
|
@testable import bitchat
|
|
|
|
final class MockIdentityManager: SecureIdentityStateManagerProtocol {
|
|
private let keychain: KeychainManagerProtocol
|
|
private var blockedFingerprints: Set<String> = []
|
|
private var blockedNostrPubkeys: Set<String> = []
|
|
private var socialIdentities: [String: SocialIdentity] = [:]
|
|
|
|
init(_ keychain: KeychainManagerProtocol) {
|
|
self.keychain = keychain
|
|
}
|
|
|
|
func loadIdentityCache() {}
|
|
|
|
func saveIdentityCache() {}
|
|
|
|
func forceSave() {}
|
|
|
|
func getSocialIdentity(for fingerprint: String) -> SocialIdentity? {
|
|
socialIdentities[fingerprint]
|
|
}
|
|
|
|
func upsertCryptographicIdentity(fingerprint: String, noisePublicKey: Data, signingPublicKey: Data?, claimedNickname: String?) {}
|
|
|
|
func getCryptoIdentitiesByPeerIDPrefix(_ peerID: PeerID) -> [CryptographicIdentity] {
|
|
[]
|
|
}
|
|
|
|
func updateSocialIdentity(_ identity: SocialIdentity) {
|
|
socialIdentities[identity.fingerprint] = identity
|
|
if identity.isBlocked {
|
|
blockedFingerprints.insert(identity.fingerprint)
|
|
} else {
|
|
blockedFingerprints.remove(identity.fingerprint)
|
|
}
|
|
}
|
|
|
|
func getFavorites() -> Set<String> {
|
|
Set()
|
|
}
|
|
|
|
func setFavorite(_ fingerprint: String, isFavorite: Bool) {}
|
|
|
|
func isFavorite(fingerprint: String) -> Bool {
|
|
false
|
|
}
|
|
|
|
func isBlocked(fingerprint: String) -> Bool {
|
|
blockedFingerprints.contains(fingerprint) || socialIdentities[fingerprint]?.isBlocked == true
|
|
}
|
|
|
|
func setBlocked(_ fingerprint: String, isBlocked: Bool) {
|
|
if var identity = socialIdentities[fingerprint] {
|
|
identity.isBlocked = isBlocked
|
|
socialIdentities[fingerprint] = identity
|
|
} else {
|
|
let identity = SocialIdentity(
|
|
fingerprint: fingerprint,
|
|
localPetname: nil,
|
|
claimedNickname: "",
|
|
trustLevel: .unknown,
|
|
isFavorite: false,
|
|
isBlocked: isBlocked,
|
|
notes: nil
|
|
)
|
|
socialIdentities[fingerprint] = identity
|
|
}
|
|
if isBlocked {
|
|
blockedFingerprints.insert(fingerprint)
|
|
} else {
|
|
blockedFingerprints.remove(fingerprint)
|
|
}
|
|
}
|
|
|
|
func isNostrBlocked(pubkeyHexLowercased: String) -> Bool {
|
|
blockedNostrPubkeys.contains(pubkeyHexLowercased)
|
|
}
|
|
|
|
func setNostrBlocked(_ pubkeyHexLowercased: String, isBlocked: Bool) {
|
|
if isBlocked {
|
|
blockedNostrPubkeys.insert(pubkeyHexLowercased)
|
|
} else {
|
|
blockedNostrPubkeys.remove(pubkeyHexLowercased)
|
|
}
|
|
}
|
|
|
|
func getBlockedNostrPubkeys() -> Set<String> {
|
|
blockedNostrPubkeys
|
|
}
|
|
|
|
func registerEphemeralSession(peerID: PeerID, handshakeState: HandshakeState) {}
|
|
|
|
func updateHandshakeState(peerID: PeerID, state: HandshakeState) {}
|
|
|
|
func clearAllIdentityData() {}
|
|
|
|
func removeEphemeralSession(peerID: PeerID) {}
|
|
|
|
func setVerified(fingerprint: String, verified: Bool) {}
|
|
|
|
func isVerified(fingerprint: String) -> Bool {
|
|
true
|
|
}
|
|
|
|
func getVerifiedFingerprints() -> Set<String> {
|
|
Set()
|
|
}
|
|
}
|