fix: Allow DataAccessorBasedStore to create root

This commit is contained in:
Joachim Van Herwegen 2020-12-14 13:44:37 +01:00
parent 209b87a424
commit a08b7e9112
2 changed files with 17 additions and 1 deletions

View File

@ -218,7 +218,8 @@ export class DataAccessorBasedStore implements ResourceStore {
await this.handleContainerData(representation);
}
if (createContainers) {
// Root container should not have a parent container
if (createContainers && !this.identifierStrategy.isRootContainer(identifier)) {
await this.createRecursiveContainers(this.identifierStrategy.getParentContainer(identifier));
}

View File

@ -343,6 +343,21 @@ describe('A DataAccessorBasedStore', (): void => {
new ConflictHttpError(`Creating container ${root}a/ conflicts with an existing resource.`),
);
});
it('can write to root if it does not exist.', async(): Promise<void> => {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete accessor.data[root];
const resourceID = { path: `${root}` };
// Generate based on URI
representation.metadata.removeAll(RDF.type);
representation.metadata.contentType = 'text/turtle';
representation.data = guardedStreamFrom([]);
await expect(store.setRepresentation(resourceID, representation)).resolves.toBeUndefined();
expect(accessor.data[resourceID.path]).toBeTruthy();
expect(Object.keys(accessor.data)).toHaveLength(1);
expect(accessor.data[resourceID.path].metadata.contentType).toBeUndefined();
});
});
describe('modifying a Representation', (): void => {