Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test logging out #5878

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,9 @@ class AlertViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

view.accessibilityIdentifier = presentation.accessibilityIdentifier ?? .alertContainerView
view.backgroundColor = .black.withAlphaComponent(0.5)

let accessibilityIdentifier = presentation.accessibilityIdentifier ?? .alertContainerView
view.accessibilityIdentifier = accessibilityIdentifier

setContent()
setConstraints()
}
Expand Down
17 changes: 17 additions & 0 deletions ios/MullvadVPNUITests/AccountTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,21 @@ class AccountTests: LoggedOutUITestCase {
.verifyFailIconShown()
.waitForPageToBeShown() // Verify still on login page
}

func testLogOut() throws {
let newAccountNumber = try MullvadAPIWrapper().createAccount()
login(accountNumber: newAccountNumber)
XCTAssertEqual(try MullvadAPIWrapper().getDevices(newAccountNumber).count, 1)

HeaderBar(app)
.tapAccountButton()

AccountPage(app)
.tapLogOutButton()

LoginPage(app)

XCTAssertEqual(try MullvadAPIWrapper().getDevices(newAccountNumber).count, 0)
try MullvadAPIWrapper().deleteAccount(newAccountNumber)
}
}
20 changes: 10 additions & 10 deletions ios/MullvadVPNUITests/MullvadApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ struct InitMutableBufferError: Error {
let description = "Failed to allocate memory for mutable buffer"
}

struct Device {
let name: String
let id: UUID

init(device_struct: MullvadApiDevice) {
name = String(cString: device_struct.name_ptr)
id = UUID(uuid: device_struct.id)
}
}

/// - Warning: Do not change the `apiAddress` or the `hostname` after the time `MullvadApi.init` has been invoked
/// The Mullvad API crate is using a global static variable to store those. They will be initialized only once.
///
Expand Down Expand Up @@ -113,16 +123,6 @@ class MullvadApi {
mullvad_api_client_drop(clientContext)
}

struct Device {
let name: String
let id: UUID

init(device_struct: MullvadApiDevice) {
name = String(cString: device_struct.name_ptr)
id = UUID(uuid: device_struct.id)
}
}

class DeviceIterator {
private let backingIter: MullvadApiDeviceIterator

Expand Down
8 changes: 8 additions & 0 deletions ios/MullvadVPNUITests/Networking/MullvadAPIWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,12 @@ class MullvadAPIWrapper {
throw MullvadAPIError.requestError
}
}

func getDevices(_ account: String) throws -> [Device] {
do {
return try mullvadAPI.listDevices(forAccount: account)
} catch {
throw MullvadAPIError.requestError
}
}
}
Loading