Skip to content
Snippets Groups Projects
Commit 7c7055c0 authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Merge branch 'feature/messenger-destroy' into 'development'

Improve MessengerDestroy functor

See merge request elixxir/elixxir-dapps-sdk-swift!44
parents 1ad1ef94 c90c312b
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!44Improve MessengerDestroy functor
...@@ -11,10 +11,10 @@ public struct MessengerDestroy { ...@@ -11,10 +11,10 @@ public struct MessengerDestroy {
extension MessengerDestroy { extension MessengerDestroy {
public static func live(_ env: MessengerEnvironment) -> MessengerDestroy { public static func live(_ env: MessengerEnvironment) -> MessengerDestroy {
MessengerDestroy { MessengerDestroy {
try env.fileManager.removeDirectory(env.storageDir)
env.ud.set(nil) env.ud.set(nil)
env.e2e.set(nil) env.e2e.set(nil)
env.cMix.set(nil) env.cMix.set(nil)
try env.fileManager.removeDirectory(env.storageDir)
} }
} }
} }
......
...@@ -13,30 +13,39 @@ final class MessengerDestroyTests: XCTestCase { ...@@ -13,30 +13,39 @@ final class MessengerDestroyTests: XCTestCase {
var env: MessengerEnvironment = .unimplemented var env: MessengerEnvironment = .unimplemented
env.storageDir = storageDir env.storageDir = storageDir
env.fileManager.removeDirectory = { didRemoveDirectory.append($0) }
env.ud.set = { didSetUD.append($0) } env.ud.set = { didSetUD.append($0) }
env.e2e.set = { didSetE2E.append($0) } env.e2e.set = { didSetE2E.append($0) }
env.cMix.set = { didSetCMix.append($0) } env.cMix.set = { didSetCMix.append($0) }
env.fileManager.removeDirectory = { didRemoveDirectory.append($0) }
let destroy: MessengerDestroy = .live(env) let destroy: MessengerDestroy = .live(env)
try destroy() try destroy()
XCTAssertNoDifference(didRemoveDirectory, [storageDir])
XCTAssertNoDifference(didSetUD.map { $0 == nil }, [true]) XCTAssertNoDifference(didSetUD.map { $0 == nil }, [true])
XCTAssertNoDifference(didSetE2E.map { $0 == nil }, [true]) XCTAssertNoDifference(didSetE2E.map { $0 == nil }, [true])
XCTAssertNoDifference(didSetCMix.map { $0 == nil }, [true]) XCTAssertNoDifference(didSetCMix.map { $0 == nil }, [true])
XCTAssertNoDifference(didRemoveDirectory, [storageDir])
} }
func testRemoveDirectoryFailure() { func testRemoveDirectoryFailure() {
struct Error: Swift.Error, Equatable {} struct Error: Swift.Error, Equatable {}
let error = Error() let error = Error()
var didSetUD: [UserDiscovery?] = []
var didSetE2E: [E2E?] = []
var didSetCMix: [CMix?] = []
var env: MessengerEnvironment = .unimplemented var env: MessengerEnvironment = .unimplemented
env.ud.set = { didSetUD.append($0) }
env.e2e.set = { didSetE2E.append($0) }
env.cMix.set = { didSetCMix.append($0) }
env.fileManager.removeDirectory = { _ in throw error } env.fileManager.removeDirectory = { _ in throw error }
let destroy: MessengerDestroy = .live(env) let destroy: MessengerDestroy = .live(env)
XCTAssertThrowsError(try destroy()) { err in XCTAssertThrowsError(try destroy()) { err in
XCTAssertEqual(err as? Error, error) XCTAssertEqual(err as? Error, error)
} }
XCTAssertNoDifference(didSetUD.map { $0 == nil }, [true])
XCTAssertNoDifference(didSetE2E.map { $0 == nil }, [true])
XCTAssertNoDifference(didSetCMix.map { $0 == nil }, [true])
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment