mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 14:25:20 +00:00
Convert the remaining tests to Swift Testing (#781)
* SwiftTesting: NoiseProtocolTests + BinaryProtocolPaddingTests * SwiftTesting: `NotificationStreamAssemblerTests` * SwiftTesting: `NostrProtocolTests` * SwiftTesting: `BinaryProtocolTests` * SwiftTesting: `PeerIDTests` * SwiftTesting: `BLEServiceTests` * SwiftTesting: `CommandProcessorTests` * SwiftTesting: `GCSFilterTests` * SwiftTesting: `GeohashBookmarksStoreTests` * Remove `peerID` test constants * Remove PeerID + String interop from tests * Refactor IntegrationTests to extract state management * Refactor global state management of MockBLEService * NoiseProtocolSwiftTests: `actor` -> `struct` * Remove measurement tests w/ no benchmark * `NoiseProtocolSwiftTests` -> `NoiseProtocolTests` * SwiftTesting: `LocationChannelsTests` * SwiftTesting: `GossipSyncManagerTests` * SwiftTesting: `LocationNotesManagerTests` * Global `sleep` function for tests * SwiftTesting: `IntegrationTests` --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
This commit is contained in:
committed by
islam
co-authored by
jack
parent
790dcda8e5
commit
5267489fa2
@@ -1,52 +1,38 @@
|
||||
import XCTest
|
||||
import Testing
|
||||
import Foundation
|
||||
@testable import bitchat
|
||||
|
||||
final class GeohashBookmarksStoreTests: XCTestCase {
|
||||
let storeKey = "locationChannel.bookmarks"
|
||||
var storage: UserDefaults!
|
||||
var store: GeohashBookmarksStore!
|
||||
struct GeohashBookmarksStoreTests {
|
||||
private let storeKey = "locationChannel.bookmarks"
|
||||
private let storage = UserDefaults(suiteName: UUID().uuidString)!
|
||||
private let store: GeohashBookmarksStore
|
||||
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// Unique instance for each test to avoid race condition
|
||||
storage = UserDefaults(suiteName: UUID().uuidString)
|
||||
store = GeohashBookmarksStore(storage: storage!)
|
||||
init() {
|
||||
store = GeohashBookmarksStore(storage: storage)
|
||||
}
|
||||
|
||||
override func tearDown() {
|
||||
storage.removeObject(forKey: storeKey)
|
||||
store._resetForTesting()
|
||||
store = nil
|
||||
storage = nil
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testToggleAndNormalize() {
|
||||
@Test func toggleAndNormalize() {
|
||||
// Start clean
|
||||
XCTAssertTrue(store.bookmarks.isEmpty)
|
||||
#expect(store.bookmarks.isEmpty)
|
||||
|
||||
// Add with mixed case and hash prefix
|
||||
store.toggle("#U4PRUY")
|
||||
XCTAssertTrue(store.isBookmarked("u4pruy"))
|
||||
XCTAssertEqual(store.bookmarks.first, "u4pruy")
|
||||
#expect(store.isBookmarked("u4pruy"))
|
||||
#expect(store.bookmarks.first == "u4pruy")
|
||||
|
||||
// Toggling again removes
|
||||
store.toggle("u4pruy")
|
||||
XCTAssertFalse(store.isBookmarked("u4pruy"))
|
||||
XCTAssertTrue(store.bookmarks.isEmpty)
|
||||
#expect(!store.isBookmarked("u4pruy"))
|
||||
#expect(store.bookmarks.isEmpty)
|
||||
}
|
||||
|
||||
func testPersistenceWritten() throws {
|
||||
@Test func persistenceWritten() throws {
|
||||
store.toggle("ezs42")
|
||||
store.toggle("u4pruy")
|
||||
|
||||
// Verify persisted JSON contains both (order not enforced here)
|
||||
guard let data = storage.data(forKey: storeKey) else {
|
||||
XCTFail("No persisted data found")
|
||||
return
|
||||
}
|
||||
let data = try #require(storage.data(forKey: storeKey), "No persisted data found")
|
||||
let arr = try JSONDecoder().decode([String].self, from: data)
|
||||
XCTAssertTrue(arr.contains("ezs42"))
|
||||
XCTAssertTrue(arr.contains("u4pruy"))
|
||||
#expect(arr.contains("ezs42"))
|
||||
#expect(arr.contains("u4pruy"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user