json_api_assert
json_api_assert copied to clipboard
New API and library rename
New name: jassert or jassert
One function that conn can be pipped through. The following API:
jassert(conn)- creates a new map%{payload: JSON.parse(conn.body), status: conn.status}
This function should be the first connection used. It will parse the conns body into a payload object.
Will assert that the payload is a properly formed json-api payload.
Will assert that the proper response headers are included.
Will assert that jsonapi object exists with correct meta data in the root of the document.
The payload and the response status are then stored in a new map object that can be consumed by corresponding jassert functions.
jassert(payload, :data, data)
This function will assert that data is contained in the data object of the payload.
If data is a list it will iterate over each member of the list and assert each individually.
If payload.status == 201 the id of data WON'T be expected. The data object on the payload MUST return a single resource object otherwise assertion fails.
jassert(payload, :included, included_data)
This function will assert that included_data is contained in the included object of the payload. If included_data is a list it will iterate over each member of the list and assert each individually.
jassert(payload, {:data, :included}, data, :relationship, type, relationship_data)
This function will assert that relationship_data is setup as a relationship for the given data. The path is followed either down data or included. The type can be singular or plural.
If relationship_data is a list each member of the list is asserted.
jassert(payload, :links, link_data)
This function will assert that link_data exists in the root of the document.
jassert(payload, {:data, :included}, data, :links, link_data)
This function will assert that link_data exists in the data resource object on the proper path.
jassert(payload, {:data, :included}, data, :relationship, type, relationship_data, :links, link_data)
This function will assert that link_data exists on the given relationship for the given resource object.
jassert(payload, :meta, meta_data)
This function will assert that meta_data exists in the root of the document
jassert(payload, {:data, :included}, data, :meta, meta_data)
This function will assert that meta_data exists in the given resource object
jassert(payload, {:data, :included}, data, :relationship, type, relationship_data, :meta, meta_data)
This function will assert that meta_data exists on the given relationship for the given resource object
New name:
jassertorjassert
😆
This looks great. I really like the idea of jassert(conn). I was wondering how we would go about testing the status codes, and of course conn makes this so easy.
Will assert that jsonapi object exists with correct meta data in the root of the document.
This is currently optional according to spec. If we require it, I think we should also require the version to be included in the meta data.
Please let me know if I can help in any way.