mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 14:45:21 +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,8 +1,9 @@
|
||||
import XCTest
|
||||
import Testing
|
||||
import Foundation
|
||||
@testable import bitchat
|
||||
|
||||
@MainActor
|
||||
final class LocationNotesManagerTests: XCTestCase {
|
||||
struct LocationNotesManagerTests {
|
||||
// func testSubscribeWithoutRelaysSetsNoRelaysState() {
|
||||
// var subscribeCalled = false
|
||||
// let deps = LocationNotesDependencies(
|
||||
@@ -47,15 +48,15 @@ final class LocationNotesManagerTests: XCTestCase {
|
||||
// XCTAssertNotEqual(manager.errorMessage, "location_notes.error.no_relays")
|
||||
// }
|
||||
|
||||
func testSubscribeUsesGeoRelaysAndAppendsNotes() {
|
||||
@Test func subscribeUsesGeoRelaysAndAppendsNotes() {
|
||||
var relaysCaptured: [String] = []
|
||||
var storedHandler: ((NostrEvent) -> Void)?
|
||||
var storedEOSE: (() -> Void)?
|
||||
let deps = LocationNotesDependencies(
|
||||
relayLookup: { _, _ in ["wss://relay.one"] },
|
||||
subscribe: { filter, id, relays, handler, eose in
|
||||
XCTAssertEqual(filter.kinds, [1])
|
||||
XCTAssertFalse(id.isEmpty)
|
||||
#expect(filter.kinds == [1])
|
||||
#expect(!id.isEmpty)
|
||||
relaysCaptured = relays
|
||||
storedHandler = handler
|
||||
storedEOSE = eose
|
||||
@@ -67,8 +68,8 @@ final class LocationNotesManagerTests: XCTestCase {
|
||||
)
|
||||
|
||||
let manager = LocationNotesManager(geohash: "u4pruydq", dependencies: deps)
|
||||
XCTAssertEqual(relaysCaptured, ["wss://relay.one"])
|
||||
XCTAssertEqual(manager.state, .loading)
|
||||
#expect(relaysCaptured == ["wss://relay.one"])
|
||||
#expect(manager.state == .loading)
|
||||
|
||||
var event = NostrEvent(
|
||||
pubkey: "pub",
|
||||
@@ -81,9 +82,9 @@ final class LocationNotesManagerTests: XCTestCase {
|
||||
storedHandler?(event)
|
||||
storedEOSE?()
|
||||
|
||||
XCTAssertEqual(manager.state, .ready)
|
||||
XCTAssertEqual(manager.notes.count, 1)
|
||||
XCTAssertEqual(manager.notes.first?.content, "hi")
|
||||
#expect(manager.state == .ready)
|
||||
#expect(manager.notes.count == 1)
|
||||
#expect(manager.notes.first?.content == "hi")
|
||||
}
|
||||
|
||||
private enum TestError: Error {
|
||||
@@ -92,8 +93,8 @@ final class LocationNotesManagerTests: XCTestCase {
|
||||
}
|
||||
|
||||
@MainActor
|
||||
final class LocationNotesCounterTests: XCTestCase {
|
||||
func testSubscribeWithoutRelaysMarksUnavailable() {
|
||||
struct LocationNotesCounterTests {
|
||||
@Test func subscribeWithoutRelaysMarksUnavailable() {
|
||||
var subscribeCalled = false
|
||||
let deps = LocationNotesCounterDependencies(
|
||||
relayLookup: { _, _ in [] },
|
||||
@@ -104,21 +105,21 @@ final class LocationNotesCounterTests: XCTestCase {
|
||||
let counter = LocationNotesCounter(testDependencies: deps)
|
||||
counter.subscribe(geohash: "u4pruydq")
|
||||
|
||||
XCTAssertFalse(subscribeCalled)
|
||||
XCTAssertFalse(counter.relayAvailable)
|
||||
XCTAssertTrue(counter.initialLoadComplete)
|
||||
XCTAssertEqual(counter.count, 0)
|
||||
#expect(!subscribeCalled)
|
||||
#expect(!counter.relayAvailable)
|
||||
#expect(counter.initialLoadComplete)
|
||||
#expect(counter.count == 0)
|
||||
}
|
||||
|
||||
func testSubscribeCountsUniqueNotes() {
|
||||
@Test func subscribeCountsUniqueNotes() {
|
||||
var storedHandler: ((NostrEvent) -> Void)?
|
||||
var storedEOSE: (() -> Void)?
|
||||
let deps = LocationNotesCounterDependencies(
|
||||
relayLookup: { _, _ in ["wss://relay.geo"] },
|
||||
subscribe: { filter, id, relays, handler, eose in
|
||||
XCTAssertEqual(relays, ["wss://relay.geo"])
|
||||
XCTAssertEqual(filter.kinds, [1])
|
||||
XCTAssertFalse(id.isEmpty)
|
||||
#expect(relays == ["wss://relay.geo"])
|
||||
#expect(filter.kinds == [1])
|
||||
#expect(!id.isEmpty)
|
||||
storedHandler = handler
|
||||
storedEOSE = eose
|
||||
},
|
||||
@@ -143,8 +144,8 @@ final class LocationNotesCounterTests: XCTestCase {
|
||||
|
||||
storedEOSE?()
|
||||
|
||||
XCTAssertTrue(counter.relayAvailable)
|
||||
XCTAssertEqual(counter.count, 1)
|
||||
XCTAssertTrue(counter.initialLoadComplete)
|
||||
#expect(counter.relayAvailable)
|
||||
#expect(counter.count == 1)
|
||||
#expect(counter.initialLoadComplete)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user