mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00

* 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
22 lines
965 B
TypeScript
22 lines
965 B
TypeScript
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);
|
|
});
|
|
});
|