Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subs are not getting Alamofire 5 parameters #322

Open
6 of 9 tasks
ricardorauber opened this issue Mar 26, 2020 · 2 comments
Open
6 of 9 tasks

Subs are not getting Alamofire 5 parameters #322

ricardorauber opened this issue Mar 26, 2020 · 2 comments

Comments

@ricardorauber
Copy link

New Issue Checklist

Environment

  • version of OHHTTPStubs: 9.0.0
  • integration method you are using:
    • Cocoapods
    • Carthage
    • submodule
    • other
  • version of the tool you use: 1.8.4

Issue Description

I am trying to use it in a project with Alamofire 5.0.5 and for some reason, it is not getting the parameters. I just tried the sample they use on their guide:

stub(condition: isMethodPOST() && isPath("/post")) { request in
	print("Method:", request.httpMethod ?? "-")
	print("Request:", request)
	print("Body:", request.httpBody ?? "-")
	return HTTPStubsResponse(jsonObject: ["result": true], statusCode: 200, headers: nil)
}
struct Login: Encodable {
	let email: String
	let password: String
}
let login = Login(email: "[email protected]", password: "testPassword")
AF.request("https://httpbin.org/post",
		   method: .post,
		   parameters: login,
		   encoder: JSONParameterEncoder.default).validate().responseString { response in
	print("response", response)
}
Complete output when you encounter the issue (if any)
Method: POST
Request: https://httpbin.org/post
Body: -
response success("{\"result\":true}")

When using a breakpoint and PO the request, this is what I get:

▿ https://httpbin.org/post
  ▿ url : Optional<URL>
    ▿ some : https://httpbin.org/post
      - _url : https://httpbin.org/post
  - cachePolicy : 0
  - timeoutInterval : 60.0
  - mainDocumentURL : nil
  - networkServiceType : __C.NSURLRequestNetworkServiceType
  - allowsCellularAccess : true
  ▿ httpMethod : Optional<String>
    - some : "POST"
  ▿ allHTTPHeaderFields : Optional<Dictionary<String, String>>
    ▿ some : 5 elements
      ▿ 0 : 2 elements
        - key : "Accept-Language"
        - value : "en;q=1.0"
      ▿ 1 : 2 elements
        - key : "Content-Type"
        - value : "application/json"
      ▿ 2 : 2 elements
        - key : "Content-Length"
        - value : "52"
      ▿ 3 : 2 elements
        - key : "User-Agent"
        - value : "dummy/1.0 (dummy; build:1; iOS 13.3.0) Alamofire/5.0.5"
      ▿ 4 : 2 elements
        - key : "Accept-Encoding"
        - value : "br;q=1.0, gzip;q=0.9, deflate;q=0.8"
  - httpBody : nil
  ▿ httpBodyStream : Optional<NSInputStream>
    - some : <__NSCFInputStream: 0x6000037d6ac0>
  - httpShouldHandleCookies : true
  - httpShouldUsePipelining : false

If I remove the stub, it works perfectly with the real server:

response success("{\n  \"args\": {}, \n  \"data\": \"{\\\"email\\\":\\\"[email protected]\\\",\\\"password\\\":\\\"testPassword\\\"}\", \n  \"files\": {}, \n  \"form\": {}, \n  \"headers\": {\n    \"Accept\": \"*/*\", \n    \"Accept-Encoding\": \"br;q=1.0, gzip;q=0.9, deflate;q=0.8\", \n    \"Accept-Language\": \"en;q=1.0\", \n    \"Content-Length\": \"52\", \n    \"Content-Type\": \"application/json\", \n    \"Host\": \"httpbin.org\", \n    \"X-Amzn-Trace-Id\": \"Root=1-5e7d1048-dd2e0ff448f3900c34e0ec90\"\n  }, \n  \"json\": {\n    \"email\": \"[email protected]\", \n    \"password\": \"testPassword\"\n  }, \n  \"origin\": \"187.39.113.117\", \n  \"url\": \"https://httpbin.org/post\"\n}\n")
@henrique-morbin-ifood
Copy link

Hi, I am facing the same issue now, and I'm not even using Alamofire.

@henrique-morbin-ifood
Copy link

I found it here. The request's body is actually on ohhttpStubs_HTTPBody.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants