mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: ExtensionBasedMapper no longer throws if there is no file
This commit is contained in:
@@ -223,20 +223,27 @@ describe('A FileDataAccessor', (): void => {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not try to update the content-type if there is no original file.', async(): Promise<void> => {
|
||||
metadata.identifier = DataFactory.namedNode(`${base}resource.txt`);
|
||||
metadata.contentType = 'text/turtle';
|
||||
metadata.add('new', 'metadata');
|
||||
await expect(accessor.writeDocument({ path: `${base}resource.txt` }, data, metadata))
|
||||
.resolves.toBeUndefined();
|
||||
expect(cache.data).toEqual({
|
||||
'resource.txt$.ttl': 'data',
|
||||
'resource.txt.meta': expect.stringMatching(`<${base}resource.txt> <new> "metadata".`),
|
||||
});
|
||||
});
|
||||
|
||||
it('throws an error if there is an issue deleting the original file.', async(): Promise<void> => {
|
||||
cache.data = { 'resource$.ttl': '<this> <is> <data>.' };
|
||||
jest.requireMock('fs').promises.unlink = (): any => {
|
||||
const error = new Error('error') as SystemError;
|
||||
error.code = 'ENOENT';
|
||||
error.code = 'EISDIR';
|
||||
error.syscall = 'unlink';
|
||||
throw error;
|
||||
};
|
||||
|
||||
// `unlink` throwing ENOENT should not be an issue if the content-type does not change
|
||||
metadata.contentType = 'text/turtle';
|
||||
await expect(accessor.writeDocument({ path: `${base}resource` }, data, metadata))
|
||||
.resolves.toBeUndefined();
|
||||
|
||||
metadata.contentType = 'text/plain';
|
||||
await expect(accessor.writeDocument({ path: `${base}resource` }, data, metadata))
|
||||
.rejects.toThrow(new Error('error'));
|
||||
|
||||
@@ -50,16 +50,24 @@ describe('An ExtensionBasedMapper', (): void => {
|
||||
.rejects.toThrow(new BadRequestHttpError('Identifiers cannot contain a dollar sign before their extension'));
|
||||
});
|
||||
|
||||
it('throws 404 when looking in a folder that does not exist.', async(): Promise<void> => {
|
||||
it('determines content-type by extension when looking in a folder that does not exist.', async(): Promise<void> => {
|
||||
fsPromises.readdir.mockImplementation((): void => {
|
||||
throw new Error('does not exist');
|
||||
});
|
||||
await expect(mapper.mapUrlToFilePath({ path: `${base}no/test.txt` })).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(mapper.mapUrlToFilePath({ path: `${base}no/test.txt` })).resolves.toEqual({
|
||||
identifier: { path: `${base}no/test.txt` },
|
||||
filePath: `${rootFilepath}no/test.txt`,
|
||||
contentType: 'text/plain',
|
||||
});
|
||||
});
|
||||
|
||||
it('throws 404 when looking for a file that does not exist.', async(): Promise<void> => {
|
||||
it('determines content-type by extension when looking for a file that does not exist.', async(): Promise<void> => {
|
||||
fsPromises.readdir.mockReturnValue([ 'test.ttl' ]);
|
||||
await expect(mapper.mapUrlToFilePath({ path: `${base}test.txt` })).rejects.toThrow(NotFoundHttpError);
|
||||
await expect(mapper.mapUrlToFilePath({ path: `${base}test.txt` })).resolves.toEqual({
|
||||
identifier: { path: `${base}test.txt` },
|
||||
filePath: `${rootFilepath}test.txt`,
|
||||
contentType: 'text/plain',
|
||||
});
|
||||
});
|
||||
|
||||
it('determines the content-type based on the extension.', async(): Promise<void> => {
|
||||
|
||||
Reference in New Issue
Block a user