func test409Error()

in source/UberRidesTests/RequestLayerTests.swift [120:151]


    func test409Error() {
        stub(condition: isHost("sandbox-api.uber.com")) { _ in
            let json = ["meta": ["surge_confirmation": ["href": "api.uber.com/v1/surge-confirmations/abc", "surge_confirmation_id": "abc"]]]
            return HTTPStubsResponse(jsonObject: json, statusCode: 409, headers: self.headers)
        }
        
        let expectation = self.expectation(description: "409 error response")
        let endpoint = Products.getProduct(productID: productID)
        guard let request = Request(session: client.session, endpoint: endpoint) else {
            XCTFail("Unable to create request")
            return
        }
        request.execute({ response in
            XCTAssertEqual(response.statusCode, 409)
            XCTAssertNotNil(response.error)
            XCTAssertTrue(response.error is UberClientError)
            XCTAssertNotNil(response.error!.meta)
            
                let meta = response.error!.meta! as! [String: [String: String]]
            XCTAssertEqual(meta["surge_confirmation"]!["href"], "api.uber.com/v1/surge-confirmations/abc")
            XCTAssertEqual(meta["surge_confirmation"]!["surge_confirmation_id"], "abc")
            
            expectation.fulfill()
        })
        
        waitForExpectations(timeout: timeout, handler: { error in
            if let error = error {
                print("Error: \(error.localizedDescription)")
            }
            request.cancelTasks()
        })
    }