mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Combine metadata with data when generating resources
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { DataFactory } from 'n3';
|
||||
import type { ResourceIdentifier } from '../../../../src/http/representation/ResourceIdentifier';
|
||||
import { BaseResourcesGenerator } from '../../../../src/pods/generate/BaseResourcesGenerator';
|
||||
import type {
|
||||
@@ -10,7 +11,6 @@ import { asyncToArray } from '../../../../src/util/IterableUtil';
|
||||
import { ensureTrailingSlash, joinFilePath, trimTrailingSlashes } from '../../../../src/util/PathUtil';
|
||||
import { readableToQuads, readableToString } from '../../../../src/util/StreamUtil';
|
||||
import { HandlebarsTemplateEngine } from '../../../../src/util/templates/HandlebarsTemplateEngine';
|
||||
import { CONTENT_TYPE_TERM } from '../../../../src/util/Vocabularies';
|
||||
import { SimpleSuffixStrategy } from '../../../util/SimpleSuffixStrategy';
|
||||
import { mockFileSystem } from '../../../util/Util';
|
||||
|
||||
@@ -110,7 +110,8 @@ describe('A BaseResourcesGenerator', (): void => {
|
||||
|
||||
it('adds metadata from .meta files.', async(): Promise<void> => {
|
||||
const meta = '<> <pre:has> "metadata".';
|
||||
cache.data = { '.meta': meta, container: { 'template.meta': meta, template }};
|
||||
const metaType = '<> <http://www.w3.org/ns/ma-ont#format> "text/plain".';
|
||||
cache.data = { '.meta': meta, container: { 'template.meta': meta, template, type: 'dummy', 'type.meta': metaType }};
|
||||
|
||||
// Not using options since our dummy template generator generates invalid turtle
|
||||
const result = await asyncToArray(generator.generate(rootFilePath, location, { webId }));
|
||||
@@ -120,7 +121,7 @@ describe('A BaseResourcesGenerator', (): void => {
|
||||
{ path: `${location.path}.meta` },
|
||||
{ path: `${location.path}container/` },
|
||||
{ path: `${location.path}container/template` },
|
||||
{ path: `${location.path}container/template.meta` },
|
||||
{ path: `${location.path}container/type` },
|
||||
]);
|
||||
|
||||
// Root has the 1 raw metadata triple (with <> changed to its identifier) and content-type
|
||||
@@ -137,18 +138,17 @@ describe('A BaseResourcesGenerator', (): void => {
|
||||
expect(contMetadata.identifier.value).toBe(`${location.path}container/`);
|
||||
expect(contMetadata.quads()).toHaveLength(0);
|
||||
|
||||
// Document has the 1 raw metadata triple (with <> changed to its identifier) and content-type
|
||||
// Document has the new metadata
|
||||
const docMetadata = result[3].representation.metadata;
|
||||
expect(docMetadata.identifier.value).toBe(`${location.path}container/template`);
|
||||
expect(docMetadata.contentType).toBe('text/turtle');
|
||||
const docMetadataQuads = await readableToQuads(result[4].representation.data);
|
||||
const expDocMetadataQuads = docMetadataQuads.getQuads(docMetadata.identifier, 'pre:has', null, null);
|
||||
expect(expDocMetadataQuads).toHaveLength(1);
|
||||
expect(expDocMetadataQuads[0].object.value).toBe('metadata');
|
||||
// Metadata will replace existing metadata so need to make sure content-type is still there
|
||||
const contentDocMetadataQuads = docMetadataQuads.getQuads(docMetadata.identifier, CONTENT_TYPE_TERM, null, null);
|
||||
expect(contentDocMetadataQuads).toHaveLength(1);
|
||||
expect(contentDocMetadataQuads[0].object.value).toBe('text/turtle');
|
||||
expect(docMetadata.contentType).toBe('text/turtle');
|
||||
expect(docMetadata.get(DataFactory.namedNode('pre:has'))?.value).toBe('metadata');
|
||||
|
||||
// Type document has new content type
|
||||
const typeMetadata = result[4].representation.metadata;
|
||||
expect(typeMetadata.identifier.value).toBe(`${location.path}container/type`);
|
||||
expect(typeMetadata.contentType).toBe('text/plain');
|
||||
});
|
||||
|
||||
it('does not create container when it already exists.', async(): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user