Skip to content

Commit

Permalink
#157: fix encoding of search options, which did encode the sorting op…
Browse files Browse the repository at this point in the history
…tion twice

Signed-off-by: Florian Fendt <Florian.Fendt@bosch.io>
  • Loading branch information
ffendt committed May 27, 2021
1 parent 8ae348e commit b4fba5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion javascript/lib/api/src/options/request.options.ts
Expand Up @@ -332,7 +332,7 @@ export class DefaultSearchOptions extends AbstractRequestOptions<DefaultSearchOp
}

public withSort(sortOperation: string): DefaultSearchOptions {
this.sort = `sort(${encodeURIComponent(sortOperation)})`;
this.sort = `sort(${sortOperation})`;
return this.setOption();
}

Expand Down
16 changes: 8 additions & 8 deletions javascript/lib/api/tests/options/request.options.spec.ts
Expand Up @@ -195,22 +195,22 @@ describe('Search Options', () => {
expect(searchOptions.getOptions().get('namespaces')).toEqual(encodeURIComponent('C,D'));
});
it('sets sort', () => {
searchOptions.withSort('A');
expect(searchOptions.getOptions().get('option')).toEqual(encodeURIComponent('sort(A)'));
searchOptions.withSort('+A');
expect(searchOptions.getOptions().get('option')).toEqual(encodeURIComponent('sort(+A)'));
});
it('overrides sort', () => {
searchOptions.withSort('A');
searchOptions.withSort('+A');
searchOptions.withSort('B');
expect(searchOptions.getOptions().get('option')).toEqual(encodeURIComponent('sort(B)'));
});
it('combines option', () => {
searchOptions.withLimit(1, 2).withSort('A');
expect(searchOptions.getOptions().get('option')).toEqual(encodeURIComponent('limit(1,2),sort(A)'));
searchOptions.withLimit(1, 2).withSort('+A');
expect(searchOptions.getOptions().get('option')).toEqual(encodeURIComponent('limit(1,2),sort(+A)'));
});
it('overrides combined option', () => {
searchOptions.withLimit(1, 2).withSort('A');
searchOptions.withLimit(3, 4).withSort('B');
expect(searchOptions.getOptions().get('option')).toEqual(encodeURIComponent('limit(3,4),sort(B)'));
searchOptions.withLimit(1, 2).withSort('+A');
searchOptions.withLimit(3, 4).withSort('-B');
expect(searchOptions.getOptions().get('option')).toEqual(encodeURIComponent('limit(3,4),sort(-B)'));
});
});

Expand Down

0 comments on commit b4fba5a

Please sign in to comment.