feat: Update ExtensionBasedMapper custom types

This commit is contained in:
Ruben Taelman
2021-06-11 13:36:37 +02:00
committed by Joachim Van Herwegen
parent c01e33ecd9
commit 3f8f822d81
7 changed files with 77 additions and 19 deletions

View File

@@ -130,6 +130,28 @@ describe('An ExtensionBasedMapper', (): void => {
await expect(result).rejects.toThrow(NotImplementedHttpError);
await expect(result).rejects.toThrow('Unsupported content type fake/data');
});
it('supports custom types.', async(): Promise<void> => {
const customMapper = new ExtensionBasedMapper(base, rootFilepath, { cstm: 'text/custom' });
await expect(customMapper.mapUrlToFilePath({ path: `${base}test.cstm` }, false))
.resolves.toEqual({
identifier: { path: `${base}test.cstm` },
filePath: `${rootFilepath}test.cstm`,
contentType: 'text/custom',
isMetadata: false,
});
});
it('supports custom extensions.', async(): Promise<void> => {
const customMapper = new ExtensionBasedMapper(base, rootFilepath, { cstm: 'text/custom' });
await expect(customMapper.mapUrlToFilePath({ path: `${base}test` }, false, 'text/custom'))
.resolves.toEqual({
identifier: { path: `${base}test` },
filePath: `${rootFilepath}test$.cstm`,
contentType: 'text/custom',
isMetadata: false,
});
});
});
describe('mapFilePathToUrl', (): void => {
@@ -180,6 +202,17 @@ describe('An ExtensionBasedMapper', (): void => {
isMetadata: false,
});
});
it('supports custom extensions.', async(): Promise<void> => {
const customMapper = new ExtensionBasedMapper(base, rootFilepath, { cstm: 'text/custom' });
await expect(customMapper.mapFilePathToUrl(`${rootFilepath}test$.cstm`, false))
.resolves.toEqual({
identifier: { path: `${base}test` },
filePath: `${rootFilepath}test$.cstm`,
contentType: 'text/custom',
isMetadata: false,
});
});
});
describe('An ExtensionBasedMapperFactory', (): void => {