Skip to content

Commit 138add1

Browse files
More descriptive fails for unsuccessful API requests
1 parent 49dcbd2 commit 138add1

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

ios/MullvadVPNUITests/Networking/MullvadAPIWrapper.swift

+5-15
Original file line numberDiff line numberDiff line change
@@ -86,48 +86,43 @@ class MullvadAPIWrapper {
8686

8787
func createAccount() -> String {
8888
var accountNumber = String()
89-
var requestError: Error?
9089
let requestCompletedExpectation = XCTestExpectation(description: "Create account request completed")
9190

9291
throttle {
9392
do {
9493
accountNumber = try self.mullvadAPI.createAccount()
9594
} catch {
96-
requestError = MullvadAPIError.requestError
95+
XCTFail("Failed to create account with error: \(error.localizedDescription)")
9796
}
9897

9998
requestCompletedExpectation.fulfill()
10099
}
101100

102101
let waitResult = XCTWaiter().wait(for: [requestCompletedExpectation], timeout: throttleWaitTimeout)
103102
XCTAssertEqual(waitResult, .completed, "Create account request completed")
104-
XCTAssertNil(requestError, "Create account error is nil")
105103

106104
return accountNumber
107105
}
108106

109107
func deleteAccount(_ accountNumber: String) {
110-
var requestError: Error?
111108
let requestCompletedExpectation = XCTestExpectation(description: "Delete account request completed")
112109

113110
throttle {
114111
do {
115112
try self.mullvadAPI.delete(account: accountNumber)
116113
} catch {
117-
requestError = MullvadAPIError.requestError
114+
XCTFail("Failed to delete account with error: \(error.localizedDescription)")
118115
}
119116

120117
requestCompletedExpectation.fulfill()
121118
}
122119

123120
let waitResult = XCTWaiter().wait(for: [requestCompletedExpectation], timeout: throttleWaitTimeout)
124121
XCTAssertEqual(waitResult, .completed, "Delete account request completed")
125-
XCTAssertNil(requestError, "Delete account error is nil")
126122
}
127123

128124
/// Add another device to specified account. A dummy WireGuard key will be generated.
129125
func addDevice(_ account: String) {
130-
var addDeviceError: Error?
131126
let requestCompletedExpectation = XCTestExpectation(description: "Add device request completed")
132127

133128
throttle {
@@ -136,15 +131,14 @@ class MullvadAPIWrapper {
136131
do {
137132
try self.mullvadAPI.addDevice(forAccount: account, publicKey: devicePublicKey)
138133
} catch {
139-
addDeviceError = MullvadAPIError.requestError
134+
XCTFail("Failed to add device with error: \(error.localizedDescription)")
140135
}
141136

142137
requestCompletedExpectation.fulfill()
143138
}
144139

145140
let waitResult = XCTWaiter().wait(for: [requestCompletedExpectation], timeout: throttleWaitTimeout)
146141
XCTAssertEqual(waitResult, .completed, "Add device request completed")
147-
XCTAssertNil(addDeviceError, "Add device error is nil")
148142
}
149143

150144
/// Add multiple devices to specified account. Dummy WireGuard keys will be generated.
@@ -157,45 +151,41 @@ class MullvadAPIWrapper {
157151

158152
func getAccountExpiry(_ account: String) throws -> Date {
159153
var accountExpiryDate: Date = .distantPast
160-
var requestError: Error?
161154
let requestCompletedExpectation = XCTestExpectation(description: "Get account expiry request completed")
162155

163156
throttle {
164157
do {
165158
let accountExpiryTimestamp = Double(try self.mullvadAPI.getExpiry(forAccount: account))
166159
accountExpiryDate = Date(timeIntervalSince1970: accountExpiryTimestamp)
167160
} catch {
168-
requestError = MullvadAPIError.requestError
161+
XCTFail("Failed to get account expiry with error: \(error.localizedDescription)")
169162
}
170163

171164
requestCompletedExpectation.fulfill()
172165
}
173166

174167
let waitResult = XCTWaiter().wait(for: [requestCompletedExpectation], timeout: throttleWaitTimeout)
175168
XCTAssertEqual(waitResult, .completed, "Get account expiry request completed")
176-
XCTAssertNil(requestError, "Get account expiry error is nil")
177169

178170
return accountExpiryDate
179171
}
180172

181173
func getDevices(_ account: String) throws -> [Device] {
182174
var devices: [Device] = []
183-
var requestError: Error?
184175
let requestCompletedExpectation = XCTestExpectation(description: "Get devices request completed")
185176

186177
throttle {
187178
do {
188179
devices = try self.mullvadAPI.listDevices(forAccount: account)
189180
} catch {
190-
requestError = MullvadAPIError.requestError
181+
XCTFail("Failed to get devices with error: \(error.localizedDescription)")
191182
}
192183

193184
requestCompletedExpectation.fulfill()
194185
}
195186

196187
let waitResult = XCTWaiter.wait(for: [requestCompletedExpectation], timeout: throttleWaitTimeout)
197188
XCTAssertEqual(waitResult, .completed, "Get devices request completed")
198-
XCTAssertNil(requestError, "Get devices error is nil")
199189

200190
return devices
201191
}

0 commit comments

Comments
 (0)