From b9c7fac96744fc8105d9d33d5227ce6c0562fef6 Mon Sep 17 00:00:00 2001 From: Niklas Berglund Date: Tue, 10 Sep 2024 16:30:18 +0200 Subject: [PATCH] Create accounts using partner API when available --- ios/MullvadVPNUITests/AccountTests.swift | 13 +++---------- .../Base/BaseUITestCase.swift | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ios/MullvadVPNUITests/AccountTests.swift b/ios/MullvadVPNUITests/AccountTests.swift index 8b6814b4d0ea..a1fbda5a1ca5 100644 --- a/ios/MullvadVPNUITests/AccountTests.swift +++ b/ios/MullvadVPNUITests/AccountTests.swift @@ -9,13 +9,6 @@ import XCTest class AccountTests: LoggedOutUITestCase { - lazy var mullvadAPIWrapper: MullvadAPIWrapper = { - do { - // swiftlint:disable:next force_try - return try! MullvadAPIWrapper() - } - }() - override func setUpWithError() throws { continueAfterFailure = false @@ -33,7 +26,7 @@ class AccountTests: LoggedOutUITestCase { } func testDeleteAccount() throws { - let accountNumber = mullvadAPIWrapper.createAccount() + let accountNumber = createTemporaryAccountWithoutTime() LoginPage(app) .tapAccountNumberTextField() @@ -99,7 +92,7 @@ class AccountTests: LoggedOutUITestCase { func testLoginToAccountWithTooManyDevices() throws { // Setup - let temporaryAccountNumber = mullvadAPIWrapper.createAccount() + let temporaryAccountNumber = createTemporaryAccountWithoutTime() mullvadAPIWrapper.addDevices(5, account: temporaryAccountNumber) // Teardown @@ -133,7 +126,7 @@ class AccountTests: LoggedOutUITestCase { } func testLogOut() throws { - let newAccountNumber = mullvadAPIWrapper.createAccount() + let newAccountNumber = createTemporaryAccountWithoutTime() login(accountNumber: newAccountNumber) XCTAssertEqual(try mullvadAPIWrapper.getDevices(newAccountNumber).count, 1, "Account has one device") diff --git a/ios/MullvadVPNUITests/Base/BaseUITestCase.swift b/ios/MullvadVPNUITests/Base/BaseUITestCase.swift index 0df61d39f235..e7ef66f0fd55 100644 --- a/ios/MullvadVPNUITests/Base/BaseUITestCase.swift +++ b/ios/MullvadVPNUITests/Base/BaseUITestCase.swift @@ -42,8 +42,16 @@ class BaseUITestCase: XCTestCase { .infoDictionary?["IOSDevicePinCode"] as! String let attachAppLogsOnFailure = Bundle(for: BaseUITestCase.self) .infoDictionary?["AttachAppLogsOnFailure"] as! String == "1" + let partnerApiToken = Bundle(for: BaseUITestCase.self).infoDictionary?["PartnerApiToken"] as? String // swiftlint:enable force_cast + lazy var mullvadAPIWrapper: MullvadAPIWrapper = { + do { + // swiftlint:disable:next force_try + return try! MullvadAPIWrapper() + } + }() + static func testDeviceIsIPad() -> Bool { if let testDeviceIsIPad = Bundle(for: BaseUITestCase.self).infoDictionary?["TestDeviceIsIPad"] as? String { return testDeviceIsIPad == "1" @@ -80,6 +88,16 @@ class BaseUITestCase: XCTestCase { } } + /// Create temporary account without time. Will be created using partner API if token is configured, else falling back to app API + func createTemporaryAccountWithoutTime() -> String { + if let partnerApiToken { + let partnerAPIClient = PartnerAPIClient() + return partnerAPIClient.createAccount() + } else { + return mullvadAPIWrapper.createAccount() + } + } + /// Get an account number without time. If an account without time is specified in the configuration file that account will be used, else a temporary account will be created. func getAccountWithoutTime() -> String { if let configuredAccountWithoutTime = bundleNoTimeAccountNumber, !configuredAccountWithoutTime.isEmpty {