Skip to content

Commit

Permalink
Merge pull request #44 from solid/n3-patch
Browse files Browse the repository at this point in the history
N3 patch
  • Loading branch information
michielbdejong authored Feb 7, 2022
2 parents e81aece + da68ecf commit 97eafae
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 50 deletions.
7 changes: 5 additions & 2 deletions patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ async function run(url) {
const result = await fetcher.fetch(url, {
method: 'PATCH',
headers: {
'Content-Type': 'application/sparql-update'
"Content-Type": "text/n3",
},
body: 'INSERT DATA { <#patch> <#to> <#create> . }'
body:
"@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#patch> <#to> <#create> .}.",
});
console.log(result.status, await result.text());
}
Expand Down
72 changes: 48 additions & 24 deletions test/surface/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,13 @@ describe('Create', () => {
});
const result = await solidLogicBob.fetch(`${containerUrl}new.txt`, {
method: 'PATCH',
body: 'INSERT DATA { <#hello> <#linked> <#world> . }',
headers: {
'Content-Type': 'application/sparql-update'
}
"Content-Type": "text/n3",
},
body:
"@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#hello> <#linked> <#world> .}.",
});
expect(responseCodeGroup(result.status)).toEqual('2xx');
});
Expand All @@ -318,10 +321,13 @@ describe('Create', () => {
});
const result = await solidLogicBob.fetch(`${containerUrl}new.txt`, {
method: 'PATCH',
body: 'INSERT DATA { <#hello> <#linked> <#world> . }',
headers: {
'Content-Type': 'application/sparql-update'
}
"Content-Type": "text/n3",
},
body:
"@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#hello> <#linked> <#world> .}.",
});
expect(responseCodeGroup(result.status)).toEqual('2xx');
});
Expand Down Expand Up @@ -350,10 +356,13 @@ describe('Create', () => {

const result = await solidLogicBob.fetch(`${containerUrl}new.txt`, {
method: 'PATCH',
body: 'INSERT DATA { <#hello> <#linked> <#world> . }',
headers: {
'Content-Type': 'application/sparql-update'
}
"Content-Type": "text/n3",
},
body:
"@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#hello> <#linked> <#world> .}.",
});
expect(result.status).toEqual(403);
});
Expand All @@ -380,10 +389,13 @@ describe('Create', () => {
});
const result = await solidLogicBob.fetch(`${containerUrl}new.txt`, {
method: 'PATCH',
body: 'INSERT DATA { <#hello> <#linked> <#world> . }',
headers: {
'Content-Type': 'application/sparql-update'
}
"Content-Type": "text/n3",
},
body:
"@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#hello> <#linked> <#world> .}.",
});
expect(result.status).toEqual(403);
});
Expand Down Expand Up @@ -539,10 +551,13 @@ describe('Create', () => {
});
const result = await solidLogicBob.fetch(`${containerUrl}nested/new.txt`, {
method: 'PATCH',
body: 'INSERT DATA { <#hello> <#linked> <#world> . }',
headers: {
'Content-Type': 'application/sparql-update'
}
"Content-Type": "text/n3",
},
body:
"@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#hello> <#linked> <#world> .}.",
});
expect(responseCodeGroup(result.status)).toEqual('2xx');
});
Expand All @@ -568,10 +583,13 @@ describe('Create', () => {
});
const result = await solidLogicBob.fetch(`${containerUrl}nested/new.txt`, {
method: 'PATCH',
body: 'INSERT DATA { <#hello> <#linked> <#world> . }',
headers: {
'Content-Type': 'application/sparql-update'
}
"Content-Type": "text/n3",
},
body:
"@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#hello> <#linked> <#world> .}.",
});
expect(responseCodeGroup(result.status)).toEqual('2xx');
});
Expand All @@ -598,10 +616,13 @@ describe('Create', () => {
});
const result = await solidLogicBob.fetch(`${containerUrl}nested/new.txt`, {
method: 'PATCH',
body: 'INSERT DATA { <#hello> <#linked> <#world> . }',
headers: {
'Content-Type': 'application/sparql-update'
}
"Content-Type": "text/n3",
},
body:
"@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#hello> <#linked> <#world> .}.",
});
expect(result.status).toEqual(403);
});
Expand All @@ -628,10 +649,13 @@ describe('Create', () => {
});
const result = await solidLogicBob.fetch(`${containerUrl}nested/new.txt`, {
method: 'PATCH',
body: 'INSERT DATA { <#hello> <#linked> <#world> . }',
headers: {
'Content-Type': 'application/sparql-update'
}
"Content-Type": "text/n3",
},
body:
"@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#hello> <#linked> <#world> .}.",
});
expect(result.status).toEqual(403);
});
Expand Down
73 changes: 49 additions & 24 deletions test/surface/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,17 @@ describe('Update', () => {
}
});
const headers = {
'Content-Type': 'application/sparql-update',
'Content-Type': 'text/n3',
};
if (etagInQuotes) {
headers['If-Match'] = etagInQuotes
}
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'INSERT DATA { <#how> <#are> <#you> . }',
body:
"@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#how> <#are> <#you> . }",
headers
});
expect(responseCodeGroup(result.status)).toEqual("2xx");
Expand Down Expand Up @@ -402,14 +405,16 @@ describe('Update', () => {
}
});
const headers = {
'Content-Type': 'application/sparql-update',
'Content-Type': 'application/text/n3',
};
if (etagInQuotes) {
headers['If-Match'] = etagInQuotes
}
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'INSERT DATA { <#how> <#are> <#you> . }',
body: "@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#how> <#are> <#you> . }",
headers
});
expect(responseCodeGroup(result.status)).toEqual("2xx");
Expand Down Expand Up @@ -437,14 +442,16 @@ describe('Update', () => {
}
});
const headers = {
'Content-Type': 'application/sparql-update',
'Content-Type': 'text/n3',
};
if (etagInQuotes) {
headers['If-Match'] = etagInQuotes
}
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'INSERT DATA { <#how> <#are> <#you> . }',
body: "@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#how> <#are> <#you> . }",
headers
});
expect(result.status).toEqual(403);
Expand Down Expand Up @@ -473,14 +480,16 @@ describe('Update', () => {
}
});
const headers = {
'Content-Type': 'application/sparql-update',
'Content-Type': 'text/n3',
};
if (etagInQuotes) {
headers['If-Match'] = etagInQuotes
}
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'INSERT DATA { <#how> <#are> <#you> . }',
body: "@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#how> <#are> <#you> . }",
headers
});
expect(responseCodeGroup(result.status)).toEqual("2xx");
Expand Down Expand Up @@ -509,14 +518,16 @@ describe('Update', () => {
}
});
const headers = {
'Content-Type': 'application/sparql-update',
'Content-Type': 'text/n3',
};
if (etagInQuotes) {
headers['If-Match'] = etagInQuotes
}
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'INSERT DATA { <#how> <#are> <#you> . }',
body: "@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#how> <#are> <#you> . }",
headers
});
expect(responseCodeGroup(result.status)).toEqual("2xx");
Expand Down Expand Up @@ -545,14 +556,16 @@ describe('Update', () => {
}
});
const headers = {
'Content-Type': 'application/sparql-update',
'Content-Type': 'text/n3',
};
if (etagInQuotes) {
headers['If-Match'] = etagInQuotes
}
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'INSERT DATA { <#how> <#are> <#you> . }',
body: "@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:inserts { <#how> <#are> <#you> . }",
headers
});
expect(result.status).toEqual(403);
Expand Down Expand Up @@ -585,9 +598,11 @@ describe('Update', () => {
});
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'DELETE DATA { <#hello> <#linked> <#world> . }',
body: "@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:deletes { <#hello> <#linked> <#world> . }",
headers: {
'Content-Type': 'application/sparql-update'
'Content-Type': 'text/n3'
}
});
expect(responseCodeGroup(result.status)).toEqual("2xx");
Expand Down Expand Up @@ -615,14 +630,16 @@ describe('Update', () => {
}
});
const headers = {
'Content-Type': 'application/sparql-update',
'Content-Type': 'text/n3',
};
if (etagInQuotes) {
headers['If-Match'] = etagInQuotes
}
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'DELETE DATA { <#hello> <#linked> <#world> . }',
body: "@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:deletes { <#hello> <#linked> <#world> . }",
headers
});
expect(result.status).toEqual(403);
Expand Down Expand Up @@ -651,14 +668,16 @@ describe('Update', () => {
}
});
const headers = {
'Content-Type': 'application/sparql-update',
'Content-Type': 'text/n3',
};
if (etagInQuotes) {
headers['If-Match'] = etagInQuotes
}
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'DELETE DATA { <#hello> <#linked> <#world> . }',
body: "@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:deletes { <#hello> <#linked> <#world> . }",
headers
});
expect(result.status).toEqual(403);
Expand Down Expand Up @@ -687,14 +706,16 @@ describe('Update', () => {
}
});
const headers = {
'Content-Type': 'application/sparql-update',
'Content-Type': 'text/n3',
};
if (etagInQuotes) {
headers['If-Match'] = etagInQuotes
}
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'DELETE DATA { <#hello> <#linked> <#world> . }',
body: "@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:deletes { <#hello> <#linked> <#world> . }",
headers
});
expect(responseCodeGroup(result.status)).toEqual("2xx");
Expand Down Expand Up @@ -723,14 +744,16 @@ describe('Update', () => {
}
});
const headers = {
'Content-Type': 'application/sparql-update',
'Content-Type': 'text/n3',
};
if (etagInQuotes) {
headers['If-Match'] = etagInQuotes
}
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'DELETE DATA { <#hello> <#linked> <#world> . }',
body: "@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:deletes { <#hello> <#linked> <#world> . }",
headers
});
expect(result.status).toEqual(403);
Expand Down Expand Up @@ -761,14 +784,16 @@ describe('Update', () => {
}
});
const headers = {
'Content-Type': 'application/sparql-update',
'Content-Type': 'text/n3',
};
if (etagInQuotes) {
headers['If-Match'] = etagInQuotes
}
const result = await solidLogicBob.fetch(resourceUrl, {
method: 'PATCH',
body: 'DELETE DATA { <#hello> <#linked> <#world> . }',
body: "@prefix solid: <http://www.w3.org/ns/solid/terms#>." +
"#patch a solid:InsertDeletePatch;" +
" solid:deletes { <#hello> <#linked> <#world> . }",
headers
});
expect(result.status).toEqual(403);
Expand Down

0 comments on commit 97eafae

Please sign in to comment.