mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 01:05:19 +00:00
* Make static functions instance functions to be testable * Injectable KeychainManager + Mock + updated tests * Remove `pendingActions` from identity manager (dead code) * Remove `getHandshakeState` from identity manager (dead code) * Remove `getAllSocialIdentities` from identity manager (dead code) * Remove `getCryptographicIdentity` from identity manager (dead code) * Remove `resolveIdentity` from identity manager (dead code) * Identity Manager: minor clean up * Put Identity Manager behind a protocol * Remove Keychain and Identity Manager singletons * Tests: include MockKeychain/MockIdentityManager in project; init identityManager in CommandProcessorTests --------- Co-authored-by: jack <jackjackbits@users.noreply.github.com>
55 lines
1.7 KiB
Swift
55 lines
1.7 KiB
Swift
import XCTest
|
|
@testable import bitchat
|
|
|
|
final class CommandProcessorTests: XCTestCase {
|
|
|
|
var identityManager: MockIdentityManager!
|
|
|
|
override func setUp() {
|
|
super.setUp()
|
|
// Provide a minimal identity manager for commands that query identity/block lists
|
|
identityManager = MockIdentityManager(MockKeychain())
|
|
}
|
|
|
|
override func tearDown() {
|
|
identityManager = nil
|
|
super.tearDown()
|
|
}
|
|
|
|
@MainActor
|
|
func test_slap_notFoundGrammar() {
|
|
let processor = CommandProcessor(chatViewModel: nil, meshService: nil, identityManager: identityManager)
|
|
let result = processor.process("/slap @system")
|
|
switch result {
|
|
case .error(let message):
|
|
XCTAssertEqual(message, "cannot slap system: not found")
|
|
default:
|
|
XCTFail("Expected error result")
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
func test_hug_notFoundGrammar() {
|
|
let processor = CommandProcessor(chatViewModel: nil, meshService: nil, identityManager: identityManager)
|
|
let result = processor.process("/hug @system")
|
|
switch result {
|
|
case .error(let message):
|
|
XCTAssertEqual(message, "cannot hug system: not found")
|
|
default:
|
|
XCTFail("Expected error result")
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
func test_slap_usageMessage() {
|
|
let processor = CommandProcessor(chatViewModel: nil, meshService: nil, identityManager: identityManager)
|
|
let result = processor.process("/slap")
|
|
switch result {
|
|
case .error(let message):
|
|
XCTAssertEqual(message, "usage: /slap <nickname>")
|
|
default:
|
|
XCTFail("Expected error result for usage message")
|
|
}
|
|
}
|
|
}
|