Skip to content

Commit

Permalink
Merge pull request #1786 from nodeSolidServer/CxRes-patch-set-status-…
Browse files Browse the repository at this point in the history
…code

fix: Return 201 when PATCH creates a new resource
  • Loading branch information
jeff-zucker authored Aug 28, 2024
2 parents 843c771 + a69da13 commit f5b2b5c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
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

0 comments on commit f5b2b5c

Please sign in to comment.