/* * Copyright (C) 2020 StApps * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ import {SCFacet, SCThingType} from '@openstapps/core'; import {expect} from 'chai'; import {parseAggregations} from '../../../src/storage/elasticsearch/aggregations'; import {AggregationResponse} from '../../../src/storage/elasticsearch/types/elasticsearch'; describe('Aggregations', function () { const aggregations: AggregationResponse = { 'catalog': { 'doc_count': 4, 'superCatalogs.categories': { buckets: [], }, 'academicTerm.acronym': { buckets: [ { key: 'SoSe 2020', doc_count: 2, }, ], }, 'superCatalog.categories': { buckets: [], }, 'categories': { buckets: [ { key: 'foo', doc_count: 1, }, { key: 'bar', doc_count: 3, }, ], }, }, 'person': { 'doc_count': 13, 'homeLocations.categories': { buckets: [], }, }, 'academic event': { 'doc_count': 0, 'academicTerms.acronym': { buckets: [], }, 'categories': { buckets: [ { key: 'foobar', doc_count: 8, }, { key: 'bar', doc_count: 2, }, ], }, 'creativeWorks.keywords': { buckets: [], }, }, 'fooType': { buckets: [ { doc_count: 321, key: 'foo', }, ], }, '@all': { doc_count: 17, type: { buckets: [ { key: 'person', doc_count: 13, }, { key: 'catalog', doc_count: 4, }, ], }, }, }; const expectedFacets: SCFacet[] = [ { buckets: [ { count: 13, key: 'person', }, { count: 4, key: 'catalog', }, ], field: 'type', }, { buckets: [ { count: 8, key: 'foobar', }, { count: 2, key: 'bar', }, ], field: 'categories', onlyOnType: SCThingType.AcademicEvent, }, { buckets: [ { count: 2, key: 'SoSe 2020', }, ], field: 'academicTerm.acronym', onlyOnType: SCThingType.Catalog, }, { buckets: [ { count: 1, key: 'foo', }, { count: 3, key: 'bar', }, ], field: 'categories', onlyOnType: SCThingType.Catalog, }, // no fooType as it doesn't appear in the aggregation schema ]; it('should parse the aggregations providing the appropriate facets', function () { const facets = parseAggregations(aggregations); expect(facets).to.be.eql(expectedFacets); }); });