Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexesprit committed Sep 20, 2020
1 parent 3e036ad commit 1b4cdc9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ export class MetadataFilter {
* @throws Throw an error if an invalid field is specified
*/
filterField(field: string, fieldValue: string): string {
if (!(field in this.mergedFilterSet)) {
throw new TypeError(`Invalid filter field: ${field}`);
if (field in this.mergedFilterSet) {
return this.filterText(fieldValue, this.mergedFilterSet[field]);
}

return this.filterText(fieldValue, this.mergedFilterSet[field]);
throw new TypeError(`Invalid filter field: ${field}`);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions test/filter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ describe('Test filtering empty strings', () => {

it('should not call filter function is the input is null', () => {
const input = null;
// @ts-ignore
const actual = filter.filterField('artist', input);

expect(actual).to.be.equal(input);
Expand All @@ -127,6 +128,7 @@ describe('Test filtering invalid filter field', () => {

describe('Test invalid filter', () => {
it('should throw error if the filter set is not specified', () => {
// @ts-ignore
expect(() => createFilter(null)).to.throw();
});

Expand Down
4 changes: 2 additions & 2 deletions test/helper/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MetadataFilter, createFilter } from '../../src/filter';
import { MetadataFilter, createFilter, FilterSet } from '../../src/filter';
import { FilterFuncion } from '../../src/functions';

/**
Expand All @@ -17,7 +17,7 @@ export function createFilterFromFunction(
const filterSet = fields.reduce((filterSet, field) => {
filterSet[field] = filterFunc;
return filterSet;
}, {});
}, {} as FilterSet);

return createFilter(filterSet);
}
Expand Down

0 comments on commit 1b4cdc9

Please sign in to comment.