Updated test

This commit is contained in:
delvedor
2020-09-04 18:05:35 +02:00
parent 8fce294e93
commit 06b008099b
3 changed files with 66 additions and 12 deletions

View File

@ -557,7 +557,7 @@ test('nested with only should', t => {
t.end()
})
test('nested with only should and minimum_should_match', t => {
test('nested with only should and minimum_should_match / 1', t => {
const query = Q.bool(
Q.should(
Q.bool(
@ -589,6 +589,40 @@ test('nested with only should and minimum_should_match', t => {
t.end()
})
test('nested with only should and minimum_should_match / 2', t => {
const query = Q.bool(
Q.bool(
Q.should(
Q.match('1', '2'),
Q.term('3', '4')
),
Q.minShouldMatch(2)
),
Q.should(Q.match('5', '6'))
)
t.deepEqual(query, {
query: {
bool: {
must: [{
bool: {
should: [
{ match: { 1: '2' } },
{ term: { 3: '4' } }
],
minimum_should_match: 2
}
}],
should: [{
match: { 5: '6' }
}]
}
}
})
t.end()
})
test('nested with should and other clause', t => {
const query = Q.bool(
Q.should(
@ -761,16 +795,29 @@ test('Should not merge up named queries / 2', t => {
t.end()
})
test('should throw if it can\'t merge the query', t => {
test('_name defined twice', t => {
try {
Q.bool(
Q.must(),
Q.must(),
Q.should()
Q.name('foo'),
Q.name('bar')
)
t.fail('It should throw')
t.fail('should throw')
} catch (err) {
t.is(err.message, 'Cannot merge this query')
t.is(err.message, 'The query name has already been defined')
}
t.end()
})
test('minimum_should_match defined twice', t => {
try {
Q.bool(
Q.minShouldMatch(4),
Q.minShouldMatch(2)
)
t.fail('should throw')
} catch (err) {
t.is(err.message, 'minimum_should_match has already been defined')
}
t.end()

View File

@ -7,7 +7,7 @@ import * as types from '../../dsl/lib/types'
import { F } from '../../dsl'
test('match', t => {
t.deepEqual(new F()
t.deepEqual(F()
.match('foo', 'bar')
.match('foo', 'baz')
.build(), {
@ -21,7 +21,7 @@ test('match', t => {
}
})
t.deepEqual(new F()
t.deepEqual(F()
.match('foo', ['bar', 'baz'])
.build(), {
query: {
@ -38,7 +38,7 @@ test('match', t => {
})
test('matchPhrase', t => {
t.deepEqual(new F()
t.deepEqual(F()
.matchPhrase('foo', 'bar')
.build(), {
query: {
@ -50,7 +50,7 @@ test('matchPhrase', t => {
})
test('matchPhrasePrefix', t => {
t.deepEqual(new F()
t.deepEqual(F()
.matchPhrasePrefix('foo', 'bar')
.build(), {
query: {

View File

@ -66,13 +66,20 @@ test('Q is a function that creates the final query object', t => {
[randomTopLevelKey]: 42
})
t.deepEqual(Q({ function_score: { foo: 'bar' } }, { [randomTopLevelKey]: 42 }), {
t.deepEqual(Q({ query: { function_score: { foo: 'bar' } } }, { [randomTopLevelKey]: 42 }), {
query: {
function_score: { foo: 'bar' }
},
[randomTopLevelKey]: 42
})
t.deepEqual(Q({ query: { bool: {} } }, { [randomTopLevelKey]: 42 }), {
query: {
bool: {}
},
[randomTopLevelKey]: 42
})
t.end()
})