Add PromiseKit dependency

- Added PromiseKit dependency
This commit is contained in:
2018-11-15 22:08:00 -04:00
parent 2689d86c18
commit be7b6b5881
541 changed files with 46282 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
import PMKAlamofire
import OHHTTPStubs
import PromiseKit
import XCTest
class AlamofireTests: XCTestCase {
func test() {
let json: NSDictionary = ["key1": "value1", "key2": ["value2A", "value2B"]]
OHHTTPStubs.stubRequests(passingTest: { $0.url!.host == "example.com" }) { _ in
return OHHTTPStubsResponse(jsonObject: json, statusCode: 200, headers: nil)
}
let ex = expectation(description: "")
let rq = Alamofire.request("http://example.com", method: .get).responseJSON().done { rsp in
XCTAssertEqual(json, rsp.json as? NSDictionary)
ex.fulfill()
}
waitForExpectations(timeout: 1)
}
override func tearDown() {
OHHTTPStubs.removeAllStubs()
}
#if swift(>=3.2)
private struct Fixture: Decodable {
let key1: String
let key2: [String]
}
func testDecodable1() {
func getFixture() -> Promise<Fixture> {
return Alamofire.request("http://example.com", method: .get).responseDecodable(queue: nil)
}
let json: NSDictionary = ["key1": "value1", "key2": ["value2A", "value2B"]]
OHHTTPStubs.stubRequests(passingTest: { $0.url!.host == "example.com" }) { _ in
return OHHTTPStubsResponse(jsonObject: json, statusCode: 200, headers: nil)
}
let ex = expectation(description: "")
getFixture().done { fixture in
XCTAssert(fixture.key1 == "value1", "Value1 found")
ex.fulfill()
}
waitForExpectations(timeout: 1)
}
func testDecodable2() {
let json: NSDictionary = ["key1": "value1", "key2": ["value2A", "value2B"]]
OHHTTPStubs.stubRequests(passingTest: { $0.url!.host == "example.com" }) { _ in
return OHHTTPStubsResponse(jsonObject: json, statusCode: 200, headers: nil)
}
let ex = expectation(description: "")
firstly {
Alamofire.request("http://example.com", method: .get).responseDecodable(Fixture.self)
}.done { fixture in
XCTAssert(fixture.key1 == "value1", "Value1 found")
ex.fulfill()
}
waitForExpectations(timeout: 1)
}
#endif
}