mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Do not generate empty INSERT graph.
Fixes https://github.com/solid/community-server/issues/383
This commit is contained in:
parent
c2b189184b
commit
0ecbffa885
@ -238,8 +238,10 @@ export class SparqlDataAccessor implements DataAccessor {
|
||||
if (triples) {
|
||||
// This needs to be first so it happens before the insert
|
||||
updates.unshift(this.sparqlUpdateDeleteAll(name));
|
||||
if (triples.length > 0) {
|
||||
insert.push(this.sparqlUpdateGraph(name, triples));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
updates,
|
||||
|
@ -190,6 +190,25 @@ describe('A SparqlDataAccessor', (): void => {
|
||||
]));
|
||||
});
|
||||
|
||||
it('overwrites the data and metadata when writing an empty resource.', async(): Promise<void> => {
|
||||
metadata = new RepresentationMetadata('http://test.com/container/resource',
|
||||
{ [RDF.type]: [ toNamedNode(LDP.Resource) ]});
|
||||
const empty = guardedStreamFrom([]);
|
||||
await expect(accessor.writeDocument({ path: 'http://test.com/container/resource' }, empty, metadata))
|
||||
.resolves.toBeUndefined();
|
||||
|
||||
expect(fetchUpdate).toHaveBeenCalledTimes(1);
|
||||
expect(fetchUpdate.mock.calls[0][0]).toBe(endpoint);
|
||||
expect(simplifyQuery(fetchUpdate.mock.calls[0][1])).toBe(simplifyQuery([
|
||||
'DELETE WHERE { GRAPH <http://test.com/container/resource> { ?s ?p ?o. } };',
|
||||
'DELETE WHERE { GRAPH <meta:http://test.com/container/resource> { ?s ?p ?o. } };',
|
||||
'INSERT DATA {',
|
||||
' GRAPH <meta:http://test.com/container/resource> { <http://test.com/container/resource> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/ldp#Resource>. }',
|
||||
' GRAPH <http://test.com/container/> { <http://test.com/container/> <http://www.w3.org/ns/ldp#contains> <http://test.com/container/resource>. }',
|
||||
'}',
|
||||
]));
|
||||
});
|
||||
|
||||
it('removes all references when deleting a resource.', async(): Promise<void> => {
|
||||
metadata = new RepresentationMetadata('http://test.com/container/',
|
||||
{ [RDF.type]: [ toNamedNode(LDP.Resource), toNamedNode(LDP.Container) ]});
|
||||
|
Loading…
x
Reference in New Issue
Block a user