Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Return 201 when PATCH creates a new resource #1786

Merged
merged 2 commits into from
Aug 28, 2024
Merged
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
3 changes: 2 additions & 1 deletion lib/handlers/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ async function patchHandler (req, res, next) {
return writeGraph(graph, resource, ldp.resourceMapper.resolveFilePath(req.hostname), ldp.serverUri)
})

// Send the result to the client
// Send the status and result to the client
res.status(resourceExists ? 200 : 201)
res.send(result)
} catch (err) {
return next(err)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/acl-oidc-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
options.headers['content-type'] = 'application/sparql-update'
request.patch(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
assert.equal(response.statusCode, 201)
done()
})
})
Expand Down Expand Up @@ -616,7 +616,7 @@ describe('ACL with WebID+OIDC over HTTP', function () {
options.headers['content-type'] = 'application/sparql-update'
request.patch(options, function (error, response, body) {
assert.equal(error, null)
assert.equal(response.statusCode, 200)
assert.equal(response.statusCode, 201)
done()
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/integration/patch-sparql-update-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('PATCH through application/sparql-update', function () {
server.patch('/notExisting.ttl')
.set('content-type', 'application/sparql-update')
.send('INSERT DATA { :test :hello 456 .}')
.expect(200)
.expect(201)
.end(function (err, res, body) {
assert.equal(
read('sampleContainer/notExisting.ttl'),
Expand Down
10 changes: 5 additions & 5 deletions test/integration/patch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('PATCH through text/n3', () => {
patch: `<> a solid:InsertDeletePatch;
solid:inserts { <x> <y> <z>. }.`
}, { // expected:
status: 200,
status: 201,
text: 'Patch applied successfully',
result: '@prefix : </new.ttl#>.\n@prefix tim: </>.\n\ntim:x tim:y tim:z.\n\n'
}))
Expand All @@ -90,7 +90,7 @@ describe('PATCH through text/n3', () => {
patch: `<> a solid:InsertDeletePatch;
solid:inserts { <x> <y> <z>. }.`
}, { // expected:
status: 200,
status: 201,
text: 'Patch applied successfully',
// result: '{\n "@id": "/x",\n "/y": {\n "@id": "/z"\n }\n}'
result: `{
Expand All @@ -110,7 +110,7 @@ describe('PATCH through text/n3', () => {
patch: `<> a solid:InsertDeletePatch;
solid:inserts { <x> <y> <z>. }.`
}, { // expected:
status: 200,
status: 201,
text: 'Patch applied successfully',
result: `<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
Expand All @@ -126,7 +126,7 @@ describe('PATCH through text/n3', () => {
patch: `<> a solid:InsertDeletePatch;
solid:inserts { <x> <y> <z>. }.`
}, { // expected:
status: 200,
status: 201,
text: 'Patch applied successfully',
result: '@prefix : </new.n3#>.\n@prefix tim: </>.\n\ntim:x tim:y tim:z.\n\n'
}))
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('PATCH through text/n3', () => {
patch: `<> a solid:InsertDeletePatch;
solid:inserts { <x> <y> <z>. }.`
}, {
status: 200,
status: 201,
text: 'Patch applied successfully',
result: '@prefix : <#>.\n@prefix fol: <./>.\n\nfol:x fol:y fol:z.\n\n'
}))
Expand Down
Loading