46 lines
1.4 KiB
Swift
46 lines
1.4 KiB
Swift
import XCTest
|
|
import AutoCatCore
|
|
|
|
class ApiTests: XCTestCase {
|
|
|
|
private var api: ApiProtocol!
|
|
|
|
private let testLogin = "test@gmail.com"
|
|
private let testPassword = "12345"
|
|
|
|
override func setUpWithError() throws {
|
|
MockURLProtocol.baseUrl = Constants.baseUrl
|
|
MockURLProtocol.apiMethodMocks = [
|
|
LoginMethodMock(httpMethod: "POST", path: "user/login", login: self.testLogin, password: self.testPassword)
|
|
]
|
|
|
|
let sessionConfig = URLSessionConfiguration.default
|
|
sessionConfig.protocolClasses = [MockURLProtocol.self]
|
|
let session = URLSession(configuration: sessionConfig)
|
|
self.api = Api(session: session)
|
|
}
|
|
|
|
override func tearDownWithError() throws {
|
|
MockURLProtocol.baseUrl = ""
|
|
MockURLProtocol.apiMethodMocks = []
|
|
}
|
|
|
|
func testLoginSuccess() async throws {
|
|
let user = try await self.api.login(email: self.testLogin, password: self.testPassword)
|
|
XCTAssertTrue(!user.token.isEmpty)
|
|
}
|
|
|
|
func testLoginInvalidParams() async throws {
|
|
do {
|
|
_ = try await self.api.login(email: "", password: "")
|
|
} catch let error as ApiError {
|
|
XCTAssertTrue(error == .invalidLoginOrPassword)
|
|
return
|
|
} catch {
|
|
XCTFail("Wrong exception type")
|
|
}
|
|
|
|
XCTFail("Exception expected")
|
|
}
|
|
}
|