vadymmarkov / Malibu

:surfer: Malibu is a networking library built on promises
https://vadymmarkov.github.io
Other
414 stars 39 forks source link

Unable to change response code when mocking with JSON #100

Closed daneov closed 6 years ago

daneov commented 6 years ago

In our backend we employ JSON error responses to inform the client of what went wrong exactly. This can be a missing field (400), which would then contain a body like:

{
    "error_code" : "missing_field_y"
}

In order to verify that the app correctly passes this information, I'm writing a test to verify that the parsing goes correctly.

However, when creating a Mock object the following way, it seems to default to a successful response.

let provider = MockProvider<HTTPMethod> { _ in
            return Mock(json: ["error_code": errorCode])
        }

Do you have any suggestions on how to work around this?

(P.S. It's also inconvenient that passing data encoded with Swift 4's JSONEncoder is not working but results in an invalid_api_response)

vadymmarkov commented 6 years ago

Should be fixed now.