mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 01:45:20 +00:00
Extract BLE and chat architecture policies (#1324)
Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
@@ -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)
|
||||
))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user