Skip to content

Commit

Permalink
fix: Allow DataAccessorBasedStore to create root
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimvh committed Dec 18, 2020
1 parent 209b87a commit a08b7e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/storage/DataAccessorBasedStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
15 changes: 15 additions & 0 deletions test/unit/storage/DataAccessorBasedStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit a08b7e9

Please sign in to comment.