Commit 83bb3e4d authored by Jose Blaya's avatar Jose Blaya
Browse files

Create a method to clean the database to fix login tests

parent 0b39a978
......@@ -80,6 +80,11 @@ public protocol AccountProvider: class {
*/
func logout(_ callback: SuccessLibraryCallback?)
/**
Remove all data from the plain and secure internal database
*/
func cleanDatabase()
#if os(iOS)
/**
Lists the available plans with their corresponding product to purchase in order to get them.
......
......@@ -197,13 +197,7 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
guard isLoggedIn else {
preconditionFailure()
}
if let username = accessedDatabase.secure.username() {
accessedDatabase.secure.setPassword(nil, for: username)
accessedDatabase.secure.setUsername(nil)
accessedDatabase.secure.setToken(nil, for: accessedDatabase.secure.tokenKey(for: username))
}
accessedDatabase.plain.publicUsername = nil
accessedDatabase.plain.accountInfo = nil
cleanDatabase()
Macros.postNotification(.PIAAccountDidLogout)
callback?(nil)
}
......@@ -416,6 +410,19 @@ class DefaultAccountProvider: AccountProvider, ConfigurationAccess, DatabaseAcce
}
}
}
/**
Remove all data from the plain and secure internal database
*/
func cleanDatabase() {
if let username = accessedDatabase.secure.username() {
accessedDatabase.secure.setPassword(nil, for: username)
accessedDatabase.secure.setUsername(nil)
accessedDatabase.secure.setToken(nil, for: accessedDatabase.secure.tokenKey(for: username))
}
accessedDatabase.plain.publicUsername = nil
accessedDatabase.plain.accountInfo = nil
}
#endif
// MARK: WebServicesConsumer
......
......@@ -11,7 +11,6 @@ import Foundation
/// Simulates account-related operations
public class MockAccountProvider: AccountProvider, WebServicesConsumer {
/// Mocks the outcome of a sign-up operation.
///
/// - Seealso: `AccountProvider.signup(...)`
......@@ -170,6 +169,11 @@ public class MockAccountProvider: AccountProvider, WebServicesConsumer {
delegate.logout(callback)
}
/// :nodoc:
public func cleanDatabase() {
delegate.cleanDatabase()
}
#if os(iOS)
/// :nodoc:
public func listPlanProducts(_ callback: (([Plan : InAppProduct]?, Error?) -> Void)?) {
......
......@@ -311,7 +311,7 @@ protocol WelcomeCompletionDelegate: class {
}
class EphemeralAccountProvider: AccountProvider, ProvidersAccess, InAppAccess {
// XXX: we want legit web services calls, yet allow the option to mock them
private var webServices: WebServices? {
guard let accountProvider = accessedProviders.accountProvider as? WebServicesConsumer else {
......@@ -373,6 +373,10 @@ class EphemeralAccountProvider: AccountProvider, ProvidersAccess, InAppAccess {
func logout(_ callback: SuccessLibraryCallback?) {
fatalError("Not implemented")
}
func cleanDatabase() {
fatalError("Not implemented")
}
func listPlanProducts(_ callback: (([Plan : InAppProduct]?, Error?) -> Void)?) {
accessedProviders.accountProvider.listPlanProducts(callback)
......
......@@ -23,11 +23,13 @@ class AccountTests: XCTestCase {
Client.database = Client.Database(group: "group.com.privateinternetaccess").truncate()
Client.bootstrap()
Client.providers.accountProvider.cleanDatabase()
}
override func tearDown() {
super.tearDown()
unregisterNotifications()
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment