mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
change: Make RepresentationMetadata accept a ResourceIdentifier.
Closes https://github.com/solid/community-server/issues/388
This commit is contained in:
committed by
Joachim Van Herwegen
parent
6ee56a6d67
commit
accfc2e58d
@@ -119,7 +119,7 @@ describe('A FileDataAccessor', (): void => {
|
||||
|
||||
const childQuads = metadata.quads().filter((quad): boolean =>
|
||||
quad.subject.value === `${base}container/resource`);
|
||||
const childMetadata = new RepresentationMetadata(`${base}container/resource`).addQuads(childQuads);
|
||||
const childMetadata = new RepresentationMetadata({ path: `${base}container/resource` }).addQuads(childQuads);
|
||||
expect(childMetadata.get(RDF.type)?.value).toBe(LDP.Resource);
|
||||
expect(childMetadata.get(POSIX.size)).toEqualRdfTerm(toTypedLiteral('data'.length, XSD.integer));
|
||||
expect(childMetadata.get(DCTERMS.modified)).toEqualRdfTerm(toTypedLiteral(now.toISOString(), XSD.dateTime));
|
||||
@@ -160,7 +160,8 @@ describe('A FileDataAccessor', (): void => {
|
||||
});
|
||||
|
||||
it('writes metadata to the corresponding metadata file.', async(): Promise<void> => {
|
||||
metadata = new RepresentationMetadata(`${base}res.ttl`, { [CONTENT_TYPE]: 'text/turtle', likes: 'apples' });
|
||||
metadata = new RepresentationMetadata({ path: `${base}res.ttl` },
|
||||
{ [CONTENT_TYPE]: 'text/turtle', likes: 'apples' });
|
||||
await expect(accessor.writeDocument({ path: `${base}res.ttl` }, data, metadata)).resolves.toBeUndefined();
|
||||
expect(cache.data['res.ttl']).toBe('data');
|
||||
expect(cache.data['res.ttl.meta']).toMatch(`<${base}res.ttl> <likes> "apples".`);
|
||||
@@ -266,21 +267,21 @@ describe('A FileDataAccessor', (): void => {
|
||||
});
|
||||
|
||||
it('writes metadata to the corresponding metadata file.', async(): Promise<void> => {
|
||||
metadata = new RepresentationMetadata(`${base}container/`, { likes: 'apples' });
|
||||
metadata = new RepresentationMetadata({ path: `${base}container/` }, { likes: 'apples' });
|
||||
await expect(accessor.writeContainer({ path: `${base}container/` }, metadata)).resolves.toBeUndefined();
|
||||
expect(cache.data.container).toEqual({ '.meta': expect.stringMatching(`<${base}container/> <likes> "apples".`) });
|
||||
});
|
||||
|
||||
it('overwrites existing metadata.', async(): Promise<void> => {
|
||||
cache.data.container = { '.meta': `<${base}container/> <likes> "pears".` };
|
||||
metadata = new RepresentationMetadata(`${base}container/`, { likes: 'apples' });
|
||||
metadata = new RepresentationMetadata({ path: `${base}container/` }, { likes: 'apples' });
|
||||
await expect(accessor.writeContainer({ path: `${base}container/` }, metadata)).resolves.toBeUndefined();
|
||||
expect(cache.data.container).toEqual({ '.meta': expect.stringMatching(`<${base}container/> <likes> "apples".`) });
|
||||
});
|
||||
|
||||
it('does not write metadata that is stored by the file system.', async(): Promise<void> => {
|
||||
metadata = new RepresentationMetadata(
|
||||
`${base}container/`,
|
||||
{ path: `${base}container/` },
|
||||
{ [RDF.type]: [ toNamedNode(LDP.BasicContainer), toNamedNode(LDP.Resource) ]},
|
||||
);
|
||||
await expect(accessor.writeContainer({ path: `${base}container/` }, metadata)).resolves.toBeUndefined();
|
||||
|
||||
@@ -86,9 +86,10 @@ describe('An InMemoryDataAccessor', (): void => {
|
||||
});
|
||||
|
||||
it('adds stored metadata when requesting document metadata.', async(): Promise<void> => {
|
||||
const inputMetadata = new RepresentationMetadata(`${base}resource`, { [RDF.type]: toNamedNode(LDP.Resource) });
|
||||
await accessor.writeDocument({ path: `${base}resource` }, data, inputMetadata);
|
||||
metadata = await accessor.getMetadata({ path: `${base}resource` });
|
||||
const identifier = { path: `${base}resource` };
|
||||
const inputMetadata = new RepresentationMetadata(identifier, { [RDF.type]: toNamedNode(LDP.Resource) });
|
||||
await accessor.writeDocument(identifier, data, inputMetadata);
|
||||
metadata = await accessor.getMetadata(identifier);
|
||||
expect(metadata.identifier.value).toBe(`${base}resource`);
|
||||
const quads = metadata.quads();
|
||||
expect(quads).toHaveLength(1);
|
||||
@@ -96,10 +97,11 @@ describe('An InMemoryDataAccessor', (): void => {
|
||||
});
|
||||
|
||||
it('adds stored metadata when requesting container metadata.', async(): Promise<void> => {
|
||||
const inputMetadata = new RepresentationMetadata(`${base}container/`, { [RDF.type]: toNamedNode(LDP.Container) });
|
||||
await accessor.writeContainer({ path: `${base}container/` }, inputMetadata);
|
||||
const identifier = { path: `${base}container/` };
|
||||
const inputMetadata = new RepresentationMetadata(identifier, { [RDF.type]: toNamedNode(LDP.Container) });
|
||||
await accessor.writeContainer(identifier, inputMetadata);
|
||||
|
||||
metadata = await accessor.getMetadata({ path: `${base}container/` });
|
||||
metadata = await accessor.getMetadata(identifier);
|
||||
expect(metadata.identifier.value).toBe(`${base}container/`);
|
||||
const quads = metadata.quads();
|
||||
expect(quads).toHaveLength(1);
|
||||
@@ -107,8 +109,9 @@ describe('An InMemoryDataAccessor', (): void => {
|
||||
});
|
||||
|
||||
it('can overwrite the metadata of an existing container without overwriting children.', async(): Promise<void> => {
|
||||
const inputMetadata = new RepresentationMetadata(`${base}container/`, { [RDF.type]: toNamedNode(LDP.Container) });
|
||||
await accessor.writeContainer({ path: `${base}container/` }, inputMetadata);
|
||||
const identifier = { path: `${base}container/` };
|
||||
const inputMetadata = new RepresentationMetadata(identifier, { [RDF.type]: toNamedNode(LDP.Container) });
|
||||
await accessor.writeContainer(identifier, inputMetadata);
|
||||
const resourceMetadata = new RepresentationMetadata();
|
||||
await accessor.writeDocument(
|
||||
{ path: `${base}container/resource` }, data, resourceMetadata,
|
||||
@@ -116,9 +119,9 @@ describe('An InMemoryDataAccessor', (): void => {
|
||||
|
||||
const newMetadata = new RepresentationMetadata(inputMetadata);
|
||||
newMetadata.add(RDF.type, toNamedNode(LDP.BasicContainer));
|
||||
await accessor.writeContainer({ path: `${base}container/` }, newMetadata);
|
||||
await accessor.writeContainer(identifier, newMetadata);
|
||||
|
||||
metadata = await accessor.getMetadata({ path: `${base}container/` });
|
||||
metadata = await accessor.getMetadata(identifier);
|
||||
expect(metadata.identifier.value).toBe(`${base}container/`);
|
||||
const quads = metadata.quads();
|
||||
expect(quads).toHaveLength(3);
|
||||
|
||||
@@ -152,7 +152,7 @@ describe('A SparqlDataAccessor', (): void => {
|
||||
});
|
||||
|
||||
it('overwrites the metadata when writing a container and updates parent.', async(): Promise<void> => {
|
||||
metadata = new RepresentationMetadata('http://test.com/container/',
|
||||
metadata = new RepresentationMetadata({ path: 'http://test.com/container/' },
|
||||
{ [RDF.type]: [ toNamedNode(LDP.Resource), toNamedNode(LDP.Container) ]});
|
||||
await expect(accessor.writeContainer({ path: 'http://test.com/container/' }, metadata)).resolves.toBeUndefined();
|
||||
|
||||
@@ -171,7 +171,7 @@ describe('A SparqlDataAccessor', (): void => {
|
||||
});
|
||||
|
||||
it('overwrites the data and metadata when writing a resource and updates parent.', async(): Promise<void> => {
|
||||
metadata = new RepresentationMetadata('http://test.com/container/resource',
|
||||
metadata = new RepresentationMetadata({ path: 'http://test.com/container/resource' },
|
||||
{ [RDF.type]: [ toNamedNode(LDP.Resource) ]});
|
||||
await expect(accessor.writeDocument({ path: 'http://test.com/container/resource' }, data, metadata))
|
||||
.resolves.toBeUndefined();
|
||||
@@ -190,7 +190,7 @@ 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',
|
||||
metadata = new RepresentationMetadata({ path: '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))
|
||||
@@ -209,7 +209,7 @@ describe('A SparqlDataAccessor', (): void => {
|
||||
});
|
||||
|
||||
it('removes all references when deleting a resource.', async(): Promise<void> => {
|
||||
metadata = new RepresentationMetadata('http://test.com/container/',
|
||||
metadata = new RepresentationMetadata({ path: 'http://test.com/container/' },
|
||||
{ [RDF.type]: [ toNamedNode(LDP.Resource), toNamedNode(LDP.Container) ]});
|
||||
await expect(accessor.deleteResource({ path: 'http://test.com/container/' })).resolves.toBeUndefined();
|
||||
|
||||
@@ -246,14 +246,14 @@ describe('A SparqlDataAccessor', (): void => {
|
||||
});
|
||||
|
||||
it('errors when the SPARQL endpoint fails during writing.', async(): Promise<void> => {
|
||||
const path = 'http://test.com/container/';
|
||||
metadata = new RepresentationMetadata(path);
|
||||
const identifier = { path: 'http://test.com/container/' };
|
||||
metadata = new RepresentationMetadata(identifier);
|
||||
|
||||
updateError = 'error';
|
||||
await expect(accessor.writeContainer({ path }, metadata)).rejects.toBe(updateError);
|
||||
await expect(accessor.writeContainer(identifier, metadata)).rejects.toBe(updateError);
|
||||
|
||||
updateError = new Error();
|
||||
await expect(accessor.writeContainer({ path }, metadata)).rejects.toThrow(updateError);
|
||||
await expect(accessor.writeContainer(identifier, metadata)).rejects.toThrow(updateError);
|
||||
|
||||
updateError = undefined;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user