Skip to content

Commit

Permalink
Create accounts using partner API when available
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasberglund authored and buggmagnet committed Sep 24, 2024
1 parent f0bb8b7 commit d5ef126
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
13 changes: 3 additions & 10 deletions ios/MullvadVPNUITests/AccountTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -33,7 +26,7 @@ class AccountTests: LoggedOutUITestCase {
}

func testDeleteAccount() throws {
let accountNumber = mullvadAPIWrapper.createAccount()
let accountNumber = createTemporaryAccountWithoutTime()

LoginPage(app)
.tapAccountNumberTextField()
Expand Down Expand Up @@ -99,7 +92,7 @@ class AccountTests: LoggedOutUITestCase {

func testLoginToAccountWithTooManyDevices() throws {
// Setup
let temporaryAccountNumber = mullvadAPIWrapper.createAccount()
let temporaryAccountNumber = createTemporaryAccountWithoutTime()
mullvadAPIWrapper.addDevices(5, account: temporaryAccountNumber)

// Teardown
Expand Down Expand Up @@ -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")

Expand Down
18 changes: 18 additions & 0 deletions ios/MullvadVPNUITests/Base/BaseUITestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d5ef126

Please sign in to comment.