mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Implement resource mapper for the file resource store (#142)
* move file mapping logic to resourcemapper * make filestore dependent of resource mapper * set default contenttype * refactor fileresourcemapper * fix map function * refactor * add normalized parser * refactor unit test * fix metadata problem * refactor names * reverse change * add getters * add comments * add comments, move code * change text/turtle to constant * add changes * add requested changes * add more requested changes * add more requested changes * more changes
This commit is contained in:
21
test/unit/storage/ExtensionBasedMapper.test.ts
Normal file
21
test/unit/storage/ExtensionBasedMapper.test.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { RuntimeConfig } from '../../../src/init/RuntimeConfig';
|
||||
import { ExtensionBasedMapper } from '../../../src/storage/ExtensionBasedMapper';
|
||||
|
||||
describe('An ExtensionBasedMapper', (): void => {
|
||||
const base = 'http://test.com/';
|
||||
const rootFilepath = 'uploads/';
|
||||
const resourceMapper = new ExtensionBasedMapper(new RuntimeConfig({ base, rootFilepath }));
|
||||
|
||||
it('returns the correct url of a file.', async(): Promise<void> => {
|
||||
let result = resourceMapper.mapFilePathToUrl(`${rootFilepath}test.txt`);
|
||||
expect(result).toEqual(`${base}test.txt`);
|
||||
|
||||
result = resourceMapper.mapFilePathToUrl(`${rootFilepath}image.jpg`);
|
||||
expect(result).toEqual(`${base}image.jpg`);
|
||||
});
|
||||
|
||||
it('errors when filepath does not contain rootFilepath.', async(): Promise<void> => {
|
||||
expect((): string => resourceMapper.mapFilePathToUrl('random/test.txt')).toThrow(Error);
|
||||
expect((): string => resourceMapper.mapFilePathToUrl('test.txt')).toThrow(Error);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user