44 lines
1.3 KiB
Swift
44 lines
1.3 KiB
Swift
import XCTest
|
|
import AutoCat2
|
|
|
|
class ApiTests: XCTestCase {
|
|
|
|
private var api: Api!
|
|
|
|
override func setUpWithError() throws {
|
|
let sessionConfig = URLSessionConfiguration.default
|
|
sessionConfig.protocolClasses = [MockURLProtocol.self]
|
|
let session = URLSession(configuration: sessionConfig)
|
|
self.api = Api(session: session)
|
|
}
|
|
|
|
override func tearDownWithError() throws {
|
|
// Put teardown code here. This method is called after the invocation of each test method in the class.
|
|
}
|
|
|
|
func testLoginSuccess() async throws {
|
|
MockURLProtocol.responseType = MockResponseType.loginSuccess
|
|
let user = try await self.api.login(email: "", password: "")
|
|
XCTAssertTrue(!user.token.isEmpty)
|
|
}
|
|
|
|
func testLoginInvalidParams() async throws {
|
|
MockURLProtocol.responseType = MockResponseType.loginWrongCredentials
|
|
do {
|
|
_ = try await self.api.login(email: "", password: "")
|
|
} catch {
|
|
return
|
|
}
|
|
|
|
XCTFail("Exception expected")
|
|
}
|
|
|
|
// func testPerformanceExample() throws {
|
|
// // This is an example of a performance test case.
|
|
// self.measure {
|
|
// // Put the code you want to measure the time of here.
|
|
// }
|
|
// }
|
|
|
|
}
|