venmo / DVR

Network testing for Swift
http://blog.soff.es/network-testing-in-swift-with-dvr
MIT License
651 stars 86 forks source link

Testing api failures #69

Closed OliverDimitrov closed 6 years ago

OliverDimitrov commented 7 years ago

Hi there, I'm using DVR, and so far I've managed successfully to create tests when api requests return success. But now I want to test the failure of the same requests. So I'm facing a problem when using DVR to test failures (401, 404 etc)..

When run for 2nd time (first time is to record the response), instead of failure callback, success callback is called with the error response inside of it. Any idea why?

Using Alamofire. Example code (creating and executing any request):

request.validate().responseJSON(completionHandler: {
    response in
    switch response.result {

         case .success(let JSON):
// This is what gets called instead of failure. Response code is 401 and the JSON contains error message.

              callback(true, JSON, nil)

         case .failure(let error):
              if let data = response.data, data.count > 0 {
                  let JSON = try! JSONSerialization.jsonObject(with: data, options: .allowFragments)
                  callback(false, JSON, error as NSError?)
              } else {
                  callback(false, nil, error as NSError?)
              }
     }
}).resume()
sethhoward commented 6 years ago

74 Related?

loudmouth commented 6 years ago

I think #74 is a duplicate issue and #80 should fix this.

eliperkins commented 6 years ago

This should be resolved by #75 and #80