refactor: Simplify TypedRepresentationConverter contruction.

This commit is contained in:
Ruben Verborgh
2021-01-09 00:07:44 +01:00
parent 27a115022b
commit 27a5711ec2
7 changed files with 96 additions and 55 deletions

View File

@@ -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);

View File

@@ -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,
});
});
});