Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/MemoryHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ MemoryStore.prototype.create = (request, newResource, callback) => {
status: '403',
code: 'EFORBIDDEN',
title: 'Requested resource already exists',
detail: `The requested resource already exists of type ${request.params.type} with id ${request.params.id}`
detail: `The requested resource already exists of type ${request.params.type} with id ${newResource.id}`
})
}
// Push the newResource into our in-memory store.
Expand Down
30 changes: 30 additions & 0 deletions test/post-resource-client-generated-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ describe('Testing jsonapi-server', () => {
done()
})
})

it('errors when creating resource with existing id', done => {
const existingId = 'cc5cca2e-0dd8-4b95-8cfc-a11230e73116'
const data = {
method: 'post',
url: 'http://localhost:16006/rest/people',
headers: {
'Content-Type': 'application/vnd.api+json'
},
body: JSON.stringify({
'data': {
'id': existingId,
'type': 'people',
'attributes': {
firstname: 'Harry',
lastname: 'Potter',
email: '[email protected]'
}
}
})
}
helpers.request(data, (err, res, json) => {
assert.equal(err, null)
json = helpers.validateError(json)
assert.equal(json.errors[0].detail, `The requested resource already exists of type people with id ${existingId}`, 'Expecting detail with correct type and id')
assert.equal(res.statusCode, '403', 'Expecting 403')

done()
})
})
})
})

Expand Down