Error messages (expected response with status 422, got: 201) when running tests

The root problem here is that User.changeset doesn’t require any fields, so sending it nils won’t cause it to be invalid.

HOWEVER

There are several other layers missing as well:

  • if there were validation errors, the code in the controller’s create function will make it fall-through and return {:error, changeset}. Do you have a fallback controller set up?

  • phoenix_swagger can help with this, but only if it’s correctly configured and enabled:

    • the name of the parameter create expects is user not body, the parameters block should start user(:body, Schema.ref(...)
    • the validations need to be wired up, either through the PhoenixSwagger.Plug.Validate plug or by directly calling PhoenixSwagger.ConnValidator.validate! directly.