Extract BLE and chat architecture policies (#1324)

Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
jack
2026-06-02 09:01:59 +02:00
committed by GitHub
co-authored by jack
parent 193cfdc06a
commit 3eb4f2bd72
46 changed files with 3286 additions and 786 deletions
@@ -0,0 +1,70 @@
import Testing
@testable import bitchat
struct ChatFavoriteTogglePolicyTests {
@Test
func addingWithoutExistingStatusUsesFallbackNicknameAndBridgeKey() {
let plan = ChatFavoriteTogglePolicy.plan(
currentStatus: nil,
fallbackNickname: "alice",
bridgedNostrKey: "npub-alice"
)
#expect(plan == ChatFavoriteTogglePlan(
persistenceAction: .add(nickname: "alice", nostrKey: "npub-alice"),
notification: .none
))
}
@Test
func addingMutualFavoriteSendsPositiveNotification() {
let plan = ChatFavoriteTogglePolicy.plan(
currentStatus: ChatFavoriteStatusSnapshot(
peerNickname: "alice",
peerNostrPublicKey: "npub-current",
isFavorite: false,
theyFavoritedUs: true
),
fallbackNickname: "fallback",
bridgedNostrKey: "npub-bridge"
)
#expect(plan == ChatFavoriteTogglePlan(
persistenceAction: .add(nickname: "alice", nostrKey: "npub-current"),
notification: .send(isFavorite: true)
))
}
@Test
func addingWithoutAnyNicknameUsesUnknown() {
let plan = ChatFavoriteTogglePolicy.plan(
currentStatus: nil,
fallbackNickname: nil,
bridgedNostrKey: nil
)
#expect(plan == ChatFavoriteTogglePlan(
persistenceAction: .add(nickname: "Unknown", nostrKey: nil),
notification: .none
))
}
@Test
func removingFavoriteSendsNegativeNotification() {
let plan = ChatFavoriteTogglePolicy.plan(
currentStatus: ChatFavoriteStatusSnapshot(
peerNickname: "alice",
peerNostrPublicKey: "npub-current",
isFavorite: true,
theyFavoritedUs: false
),
fallbackNickname: nil,
bridgedNostrKey: nil
)
#expect(plan == ChatFavoriteTogglePlan(
persistenceAction: .remove,
notification: .send(isFavorite: false)
))
}
}