Make panic wipe deterministic and device-bound

This commit is contained in:
jack
2026-07-10 20:44:20 +02:00
parent 733098bb63
commit 917c477012
11 changed files with 317 additions and 69 deletions
+17 -2
View File
@@ -15,7 +15,9 @@ import BitFoundation
/// Creates a ChatViewModel with mock dependencies for testing
@MainActor
private func makeTestableViewModel() -> (viewModel: ChatViewModel, transport: MockTransport) {
private func makeTestableViewModel(
panicMediaWipe: (() throws -> Void)? = nil
) -> (viewModel: ChatViewModel, transport: MockTransport) {
let keychain = MockKeychain()
let keychainHelper = MockKeychainHelper()
let idBridge = NostrIdentityBridge(keychain: keychainHelper)
@@ -26,7 +28,8 @@ private func makeTestableViewModel() -> (viewModel: ChatViewModel, transport: Mo
keychain: keychain,
idBridge: idBridge,
identityManager: identityManager,
transport: transport
transport: transport,
panicMediaWipe: panicMediaWipe
)
return (viewModel, transport)
@@ -1097,6 +1100,18 @@ struct ChatViewModelBluetoothTests {
struct ChatViewModelPanicTests {
@Test @MainActor
func panicClearAllData_finishesMediaWipeBeforeReturning() {
var wipeFinished = false
let (viewModel, _) = makeTestableViewModel {
wipeFinished = true
}
viewModel.panicClearAllData()
#expect(wipeFinished)
}
@Test @MainActor
func panicClearAllData_delegatesToTransport() async {
let (viewModel, transport) = makeTestableViewModel()