Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add checking of template queries and GET #149

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion services/esSearcherPreprocessorSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
angular.module('o19s.splainer-search')
.service('esSearcherPreprocessorSvc', [
'queryTemplateSvc',
'esUrlSvc',
'defaultESConfig',
function esSearcherPreprocessorSvc(queryTemplateSvc, defaultESConfig) {
function esSearcherPreprocessorSvc(queryTemplateSvc, esUrlSvc, defaultESConfig) {
var self = this;

// Attributes
Expand Down Expand Up @@ -90,6 +91,9 @@ angular.module('o19s.splainer-search')
};

var prepareGetRequest = function (searcher) {
if (esUrlSvc.isTemplateCall(searcher.args)) {
throw new Error('Template queries must be executed via POST, not GET.');
}
searcher.url = searcher.url + '?q=' + searcher.queryText;

var pagerArgs = angular.copy(searcher.args.pager);
Expand Down
30 changes: 30 additions & 0 deletions test/spec/esSearchSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,36 @@ describe('Service: searchSvc: ElasticSearch', function() {
expect(called).toEqual(1);
});
});

describe('errors on GET versus POST', function() {
beforeEach(inject(function () {

}));

it('throws an Error on a GET', function() {
// the 'id' tells us that we have a templated search.
var mockEsParams = {
id: 'tmdb-title-search-template',
params: {
search_query: 'star'
}
};

var config = {
apiMethod: 'GET'
}

expect(() => {searchSvc.createSearcher(
mockFieldSpec,
mockEsUrl,
mockEsParams,
mockQueryText,
config,
'es'
);
}).toThrowError('Template queries must be executed via POST, not GET.');
});
});
describe('scripted fields', function() {
var mockScriptedResults = {
hits: {
Expand Down