fix: Allow overwriting and deleting root container in SparqlDataAccessor

This commit is contained in:
Joachim Van Herwegen
2020-12-11 15:32:42 +01:00
parent 13061e35b9
commit fc8540f553
2 changed files with 60 additions and 16 deletions

View File

@@ -172,6 +172,24 @@ describe('A SparqlDataAccessor', (): void => {
]));
});
it('does not write containment triples when writing to a root container.', async(): Promise<void> => {
metadata = new RepresentationMetadata({ path: 'http://test.com/' },
{ [RDF.type]: [ toNamedNode(LDP.Resource), toNamedNode(LDP.Container) ]});
await expect(accessor.writeContainer({ path: 'http://test.com/' }, 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 <meta:http://test.com/> { ?s ?p ?o. } };',
'INSERT DATA {',
' GRAPH <meta:http://test.com/> {',
' <http://test.com/> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/ldp#Resource>.',
' <http://test.com/> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/ldp#Container>.',
' }',
'}',
]));
});
it('overwrites the data and metadata when writing a resource and updates parent.', async(): Promise<void> => {
metadata = new RepresentationMetadata({ path: 'http://test.com/container/resource' },
{ [RDF.type]: [ toNamedNode(LDP.Resource) ]});
@@ -224,6 +242,19 @@ describe('A SparqlDataAccessor', (): void => {
]));
});
it('does not try to remove containment triples when deleting a root container.', async(): Promise<void> => {
metadata = new RepresentationMetadata({ path: 'http://test.com/' },
{ [RDF.type]: [ toNamedNode(LDP.Resource), toNamedNode(LDP.Container) ]});
await expect(accessor.deleteResource({ path: 'http://test.com/' })).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/> { ?s ?p ?o. } };',
'DELETE WHERE { GRAPH <meta:http://test.com/> { ?s ?p ?o. } }',
]));
});
it('errors when trying to write to a metadata document.', async(): Promise<void> => {
await expect(accessor.writeDocument({ path: 'meta:http://test.com/container/resource' }, data, metadata))
.rejects.toThrow(new ConflictHttpError('Not allowed to create NamedNodes with the metadata extension.'));