vadymmarkov / Malibu

:surfer: Malibu is a networking library built on promises

Home Page:https://vadymmarkov.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to change response code when mocking with JSON

daneov opened this issue · comments

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)

Should be fixed now.