mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-24 21:45:20 +00:00
71 lines
2.1 KiB
Swift
71 lines
2.1 KiB
Swift
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)
|
|
))
|
|
}
|
|
}
|