|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | 3 | const assert = require('assert'); |
| 4 | +const { clone } = require('lodash'); |
4 | 5 | const items = require('./fixtures/items.json'); |
5 | 6 | const movies = require('./fixtures/movies.json'); |
6 | 7 | let itemsjs = require('./../src/index')(); |
@@ -195,6 +196,60 @@ describe('search', function() { |
195 | 196 | done(); |
196 | 197 | }); |
197 | 198 |
|
| 199 | + it('makes search with non existing filter value with conjunction true should return no results', function test(done) { |
| 200 | + |
| 201 | + const itemsjs = require('./../index')(items, configuration); |
| 202 | + |
| 203 | + const result = itemsjs.search({ |
| 204 | + filters: { |
| 205 | + category: ['drama', 'thriller'] |
| 206 | + } |
| 207 | + }); |
| 208 | + |
| 209 | + assert.equal(result.data.items.length, 0); |
| 210 | + assert.equal(result.data.aggregations.tags.buckets[0].doc_count, 0); |
| 211 | + |
| 212 | + done(); |
| 213 | + }); |
| 214 | + |
| 215 | + it('makes search with non existing filter value with conjunction false should return results', function test(done) { |
| 216 | + |
| 217 | + const localConfiguration = clone(configuration); |
| 218 | + localConfiguration.aggregations.category.conjunction = false; |
| 219 | + |
| 220 | + const itemsjs = require('./../index')(items, localConfiguration); |
| 221 | + |
| 222 | + const result = itemsjs.search({ |
| 223 | + filters: { |
| 224 | + category: ['drama', 'thriller'] |
| 225 | + } |
| 226 | + }); |
| 227 | + |
| 228 | + assert.equal(result.data.items.length, 2); |
| 229 | + assert.equal(result.data.aggregations.tags.buckets[0].doc_count, 2); |
| 230 | + |
| 231 | + done(); |
| 232 | + }); |
| 233 | + |
| 234 | + it('makes search with non existing single filter value with conjunction false should return no results', function test(done) { |
| 235 | + |
| 236 | + const localConfiguration = clone(configuration); |
| 237 | + localConfiguration.aggregations.category.conjunction = false; |
| 238 | + |
| 239 | + const itemsjs = require('./../index')(items, configuration); |
| 240 | + |
| 241 | + const result = itemsjs.search({ |
| 242 | + filters: { |
| 243 | + category: ['thriller'] |
| 244 | + } |
| 245 | + }); |
| 246 | + |
| 247 | + assert.equal(result.data.items.length, 0); |
| 248 | + assert.equal(result.data.aggregations.tags.buckets[0].doc_count, 0); |
| 249 | + |
| 250 | + done(); |
| 251 | + }); |
| 252 | + |
198 | 253 | it('throws an error if name does not exist', function test(done) { |
199 | 254 |
|
200 | 255 | const itemsjs = require('./../index')(items, { |
|
0 commit comments