Browse Source

Adding POST request JSON response test

Mattt Thompson 11 years ago
parent
commit
445a4ec908
1 changed files with 21 additions and 1 deletions
  1. 21 1
      Tests/ResponseTests.swift

+ 21 - 1
Tests/ResponseTests.swift

@@ -25,7 +25,7 @@ import Alamofire
 import XCTest
 
 class AlamofireJSONResponseTestCase: XCTestCase {
-    func testJSONResponse() {
+    func testGETRequestJSONResponse() {
         let URL = "http://httpbin.org/get"
         let expectation = expectationWithDescription("\(URL)")
 
@@ -44,4 +44,24 @@ class AlamofireJSONResponseTestCase: XCTestCase {
             XCTAssertNil(error, "\(error)")
         }
     }
+
+    func testPOSTRequestJSONResponse() {
+        let URL = "http://httpbin.org/post"
+        let expectation = expectationWithDescription("\(URL)")
+
+        Alamofire.request(.POST, URL, parameters: ["foo": "bar"])
+            .responseJSON { (request, response, JSON, error) in
+                expectation.fulfill()
+                XCTAssertNotNil(request, "request should not be nil")
+                XCTAssertNotNil(response, "response should not be nil")
+                XCTAssertNotNil(JSON, "JSON should not be nil")
+                XCTAssertNil(error, "error should be nil")
+
+                XCTAssertEqual(JSON!["form"] as NSObject, ["foo": "bar"], "args should be equal")
+        }
+
+        waitForExpectationsWithTimeout(10) { (error) in
+            XCTAssertNil(error, "\(error)")
+        }
+    }
 }