|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const assert = require('assert'); |
| 4 | +const items = [{ |
| 5 | + genres: 'Western' |
| 6 | +}, { |
| 7 | + genres: 'Western' |
| 8 | +}, { |
| 9 | + genres: 'Comedy' |
| 10 | +}, { |
| 11 | + genres: 'Drama' |
| 12 | +}, { |
| 13 | + genres: 'Horror' |
| 14 | +}, { |
| 15 | + genres: 'Romance' |
| 16 | +}, { |
| 17 | + genres: 'Western' |
| 18 | +}]; |
| 19 | + |
| 20 | +describe('facet sorting', function() { |
| 21 | + |
| 22 | + it('sort by key', function test(done) { |
| 23 | + |
| 24 | + const result = require('./../index')(items, { |
| 25 | + aggregations: { |
| 26 | + genres: { |
| 27 | + sort: ['key'], |
| 28 | + } |
| 29 | + } |
| 30 | + }).aggregation({ |
| 31 | + name: 'genres', |
| 32 | + }); |
| 33 | + |
| 34 | + assert.deepEqual(result.data.buckets.map(v => v.key), ['Comedy', 'Drama', 'Horror', 'Romance', 'Western']); |
| 35 | + |
| 36 | + done(); |
| 37 | + }); |
| 38 | + |
| 39 | + it('sort by key descending', function test(done) { |
| 40 | + |
| 41 | + const result = require('./../index')(items, { |
| 42 | + aggregations: { |
| 43 | + genres: { |
| 44 | + sort: ['key'], |
| 45 | + order: ['desc'] |
| 46 | + } |
| 47 | + } |
| 48 | + }).aggregation({ |
| 49 | + name: 'genres', |
| 50 | + }); |
| 51 | + |
| 52 | + assert.deepEqual(result.data.buckets.map(v => v.key), ['Western', 'Romance', 'Horror', 'Drama', 'Comedy']); |
| 53 | + |
| 54 | + done(); |
| 55 | + }); |
| 56 | + |
| 57 | + it('sort by doc_count', function test(done) { |
| 58 | + |
| 59 | + const result = require('./../index')(items, { |
| 60 | + aggregations: { |
| 61 | + genres: { |
| 62 | + sort: ['doc_count'], |
| 63 | + order: ['desc'], |
| 64 | + } |
| 65 | + } |
| 66 | + }).aggregation({ |
| 67 | + name: 'genres', |
| 68 | + }); |
| 69 | + |
| 70 | + assert.deepEqual(result.data.buckets.map(v => v.key), ['Western', 'Comedy', 'Drama', 'Horror', 'Romance']); |
| 71 | + |
| 72 | + done(); |
| 73 | + }); |
| 74 | + |
| 75 | + it('sort by doc_count and key and order key desc', function test(done) { |
| 76 | + |
| 77 | + const result = require('./../index')(items, { |
| 78 | + aggregations: { |
| 79 | + genres: { |
| 80 | + sort: ['doc_count', 'key'], |
| 81 | + order: ['desc', 'desc'], |
| 82 | + } |
| 83 | + } |
| 84 | + }).aggregation({ |
| 85 | + name: 'genres', |
| 86 | + }); |
| 87 | + |
| 88 | + assert.deepEqual(result.data.buckets.map(v => v.key), ['Western', 'Romance', 'Horror', 'Drama', 'Comedy']); |
| 89 | + |
| 90 | + done(); |
| 91 | + }); |
| 92 | + |
| 93 | +}); |
| 94 | + |
0 commit comments