From aa7dd427d2c41b34e8d30f5851b50804f20e7967 Mon Sep 17 00:00:00 2001 From: Niklas Date: Wed, 31 Jan 2024 10:23:09 +0100 Subject: [PATCH] Add log out test --- .../xcshareddata/swiftpm/Package.resolved | 22 ------------------- ios/MullvadVPNUITests/AccountTests.swift | 17 ++++++++++++++ ios/MullvadVPNUITests/MullvadApi.swift | 20 ++++++++--------- .../Networking/MullvadAPIWrapper.swift | 8 +++++++ 4 files changed, 35 insertions(+), 32 deletions(-) delete mode 100644 ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved diff --git a/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved deleted file mode 100644 index 02691892fed1..000000000000 --- a/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ /dev/null @@ -1,22 +0,0 @@ -{ - "pins" : [ - { - "identity" : "swift-log", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-log.git", - "state" : { - "revision" : "173f567a2dfec11d74588eea82cecea555bdc0bc", - "version" : "1.4.0" - } - }, - { - "identity" : "wireguard-apple", - "kind" : "remoteSourceControl", - "location" : "https://github.com/mullvad/wireguard-apple.git", - "state" : { - "revision" : "11a00c20dc03f2751db47e94f585c0778c7bde82" - } - } - ], - "version" : 2 -} diff --git a/ios/MullvadVPNUITests/AccountTests.swift b/ios/MullvadVPNUITests/AccountTests.swift index e12152291b01..b3b47dc858ff 100644 --- a/ios/MullvadVPNUITests/AccountTests.swift +++ b/ios/MullvadVPNUITests/AccountTests.swift @@ -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) + } } diff --git a/ios/MullvadVPNUITests/MullvadApi.swift b/ios/MullvadVPNUITests/MullvadApi.swift index a1a22b5c4031..6f84ac1976b6 100644 --- a/ios/MullvadVPNUITests/MullvadApi.swift +++ b/ios/MullvadVPNUITests/MullvadApi.swift @@ -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. /// @@ -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 diff --git a/ios/MullvadVPNUITests/Networking/MullvadAPIWrapper.swift b/ios/MullvadVPNUITests/Networking/MullvadAPIWrapper.swift index ba870b0ba7b8..b3d7332cedfa 100644 --- a/ios/MullvadVPNUITests/Networking/MullvadAPIWrapper.swift +++ b/ios/MullvadVPNUITests/Networking/MullvadAPIWrapper.swift @@ -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 + } + } }