mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-10 19:52:53 +00:00
refactor: move backend to monorepo
This commit is contained in:
90
backend/test/storage/elasticsearch/common.spec.ts
Normal file
90
backend/test/storage/elasticsearch/common.spec.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {
|
||||
ESAggMatchAllFilter,
|
||||
ESAggTypeFilter,
|
||||
ESNestedAggregation,
|
||||
ESTermsFilter,
|
||||
} from '@openstapps/es-mapping-generator/src/types/aggregation';
|
||||
import {expect} from 'chai';
|
||||
import {
|
||||
isNestedAggregation,
|
||||
isBucketAggregation,
|
||||
isESTermsFilter,
|
||||
isESAggMatchAllFilter,
|
||||
isESNestedAggregation,
|
||||
} from '../../../lib/storage/elasticsearch/types/guards';
|
||||
import {BucketAggregation, NestedAggregation} from '../../../src/storage/elasticsearch/types/elasticsearch';
|
||||
|
||||
describe('Common', function () {
|
||||
const bucketAggregation: BucketAggregation = {buckets: []};
|
||||
const esNestedAggregation: ESNestedAggregation = {aggs: {}, filter: {match_all: true}};
|
||||
const esTermsFilter: ESTermsFilter = {terms: {field: 'foo'}};
|
||||
|
||||
describe('isBucketAggregation', function () {
|
||||
it('should be false for a number', function () {
|
||||
expect(isBucketAggregation(123)).to.be.false;
|
||||
});
|
||||
|
||||
it('should be true for a bucket aggregation', function () {
|
||||
expect(isBucketAggregation(bucketAggregation)).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('isNestedAggregation', function () {
|
||||
it('should be false for a bucket aggregation', function () {
|
||||
expect(isNestedAggregation(bucketAggregation)).to.be.false;
|
||||
});
|
||||
|
||||
it('should be true for a nested aggregation', function () {
|
||||
const nestedAggregation: NestedAggregation = {doc_count: 123};
|
||||
|
||||
expect(isNestedAggregation(nestedAggregation)).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('isESTermsFilter', function () {
|
||||
it('should be false for an elasticsearch nested aggregation', function () {
|
||||
expect(isESTermsFilter(esNestedAggregation)).to.be.false;
|
||||
});
|
||||
|
||||
it('should be true for an elasticsearch terms filter', function () {
|
||||
expect(isESTermsFilter(esTermsFilter)).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('isESNestedAggregation', function () {
|
||||
it('should be false for an elasticsearch terms filter', function () {
|
||||
expect(isESNestedAggregation(esTermsFilter)).to.be.false;
|
||||
});
|
||||
|
||||
it('should be true for an elasticsearch nested aggregation', function () {
|
||||
expect(isESNestedAggregation(esNestedAggregation)).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('isESAggMatchAllFilter', function () {
|
||||
it('should be false for an elasticsearch aggregation type filter', function () {
|
||||
const aggregationTypeFilter: ESAggTypeFilter = {type: {value: 'foo'}};
|
||||
expect(isESAggMatchAllFilter(aggregationTypeFilter)).to.be.false;
|
||||
});
|
||||
|
||||
it('should be true for an elasticsearch aggregation match all filter', function () {
|
||||
const esAggMatchAllFilter: ESAggMatchAllFilter = {match_all: {}};
|
||||
expect(isESAggMatchAllFilter(esAggMatchAllFilter)).to.be.true;
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user