mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
refactor: Simplify TypedRepresentationConverter contruction.
This commit is contained in:
@@ -24,18 +24,12 @@ describe('A QuadToRdfConverter', (): void => {
|
||||
.resolves.toEqual({ [INTERNAL_QUADS]: 1 });
|
||||
});
|
||||
|
||||
it('defaults to rdfSerializer preferences when given no preferences.', async(): Promise<void> => {
|
||||
it('defaults to rdfSerializer preferences when given no output preferences.', async(): Promise<void> => {
|
||||
await expect(new QuadToRdfConverter().getOutputTypes())
|
||||
.resolves.toEqual(await rdfSerializer.getContentTypesPrioritized());
|
||||
});
|
||||
|
||||
it('defaults to rdfSerializer preferences when given empty preferences.', async(): Promise<void> => {
|
||||
const outputPreferences = {};
|
||||
await expect(new QuadToRdfConverter({ outputPreferences }).getOutputTypes())
|
||||
.resolves.toEqual(await rdfSerializer.getContentTypesPrioritized());
|
||||
});
|
||||
|
||||
it('returns custom preferences when given non-empty preferences.', async(): Promise<void> => {
|
||||
it('supports overriding output preferences.', async(): Promise<void> => {
|
||||
const outputPreferences = { 'text/turtle': 1 };
|
||||
await expect(new QuadToRdfConverter({ outputPreferences }).getOutputTypes())
|
||||
.resolves.toEqual(outputPreferences);
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { TypedRepresentationConverter } from '../../../../src/storage/conversion/TypedRepresentationConverter';
|
||||
|
||||
class CustomTypedRepresentationConverter extends TypedRepresentationConverter {
|
||||
public handle = jest.fn();
|
||||
}
|
||||
|
||||
describe('A TypedRepresentationConverter', (): void => {
|
||||
it('defaults to allowing everything.', async(): Promise<void> => {
|
||||
const converter = new CustomTypedRepresentationConverter();
|
||||
await expect(converter.getInputTypes()).resolves.toEqual({
|
||||
});
|
||||
await expect(converter.getOutputTypes()).resolves.toEqual({
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts strings.', async(): Promise<void> => {
|
||||
const converter = new CustomTypedRepresentationConverter('a/b', 'c/d');
|
||||
await expect(converter.getInputTypes()).resolves.toEqual({
|
||||
'a/b': 1,
|
||||
});
|
||||
await expect(converter.getOutputTypes()).resolves.toEqual({
|
||||
'c/d': 1,
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts string arrays.', async(): Promise<void> => {
|
||||
const converter = new CustomTypedRepresentationConverter([ 'a/b', 'c/d' ], [ 'e/f', 'g/h' ]);
|
||||
await expect(converter.getInputTypes()).resolves.toEqual({
|
||||
'a/b': 1,
|
||||
'c/d': 1,
|
||||
});
|
||||
await expect(converter.getOutputTypes()).resolves.toEqual({
|
||||
'e/f': 1,
|
||||
'g/h': 1,
|
||||
});
|
||||
});
|
||||
|
||||
it('accepts records.', async(): Promise<void> => {
|
||||
const converter = new CustomTypedRepresentationConverter({ 'a/b': 0.5 }, { 'c/d': 0.5 });
|
||||
await expect(converter.getInputTypes()).resolves.toEqual({
|
||||
'a/b': 0.5,
|
||||
});
|
||||
await expect(converter.getOutputTypes()).resolves.toEqual({
|
||||
'c/d': 0.5,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user