From a08b7e9112c2188ef62b8a77f7ad09073f126884 Mon Sep 17 00:00:00 2001 From: Joachim Van Herwegen Date: Mon, 14 Dec 2020 13:44:37 +0100 Subject: [PATCH] fix: Allow DataAccessorBasedStore to create root --- src/storage/DataAccessorBasedStore.ts | 3 ++- test/unit/storage/DataAccessorBasedStore.test.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/storage/DataAccessorBasedStore.ts b/src/storage/DataAccessorBasedStore.ts index e71b7544a..296e3f853 100644 --- a/src/storage/DataAccessorBasedStore.ts +++ b/src/storage/DataAccessorBasedStore.ts @@ -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)); } diff --git a/test/unit/storage/DataAccessorBasedStore.test.ts b/test/unit/storage/DataAccessorBasedStore.test.ts index 29a14c642..3512dc413 100644 --- a/test/unit/storage/DataAccessorBasedStore.test.ts +++ b/test/unit/storage/DataAccessorBasedStore.test.ts @@ -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 => { + // 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 => {