Closed jcampbell closed 7 years ago
I can confirm @jcampbell issue as well. I wrote a small script for testing it using curl
and jq
.
The main difference is that the script adds an extra person before accessing the empty relationship in step 3. The script does that to ensure everything was working as expected before performing that step.
#!/usr/bin/env bash
set -ef -o pipefail
shopt -s expand_aliases
alias jsonapi='curl -sS -H "Accept: application/vnd.api+json" -H "Content-Type: application/vnd.api+json"'
# Assumes you have run python api.py
URL=http://localhost:5000
echo -n 'Database is clean: '
jsonapi $URL/persons | jq -e '.meta.count == 0'
echo -n 'Add Person 1 and links.related is as expected: '
jsonapi $URL/persons -X POST -d '{
"data": {
"type": "person",
"attributes": {
"name": "Person1"
}
}
}' | jq -e '.data.relationships.computers.links.related == "/persons/1/computers"'
echo -n 'Add Person 2 and links.related is as expected: '
jsonapi $URL/persons -X POST -d '{
"data": {
"type": "person",
"attributes": {
"name": "Person2"
}
}
}' | jq -e '.data.relationships.computers.links.related == "/persons/2/computers"'
# Access Person's 1 (empty) relationship with computers
echo -n 'Access Person 1 (empty) relationship with computers: '
jsonapi $URL/persons/1/relationships/computers | jq -e '.links.self == "/persons/1/relationships/computers"'
echo -n 'Add Person 3 and links.related is as expected: '
jsonapi $URL/persons -X POST -d '{
"data": {
"type": "person",
"attributes": {
"name": "Person3"
}
}
}' | jq -e '.data.relationships.computers.links.related == "/persons/3/computers"'
echo 'All tests passed.'
@sodre: thanks for confirming the issue and building a great patch set. Can get this merged in?
I can provide the following steps to reproduce, but I have not been able to understand yet what's causing the issue, so I wanted to open this ticket to flag it.
I have not investigated deeply enough to understand why this is happening (or tested outside of the example sqlite), but wanted to open the issue in hopes the author can identify the problem since it definitely doesn't seem to match the JSONAPI spec or desired behavior.