fixes two issues found: couldn't post through related; returned wrong id #385
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes two separate but coupled issues I found while using the package. It started by me not being able to create related resources through the spec-approved path of
:parent_type/:parent_id/relationships/:relation_type
with a payload of{"data":[{"id":"ID","type":"RELATION"}]}
. It appears that while the code converts the keys to atoms, it was actually checking for the string version of the key. Furthermore, any request containing ameta
tag failed.While creating the tests that verified the actual fix for that issue, another issue presented itself: when creating a related resource, the server responded with the correct
type
but the wrongid
. My first thought was it was returning the join table id of the related resource but I actually now think it was returning the id of the parent. Either way, I also fixed the issue and it now returns the correcttype
/id
combination.While I was at it, I also added explicit tests for the PATCH and DELETE relationships flow as well. While it passes the tests as written, I am unsure about what actually the DELETE response body should contain.
Based on my reading of the spec1, I think the body should be empty. And I'm not sure it is expected to return the remaining related resources. I'm looking for your direction here, for sure.Based on a re-read of the correct section of the spec2, I think what we have in here is correct.Disclaimer: AI was used to track down, fix, and test these bugs. As is usually the case, a lot of steering had to be done to get it to a spot where I was comfortable opening a PR with the code it helped produce. I tried to follow other patterns found in this repo but feel free to massage it (or ask me to) to get it more in line.
Contributor checklist
Leave anything that you believe does not apply unchecked.
Footnotes
https://jsonapi.org/format/#crud-deleting-responses-200 ↩
https://jsonapi.org/format/#crud-updating-relationship-responses-200 ↩