Skip to content

Commit

Permalink
[savedObjects/searchDsl/queryParams] test experimentalFilter arg
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Apr 5, 2018
1 parent 255cf14 commit 95d00d1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function getQueryParams(mappings, type, search, searchFields, experimenta
}

if (experimentalFilter) {
bool.must = (bool.must || []).concat(
bool.filter = (bool.filter || []).concat(
convertExperimentalFilterToEsDsl(searchTypes, rootAttributes, experimentalFilter)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,30 @@ describe('searchDsl/queryParams', () => {
});
});

describe('{type,experimentalFilter}', () => {
it('includes a terms filter and filters scoped to the type', () => {
expect(getQueryParams(MAPPINGS, 'saved', undefined, undefined, { field: 'title', value: 'foo' }))
.to.eql({
query: {
bool: {
filter: [
{
term: { type: 'saved' }
},
{
multi_match: {
type: 'phrase',
query: 'foo',
fields: ['saved.title'],
}
}
]
}
}
});
});
});

describe('{search}', () => {
it('includes just a sqs query', () => {
expect(getQueryParams(MAPPINGS, null, 'us*'))
Expand All @@ -81,6 +105,38 @@ describe('searchDsl/queryParams', () => {
});
});

describe('{search,experimentalFilter}', () => {
it('includes a sqs query and filters applying to all types', () => {
expect(getQueryParams(MAPPINGS, null, 'us*', undefined, { field: 'title', value: 'foo' }))
.to.eql({
query: {
bool: {
filter: [
{
multi_match: {
type: 'phrase',
query: 'foo',
fields: [
'pending.title',
'saved.title',
],
}
}
],
must: [
{
simple_query_string: {
query: 'us*',
all_fields: true
}
}
]
}
}
});
});
});

describe('{type,search}', () => {
it('includes bool with sqs query and term filter for type', () => {
expect(getQueryParams(MAPPINGS, 'saved', 'y*'))
Expand Down

0 comments on commit 95d00d1

Please sign in to comment.