diff --git a/src/cli.ts b/src/cli.ts index 692ff609..bef68c71 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -87,7 +87,7 @@ commander commander .command('mapping ') .option('-m, --mappingPath ', 'Mapping Path') - .option('-i, --ignoredTags ', 'Ignored Tags') + .option('-i, --ignoredTags ', 'Ignored Tags (comma-separated)') .option('-a, --aggPath ', 'Aggregations Path') .option('-e, --errorPath ', 'Error Path') .action(async (relativeSrcPath, options) => { diff --git a/src/mapping.ts b/src/mapping.ts index 4b737505..1cd925d7 100644 --- a/src/mapping.ts +++ b/src/mapping.ts @@ -573,8 +573,12 @@ function readTypeTags(type: string, path: string, topTypeName: string, tags: Com * @param projectReflection a reflection of the project you want to get the ES Mappings from * @param ignoredTags the tag names for which the error output should be suppressed * @param showErrorOutput whether to print all errors in the command line or not + * @param interfaceFilter only parse specific interfaces, this is for testing purposes */ -export function generateTemplate(projectReflection: ProjectReflection, ignoredTags: string[], showErrorOutput = true): +export function generateTemplate(projectReflection: ProjectReflection, + ignoredTags: string[], + showErrorOutput = true, + interfaceFilter: string[] = []): // tslint:disable-next-line:completed-docs { aggregations: AggregationSchema; errors: string[]; mappings: ElasticsearchTemplateCollection; } { errors = []; @@ -626,6 +630,13 @@ export function generateTemplate(projectReflection: ProjectReflection, ignoredTa Logger.error(`The interface ${_interface.name} is required to use an SCThingType as a type, please do so.`); } + // filter out + if (interfaceFilter.length !== 0) { + if (typeof interfaceFilter.find((it) => it === typeName) === 'undefined') { + continue; + } + } + // init aggregation schema for type aggregations[typeName] = { aggs: {}, diff --git a/src/mappings/mapping-definitions.ts b/src/mappings/mapping-definitions.ts index ab6ab0f8..e7c0f626 100644 --- a/src/mappings/mapping-definitions.ts +++ b/src/mappings/mapping-definitions.ts @@ -207,7 +207,7 @@ export interface ElasticsearchObject { * Fields that should be excluded in the _source field */ excludes: [ - 'creation_date', + 'creation_date' ]; }; diff --git a/test/aggregations.spec.ts b/test/aggregations.spec.ts new file mode 100644 index 00000000..251d4d0a --- /dev/null +++ b/test/aggregations.spec.ts @@ -0,0 +1,72 @@ +// tslint:disable +/* + * Copyright (C) 2020 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +import {Logger} from '@openstapps/logger'; +import {slow, suite, test, timeout} from 'mocha-typescript'; +import {MapAggTest} from './mapping-model/MapAggTest'; +import {aggArrayTest} from './mapping-model/aggregations/src/agg-array'; +import {aggNestedTest} from './mapping-model/aggregations/src/agg-nested'; +import {aggGlobalTest} from './mapping-model/aggregations/src/agg-global'; +import {aggGlobalNestedTest} from './mapping-model/aggregations/src/agg-global-nested'; +import {aggInheritedTest} from './mapping-model/aggregations/src/agg-inherited'; +import {aggInheritedGlobalTest} from './mapping-model/aggregations/src/agg-inherited-global'; +import {aggInheritedOverwrittenTest} from './mapping-model/aggregations/src/agg-inherited-overwritten'; + +process.on('unhandledRejection', (error: unknown) => { + if (error instanceof Error) { + void Logger.error('UNHANDLED REJECTION', error.stack); + } + process.exit(1); +}); + +const magAppInstance = new MapAggTest('aggregations'); + +@suite(timeout(20000), slow(10000)) +export class AggregationsSpec { + @test + async 'Aggregation tag should propagate on arrays'() { + magAppInstance.testInterfaceAgainstPath(aggArrayTest); + } + + @test + async 'Should work on nested properties'() { + magAppInstance.testInterfaceAgainstPath(aggNestedTest); + } + + @test + async 'Global option should work'() { + magAppInstance.testInterfaceAgainstPath(aggGlobalTest); + } + + @test + async 'Global aggregations when nested'() { + magAppInstance.testInterfaceAgainstPath(aggGlobalNestedTest); + } + + @test + async 'Inherited aggregations should work'() { + magAppInstance.testInterfaceAgainstPath(aggInheritedTest); + } + + @test + async 'Inherited global aggregations should work'() { + magAppInstance.testInterfaceAgainstPath(aggInheritedGlobalTest); + } + + @test + async 'Inherited aggregations should work when overwritten'() { + magAppInstance.testInterfaceAgainstPath(aggInheritedOverwrittenTest); + } +} diff --git a/test/mapping-model/MapAggTest.ts b/test/mapping-model/MapAggTest.ts new file mode 100644 index 00000000..2ebe611c --- /dev/null +++ b/test/mapping-model/MapAggTest.ts @@ -0,0 +1,136 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +import {generateTemplate} from '../../src/mapping'; +import {resolve} from "path"; +import {expect} from "chai"; +import {ProjectReflection} from 'typedoc'; +import {getProjectReflection} from '../../src/common'; +import {AggregationSchema, ESNestedAggregation} from '../../src/mappings/aggregation-definitions'; +import {MapAggTestOptions, MinimalMappingDescription} from './MapAggTestOptions'; +import {ElasticsearchTemplateCollection} from '../../src/mappings/mapping-definitions'; +import {settings} from '../../src/mappings/definitions/settings'; +import {ElasticsearchDataType} from '../../src/mappings/definitions/typemap'; + +export class MapAggTest { + mapping_model_path!: string; + reflection!: ProjectReflection; + + constructor(dir: string) { + this.mapping_model_path = resolve(__dirname, dir); + this.reflection = getProjectReflection(this.mapping_model_path); + } + + testInterfaceAgainstPath(options: MapAggTestOptions) { + const template = generateTemplate(this.reflection, options.ignoredTags ?? [], false, [options.name]); + + if (typeof options.err !== 'undefined') { + for (const error of template.errors) { + expect(options.err).to.include(error, "Unexpected Error!") + } + } else { + expect(template.errors).to.be.deep.equal([], 'Unexpected Error!'); + } + + if (typeof options.agg !== 'undefined') { + const expectedAggSchema = MapAggTest.buildAggregation(options.name, options.agg.fields, options.agg.globals) + expect(template.aggregations).to.be.deep.equal(expectedAggSchema, 'Aggregation schema not equal!'); + } + + if (typeof options.map !== 'undefined') { + const expectedMappingSchema = MapAggTest.buildMapping(options.name, options.map); + expect(template.mappings).to.be.deep.equal(expectedMappingSchema, 'Mapping schema not equal!'); + } + } + + static buildAggregation(name: string, fields?: string[], globals?: string[]): AggregationSchema { + const out: AggregationSchema = { + '@all': { + aggs: {}, + filter: { + match_all: {} + } + }, + }; + + for (const global of globals ?? []) { + (out['@all']! as ESNestedAggregation).aggs[global] = { + terms: { + field: `${global}.raw`, + size: 1000, + } + } + } + + if (typeof fields === 'undefined' || fields.length === 0) { + return out; + } + + out[name] = { + aggs: {}, + filter: { + type: { + value: name, + } + } + } + + for (const field of fields) { + (out[name]! as ESNestedAggregation).aggs[field] = { + terms: { + field: `${field}.raw`, + size: 1000, + } + } + } + + return out; + } + + static buildMapping(name: string, map: MinimalMappingDescription): ElasticsearchTemplateCollection { + let typeNameWithoutSpaces = name.toLowerCase(); + while (typeNameWithoutSpaces.includes(' ')) { + typeNameWithoutSpaces = typeNameWithoutSpaces.replace(' ', '_'); + } + + const out: ElasticsearchTemplateCollection = {}; + const templateName = `template_${typeNameWithoutSpaces}`; + out[templateName] = { + mappings: {}, + settings: settings, + template: `stapps_${typeNameWithoutSpaces}*`, + } + const maps = map.maps ?? {}; + maps.type = { + type: ElasticsearchDataType.text + } + maps.creation_date = { + type: ElasticsearchDataType.date + } + out[templateName].mappings[name] = { + _source: { + excludes: [ + 'creation_date' + ] + }, + date_detection: false, + dynamic: 'strict', + properties: maps, + dynamic_templates: map.dynamicTemplates ?? [], + } + + return out; + } +} diff --git a/test/mapping-model/MapAggTestOptions.ts b/test/mapping-model/MapAggTestOptions.ts new file mode 100644 index 00000000..eb015ba6 --- /dev/null +++ b/test/mapping-model/MapAggTestOptions.ts @@ -0,0 +1,37 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +import { + ElasticsearchDynamicTemplate, + ElasticsearchValue +} from '../../src/mappings/mapping-definitions'; + +export interface MapAggTestOptions { + name: string; + agg?: { + fields?: string[]; + globals?: string[]; + } + map?: MinimalMappingDescription; + err?: string[]; + ignoredTags?: string[]; +} + +export interface MinimalMappingDescription { + maps?: { + [name: string]: ElasticsearchValue; + }; + dynamicTemplates?: ElasticsearchDynamicTemplate[]; +} diff --git a/test/mapping-model/aggregations/src/agg-array.ts b/test/mapping-model/aggregations/src/agg-array.ts new file mode 100644 index 00000000..a4d74960 --- /dev/null +++ b/test/mapping-model/aggregations/src/agg-array.ts @@ -0,0 +1,38 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; + +/** + * @indexable + */ +export interface AggArray { + /** + * @aggregatable + */ + array: Foo[]; + + type: ThingType.AggArray; +} +type Foo = 'A' | 'B' | 'C'; + +export const aggArrayTest: MapAggTestOptions = { + name: ThingType.AggArray, + agg: { + fields: ['array'], + }, +}; diff --git a/test/mapping-model/aggregations/src/agg-global-nested.ts b/test/mapping-model/aggregations/src/agg-global-nested.ts new file mode 100644 index 00000000..cadcd879 --- /dev/null +++ b/test/mapping-model/aggregations/src/agg-global-nested.ts @@ -0,0 +1,39 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; + +/** + * @indexable + */ +export interface AggGlobalNested { + nested: { + /** + * @aggregatable global + */ + foo: string; + }; + + type: ThingType.AggGlobalNested; +} + +export const aggGlobalNestedTest: MapAggTestOptions = { + name: ThingType.AggGlobalNested, + agg: { + globals: ['foo'], + }, +}; diff --git a/test/mapping-model/aggregations/src/agg-global.ts b/test/mapping-model/aggregations/src/agg-global.ts new file mode 100644 index 00000000..7f3f26fa --- /dev/null +++ b/test/mapping-model/aggregations/src/agg-global.ts @@ -0,0 +1,37 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; + +/** + * @indexable + */ +export interface AggGlobal { + /** + * @aggregatable global + */ + foo: string; + + type: ThingType.AggGlobal; +} + +export const aggGlobalTest: MapAggTestOptions = { + name: ThingType.AggGlobal, + agg: { + globals: ['foo'], + }, +}; diff --git a/test/mapping-model/aggregations/src/agg-inherited-global.ts b/test/mapping-model/aggregations/src/agg-inherited-global.ts new file mode 100644 index 00000000..65145166 --- /dev/null +++ b/test/mapping-model/aggregations/src/agg-inherited-global.ts @@ -0,0 +1,40 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; + +/** + * @indexable + */ +export interface AggInheritedGlobal extends Foo { + type: ThingType.AggInheritedGlobal; +} + + +interface Foo { + /** + * @aggregatable global + */ + bar: string; +} + +export const aggInheritedGlobalTest: MapAggTestOptions = { + name: ThingType.AggInheritedGlobal, + agg: { + globals: ['bar'], + }, +}; diff --git a/test/mapping-model/aggregations/src/agg-inherited-overwritten.ts b/test/mapping-model/aggregations/src/agg-inherited-overwritten.ts new file mode 100644 index 00000000..0512ee40 --- /dev/null +++ b/test/mapping-model/aggregations/src/agg-inherited-overwritten.ts @@ -0,0 +1,45 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; + +/** + * @indexable + */ +export interface AggInherited extends Foo { + /** + * No tag here :) + */ + bar: 'some thing'; + + type: ThingType.AggInheritedOverwritten; +} + + +interface Foo { + /** + * @aggregatable + */ + bar: string; +} + +export const aggInheritedOverwrittenTest: MapAggTestOptions = { + name: ThingType.AggInherited, + agg: { + fields: ['bar'], + }, +}; diff --git a/test/mapping-model/aggregations/src/agg-inherited.ts b/test/mapping-model/aggregations/src/agg-inherited.ts new file mode 100644 index 00000000..9cd7ef12 --- /dev/null +++ b/test/mapping-model/aggregations/src/agg-inherited.ts @@ -0,0 +1,40 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; + +/** + * @indexable + */ +export interface AggInherited extends Foo { + type: ThingType.AggInherited; +} + + +interface Foo { + /** + * @aggregatable + */ + bar: string; +} + +export const aggInheritedTest: MapAggTestOptions = { + name: ThingType.AggInherited, + agg: { + fields: ['bar'], + }, +}; diff --git a/test/mapping-model/aggregations/src/agg-nested.ts b/test/mapping-model/aggregations/src/agg-nested.ts new file mode 100644 index 00000000..8fb3b100 --- /dev/null +++ b/test/mapping-model/aggregations/src/agg-nested.ts @@ -0,0 +1,39 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; + +/** + * @indexable + */ +export interface AggNested { + nested: { + /** + * @aggregatable + */ + foo: string; + }; + + type: ThingType.AggNested; +} + +export const aggNestedTest: MapAggTestOptions = { + name: ThingType.AggNested, + agg: { + fields: ['nested.foo'], + }, +}; diff --git a/test/mapping-model/aggregations/src/types.ts b/test/mapping-model/aggregations/src/types.ts new file mode 100644 index 00000000..0978b05a --- /dev/null +++ b/test/mapping-model/aggregations/src/types.ts @@ -0,0 +1,25 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +export enum ThingType { + AggArray = 'agg array', + AggGlobal = 'agg global', + AggGlobalNested = 'agg global nested', + AggNested = 'agg nested', + AggInherited = 'agg inherited', + AggInheritedGlobal = 'agg inherited global', + AggInheritedOverwritten = 'agg inherited overwritten', +} diff --git a/test/mapping-model/aggregations/tsconfig.json b/test/mapping-model/aggregations/tsconfig.json new file mode 100644 index 00000000..c7a33719 --- /dev/null +++ b/test/mapping-model/aggregations/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../../node_modules/@openstapps/configuration/tsconfig.json" +} diff --git a/test/mapping-model/mappings/src/any-unknown.ts b/test/mapping-model/mappings/src/any-unknown.ts new file mode 100644 index 00000000..b740f9b2 --- /dev/null +++ b/test/mapping-model/mappings/src/any-unknown.ts @@ -0,0 +1,45 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; + +/** + * @indexable + */ +export interface AnyUnknown { + foo: any; + + bar: unknown; + + type: ThingType.AnyUnknown +} + +export const anyUnknownTest: MapAggTestOptions = { + name: ThingType.AnyUnknown, + map: { + maps: { + foo: { + dynamic: true, + properties: {} + }, + bar: { + dynamic: true, + properties: {} + } + } + } +}; diff --git a/test/mapping-model/mappings/src/default-generics.ts b/test/mapping-model/mappings/src/default-generics.ts new file mode 100644 index 00000000..f571671b --- /dev/null +++ b/test/mapping-model/mappings/src/default-generics.ts @@ -0,0 +1,51 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface DefaultGeneric { + foo: InterfaceWithDefaultGeneric; + + type: ThingType.DefaultGeneric; +} + +interface InterfaceWithDefaultGeneric { + bar: T; +} + +export const defaultGenericTest: MapAggTestOptions = { + name: ThingType.DefaultGeneric, + map: { + maps: { + foo: { + dynamic: 'strict', + properties: { + bar: { + type: ElasticsearchDataType.parse_error + } + } + } + } + }, + err: [ + `At "${ThingType.DefaultGeneric}::foo.bar" for Generic "T": Missing reflection, please report!` + ] +}; diff --git a/test/mapping-model/mappings/src/double-type-conflict.ts b/test/mapping-model/mappings/src/double-type-conflict.ts new file mode 100644 index 00000000..e889ca56 --- /dev/null +++ b/test/mapping-model/mappings/src/double-type-conflict.ts @@ -0,0 +1,56 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface DoubleTypeConflict { + /** + * @keyword + * @text + */ + stringDoubleTypeConflict: string; + + /** + * @integer + * @float + */ + numberDoubleTypeConflict: number; + + type: ThingType.DoubleTypeConflict; +} + +export const doubleTypeConflictTest: MapAggTestOptions = { + name: ThingType.DoubleTypeConflict, + map: { + maps: { + stringDoubleTypeConflict: { + type: ElasticsearchDataType.type_conflict + }, + numberDoubleTypeConflict: { + type: ElasticsearchDataType.type_conflict + } + } + }, + err: [ + `At "${ThingType.DoubleTypeConflict}::stringDoubleTypeConflict" for type "string": Type conflict; "keyword" would override "text"`, + `At "${ThingType.DoubleTypeConflict}::numberDoubleTypeConflict" for type "number": Type conflict; "integer" would override "float"` + ] +}; diff --git a/test/mapping-model/mappings/src/enum.ts b/test/mapping-model/mappings/src/enum.ts new file mode 100644 index 00000000..470e9379 --- /dev/null +++ b/test/mapping-model/mappings/src/enum.ts @@ -0,0 +1,56 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface Enum { + foo: Bar, + + bar: Baz, + + type: ThingType.Enum; +} + +enum Bar { + a, + b, + c, +} + +enum Baz { + d = 'd', + e = 'e', + f = 'f', +} + +export const enumTest: MapAggTestOptions = { + name: ThingType.Enum, + map: { + maps: { + foo: { + type: ElasticsearchDataType.text + }, + bar: { + type: ElasticsearchDataType.text + } + } + } +}; diff --git a/test/mapping-model/mappings/src/filterable-tag.ts b/test/mapping-model/mappings/src/filterable-tag.ts new file mode 100644 index 00000000..608b1456 --- /dev/null +++ b/test/mapping-model/mappings/src/filterable-tag.ts @@ -0,0 +1,75 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface FilterableTag { + /** + * @text + * @filterable + */ + foo: string; + + /** + * @keyword + * @filterable + */ + bar: string; + + /** + * @filterable + */ + baz: 'some literal' + + type: ThingType.FilterableTag +} + +export const filterableTagTest: MapAggTestOptions = { + name: ThingType.FilterableTag, + map: { + maps: { + foo: { + type: ElasticsearchDataType.text, + fields: { + raw: { + type: ElasticsearchDataType.keyword + } + } + }, + bar: { + type: ElasticsearchDataType.keyword, + fields: { + raw: { + type: ElasticsearchDataType.keyword + } + } + }, + baz: { + type: ElasticsearchDataType.keyword, + fields: { + raw: { + type: ElasticsearchDataType.keyword + } + } + } + } + } +}; diff --git a/test/mapping-model/mappings/src/generics.ts b/test/mapping-model/mappings/src/generics.ts new file mode 100644 index 00000000..54b127df --- /dev/null +++ b/test/mapping-model/mappings/src/generics.ts @@ -0,0 +1,61 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface Generics { + foo: InterfaceWithDefaultGeneric; + baz: InterfaceWithStringGeneric + + type: ThingType.Generics; +} + +interface InterfaceWithDefaultGeneric { + bar: T; +} + +interface InterfaceWithStringGeneric { + bar: T; +} + +export const genericTest: MapAggTestOptions = { + name: ThingType.Generics, + map: { + maps: { + foo: { + dynamic: 'strict', + properties: { + bar: { + type: ElasticsearchDataType.integer + } + } + }, + baz: { + dynamic: 'strict', + properties: { + bar: { + type: ElasticsearchDataType.text + } + } + } + } + } +}; diff --git a/test/mapping-model/mappings/src/impossible-union.ts b/test/mapping-model/mappings/src/impossible-union.ts new file mode 100644 index 00000000..069af3bf --- /dev/null +++ b/test/mapping-model/mappings/src/impossible-union.ts @@ -0,0 +1,42 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface ImpossibleUnion { + foo: 'a' | 1 | boolean; + + type: ThingType.ImpossibleUnion +} + +export const impossibleUnionTest: MapAggTestOptions = { + name: ThingType.ImpossibleUnion, + map: { + maps: { + foo: { + type: ElasticsearchDataType.boolean + } + } + }, + err: [ + `At "${ThingType.ImpossibleUnion}::foo" for type "[{"type":"1","name":"2"},"unknown","1"]": Not implemented type` + ] +}; diff --git a/test/mapping-model/mappings/src/incompatible-type.ts b/test/mapping-model/mappings/src/incompatible-type.ts new file mode 100644 index 00000000..2d119d29 --- /dev/null +++ b/test/mapping-model/mappings/src/incompatible-type.ts @@ -0,0 +1,73 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface DoubleTypeConflict { + /** + * @keyword + */ + keywordNumber: number; + + /** + * @text + */ + textNumber: number; + + /** + * @integer + */ + integerString: string; + + /** + * @float + */ + floatString: string; + + + type: ThingType.IncompatibleType; +} + +export const incompatibleTypeTest: MapAggTestOptions = { + name: ThingType.IncompatibleType, + map: { + maps: { + keywordNumber: { + type: ElasticsearchDataType.integer + }, + textNumber: { + type: ElasticsearchDataType.integer + }, + integerString: { + type: ElasticsearchDataType.text + }, + floatString: { + type: ElasticsearchDataType.text + } + } + }, + err: [ + `At "${ThingType.IncompatibleType}::keywordNumber" for tag "keyword": Not implemented tag`, + `At "${ThingType.IncompatibleType}::textNumber" for tag "text": Not implemented tag`, + `At "${ThingType.IncompatibleType}::floatString" for tag "float": Not implemented tag`, + `At "${ThingType.IncompatibleType}::integerString" for tag "integer": Not implemented tag`, + ] +}; diff --git a/test/mapping-model/mappings/src/index-signature.ts b/test/mapping-model/mappings/src/index-signature.ts new file mode 100644 index 00000000..6a8e9347 --- /dev/null +++ b/test/mapping-model/mappings/src/index-signature.ts @@ -0,0 +1,65 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface IndexSignature { + foo: { + [key: string]: { + bar: number; + baz: string; + } + } + + type: ThingType.IndexSignature; +} + +export const indexSignatureTest: MapAggTestOptions = { + name: ThingType.IndexSignature, + map: { + maps: { + foo: { + dynamic: true, + properties: {} + } + }, + dynamicTemplates: [ + { + __type: { + mapping: { + dynamic: 'strict', + properties: { + bar: { + type: ElasticsearchDataType.integer + }, + baz: { + type: ElasticsearchDataType.text + } + } + }, + match: '*', + match_mapping_type: '*', + path_match: 'foo.*' + } + } + ] + } +}; diff --git a/test/mapping-model/mappings/src/inherited-property.ts b/test/mapping-model/mappings/src/inherited-property.ts new file mode 100644 index 00000000..4688d166 --- /dev/null +++ b/test/mapping-model/mappings/src/inherited-property.ts @@ -0,0 +1,57 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface InheritedProperty extends Bar{ + foo: number, + + type: ThingType.InheritedProperty; +} + +interface Bar { + /** + * @keyword + */ + bar: string; + + /** + * @float + */ + baz: number; +} + +export const inheritedPropertyTest: MapAggTestOptions = { + name: ThingType.InheritedProperty, + map: { + maps: { + foo: { + type: ElasticsearchDataType.integer + }, + bar: { + type: ElasticsearchDataType.keyword + }, + baz: { + type: ElasticsearchDataType.float + } + } + } +}; diff --git a/test/mapping-model/mappings/src/invalid-tag.ts b/test/mapping-model/mappings/src/invalid-tag.ts new file mode 100644 index 00000000..476bf0db --- /dev/null +++ b/test/mapping-model/mappings/src/invalid-tag.ts @@ -0,0 +1,45 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface InvalidTag { + /** + * @anInvalidTag + */ + foo: string; + + type: ThingType.InvalidTag; +} + +export const invalidTagTest: MapAggTestOptions = { + name: ThingType.InvalidTag, + map: { + maps: { + foo: { + type: ElasticsearchDataType.text + } + } + }, + err: [ + `At "${ThingType.InvalidTag}::foo" for tag "aninvalidtag": Not implemented tag` + ] +}; diff --git a/test/mapping-model/mappings/src/map-explicit-types.ts b/test/mapping-model/mappings/src/map-explicit-types.ts new file mode 100644 index 00000000..a5b394f2 --- /dev/null +++ b/test/mapping-model/mappings/src/map-explicit-types.ts @@ -0,0 +1,66 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface MapExplicitTypes { + /** + * @integer + */ + esInteger: number; + + /** + * @float + */ + esFloat: number; + + /** + * @keyword + */ + esKeyword: string; + + /** + * @text + */ + esText: string; + + type: ThingType.MapExplicitTypes; +} + +export const mapExplicitTypesTest: MapAggTestOptions = { + name: ThingType.MapExplicitTypes, + map: { + maps: { + esInteger: { + type: ElasticsearchDataType.integer + }, + esFloat: { + type: ElasticsearchDataType.float + }, + esKeyword: { + type: ElasticsearchDataType.keyword + }, + esText: { + type: ElasticsearchDataType.text + } + } + } +}; diff --git a/test/mapping-model/mappings/src/missing-premap.ts b/test/mapping-model/mappings/src/missing-premap.ts new file mode 100644 index 00000000..967b4d6c --- /dev/null +++ b/test/mapping-model/mappings/src/missing-premap.ts @@ -0,0 +1,45 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface MissingPremap { + // it really doesn't matter what we use here, as long as it is an external dependency + // if you get an error here because you removed a dependency, feel free to change it around + // to your heart's content + foo: HTMLAllCollection; + + type: ThingType.MissingPremap; +} + +export const missingPremapTest: MapAggTestOptions = { + name: ThingType.MissingPremap, + map: { + maps: { + foo: { + type: ElasticsearchDataType.missing_premap + } + } + }, + err: [ + `At "${ThingType.MissingPremap}::foo" for external type "HTMLAllCollection": Missing pre-map` + ] +}; diff --git a/test/mapping-model/mappings/src/nested.ts b/test/mapping-model/mappings/src/nested.ts new file mode 100644 index 00000000..3436c9cc --- /dev/null +++ b/test/mapping-model/mappings/src/nested.ts @@ -0,0 +1,71 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface Nested { + foo: { + depth1_1: { + depth2_1: { + depth3_1: number; + /** + * @keyword + */ + depth3_2: string; + } + depth2_2: boolean; + } + } + + type: ThingType.Nested; +} + +export const nestedTest: MapAggTestOptions = { + name: ThingType.Nested, + map: { + maps: { + foo: { + dynamic: 'strict', + properties: { + depth1_1: { + dynamic: 'strict', + properties: { + depth2_1: { + dynamic: 'strict', + properties: { + depth3_1: { + type: ElasticsearchDataType.integer + }, + depth3_2: { + type: ElasticsearchDataType.keyword + } + } + }, + depth2_2: { + type: ElasticsearchDataType.boolean + } + } + } + } + } + } + } +}; diff --git a/test/mapping-model/mappings/src/object-union.ts b/test/mapping-model/mappings/src/object-union.ts new file mode 100644 index 00000000..004ed0ca --- /dev/null +++ b/test/mapping-model/mappings/src/object-union.ts @@ -0,0 +1,60 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface ObjectUnion { + foo: Bar | Baz; + + type: ThingType.ObjectUnion +} + +interface Bar { + a: boolean; + intersection: string; +} + +interface Baz { + b: number; + intersection: string; +} + +export const objectUnionTest: MapAggTestOptions = { + name: ThingType.ObjectUnion, + map: { + maps: { + foo: { + dynamic: 'strict', + properties: { + a: { + type: ElasticsearchDataType.boolean + }, + b: { + type: ElasticsearchDataType.integer + }, + intersection: { + type: ElasticsearchDataType.text + } + } + } + } + } +}; diff --git a/test/mapping-model/mappings/src/paired-tags.ts b/test/mapping-model/mappings/src/paired-tags.ts new file mode 100644 index 00000000..74100873 --- /dev/null +++ b/test/mapping-model/mappings/src/paired-tags.ts @@ -0,0 +1,68 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface PairedTags { + /** + * @keyword + * @filterable + */ + foo: string; + + /** + * @text + * @filterable + * @sortable + */ + bar: string; + + type: ThingType.PairedTags; +} + +export const pairedTagsTest: MapAggTestOptions = { + name: ThingType.PairedTags, + map: { + maps: { + foo: { + type: ElasticsearchDataType.keyword, + fields: { + raw: { + type: ElasticsearchDataType.keyword + } + } + }, + bar: { + type: ElasticsearchDataType.text, + fields: { + raw: { + type: ElasticsearchDataType.keyword + }, + sort: { + analyzer: 'ducet_sort', + fielddata: true, + type: ElasticsearchDataType.text + } + } + } + } + } +}; diff --git a/test/mapping-model/mappings/src/sensible-defaults.ts b/test/mapping-model/mappings/src/sensible-defaults.ts new file mode 100644 index 00000000..085654d4 --- /dev/null +++ b/test/mapping-model/mappings/src/sensible-defaults.ts @@ -0,0 +1,59 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface SensibleDefaults { + numberDefault: number; + stringDefault: string; + booleanDefault: boolean; + stringLiteralDefault: 'Hey there!'; + booleanTrueLiteralDefault: true; + booleanFalseLiteralDefault: false; + + type: ThingType.SensibleDefaultType; +} + +export const sensibleDefaultsTest: MapAggTestOptions = { + name: ThingType.SensibleDefaultType, + map: { + maps: { + numberDefault: { + type: ElasticsearchDataType.integer + }, + stringDefault: { + type: ElasticsearchDataType.text + }, + booleanDefault: { + type: ElasticsearchDataType.boolean + }, + stringLiteralDefault: { + type: ElasticsearchDataType.keyword + }, + booleanTrueLiteralDefault: { + type: ElasticsearchDataType.boolean + }, + booleanFalseLiteralDefault: { + type: ElasticsearchDataType.boolean + } + } + } +}; diff --git a/test/mapping-model/mappings/src/sortable-tag.ts b/test/mapping-model/mappings/src/sortable-tag.ts new file mode 100644 index 00000000..526f5738 --- /dev/null +++ b/test/mapping-model/mappings/src/sortable-tag.ts @@ -0,0 +1,79 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface SortableTag { + /** + * @sortable + */ + foo: string; + + /** + * @sortable ducet + */ + bar: string; + + /** + * @sortable + */ + baz: number; + + type: ThingType.SortableTag +} + +export const sortableTagTest: MapAggTestOptions = { + name: ThingType.SortableTag, + map: { + maps: { + foo: { + type: ElasticsearchDataType.text, + fields: { + sort: { + analyzer: 'ducet_sort', + fielddata: true, + type: 'text' + } + } + }, + bar: { + type: ElasticsearchDataType.text, + fields: { + sort: { + analyzer: 'ducet_sort', + fielddata: true, + type: 'text' + } + } + }, + baz: { + type: ElasticsearchDataType.integer, + fields: { + sort: { + analyzer: 'ducet_sort', + fielddata: true, + type: 'text' + } + } + } + } + } +}; diff --git a/test/mapping-model/mappings/src/type-query.ts b/test/mapping-model/mappings/src/type-query.ts new file mode 100644 index 00000000..75edaba7 --- /dev/null +++ b/test/mapping-model/mappings/src/type-query.ts @@ -0,0 +1,45 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface TypeQuery { + foo: typeof Bar; + + type: ThingType.TypeQuery; +} + +enum Bar { + 'a', + 'b', + 'c' +} + +export const typeQueryTest: MapAggTestOptions = { + name: ThingType.TypeQuery, + map: { + maps: { + foo: { + type: ElasticsearchDataType.text + } + } + } +}; diff --git a/test/mapping-model/mappings/src/type-wrapper-inheritance.ts b/test/mapping-model/mappings/src/type-wrapper-inheritance.ts new file mode 100644 index 00000000..c8b97b08 --- /dev/null +++ b/test/mapping-model/mappings/src/type-wrapper-inheritance.ts @@ -0,0 +1,67 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +import {ThingType} from './types'; +import {MapAggTestOptions} from '../../MapAggTestOptions'; +import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap'; + +/** + * @indexable + */ +export interface TypeWrapperInheritance { + /** + * @float + */ + numberWrapper: NumberWrapper; + + /** + * @keyword + */ + stringWrapper: StringWrapper; + + /** + * @text + */ + stringLiteralWrapper: StringLiteralWrapper; + + type: ThingType.TypeWrapperInheritance +} + +type NumberWrapper = number; +type StringWrapper = string; +type StringLiteralWrapper = 'foo'; + +export const typeWrapperInheritanceTest: MapAggTestOptions = { + name: ThingType.TypeWrapperInheritance, + map: { + maps: { + foo: { + dynamic: 'strict', + properties: { + numberWrapper: { + type: ElasticsearchDataType.float + }, + stringWrapper: { + type: ElasticsearchDataType.keyword + }, + stringLiteralWrapper: { + type: ElasticsearchDataType.text + } + } + } + } + } +}; diff --git a/test/mapping-model/mappings/src/types.ts b/test/mapping-model/mappings/src/types.ts new file mode 100644 index 00000000..387bf24b --- /dev/null +++ b/test/mapping-model/mappings/src/types.ts @@ -0,0 +1,38 @@ +// tslint:disable +/* + * Copyright (C) 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +export enum ThingType { + MapExplicitTypes = 'map explicit types', + DoubleTypeConflict = 'double type conflict', + IncompatibleType = 'incompatible type', + SensibleDefaultType = 'sensible default', + InvalidTag = 'invalid tag', + MissingPremap = 'missing premap', + DefaultGeneric = 'default generic', + Generics = 'generics', + Nested = 'nested', + IndexSignature = 'index signature', + ImpossibleUnion = 'impossible union', + TypeQuery = 'type query', + ObjectUnion = 'object union', + TypeWrapperInheritance = 'type wrapper inheritance', + SortableTag = 'sortable tag', + Enum = 'enum', + InheritedProperty = 'inherited property', + PairedTags = 'paired tags', + FilterableTag = 'filterable tag', + AnyUnknown = 'any unknown', +} diff --git a/test/mapping-model/mappings/tsconfig.json b/test/mapping-model/mappings/tsconfig.json new file mode 100644 index 00000000..c7a33719 --- /dev/null +++ b/test/mapping-model/mappings/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../../node_modules/@openstapps/configuration/tsconfig.json" +} diff --git a/test/mapping.spec.ts b/test/mapping.spec.ts new file mode 100644 index 00000000..f5c6b0fc --- /dev/null +++ b/test/mapping.spec.ts @@ -0,0 +1,153 @@ +// tslint:disable +/* + * Copyright (C) 2020 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * 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 General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +import {Logger} from '@openstapps/logger'; +import {slow, suite, test, timeout} from 'mocha-typescript'; +import {MapAggTest} from './mapping-model/MapAggTest'; +import {mapExplicitTypesTest} from './mapping-model/mappings/src/map-explicit-types'; +import {doubleTypeConflictTest} from './mapping-model/mappings/src/double-type-conflict'; +import {incompatibleTypeTest} from './mapping-model/mappings/src/incompatible-type'; +import {sensibleDefaultsTest} from './mapping-model/mappings/src/sensible-defaults'; +import {invalidTagTest} from './mapping-model/mappings/src/invalid-tag'; +import {missingPremapTest} from './mapping-model/mappings/src/missing-premap'; +import {defaultGenericTest} from './mapping-model/mappings/src/default-generics'; +import {genericTest} from './mapping-model/mappings/src/generics'; +import {nestedTest} from './mapping-model/mappings/src/nested'; +import {indexSignatureTest} from './mapping-model/mappings/src/index-signature'; +import {impossibleUnionTest} from './mapping-model/mappings/src/impossible-union'; +import {typeQueryTest} from './mapping-model/mappings/src/type-query'; +import {objectUnionTest} from './mapping-model/mappings/src/object-union'; +import {sortableTagTest} from './mapping-model/mappings/src/sortable-tag'; +import {enumTest} from './mapping-model/mappings/src/enum'; +import {inheritedPropertyTest} from './mapping-model/mappings/src/inherited-property'; +import {pairedTagsTest} from './mapping-model/mappings/src/paired-tags'; +import {filterableTagTest} from './mapping-model/mappings/src/filterable-tag'; +import {anyUnknownTest} from './mapping-model/mappings/src/any-unknown'; + +process.on('unhandledRejection', (error: unknown) => { + if (error instanceof Error) { + void Logger.error('UNHANDLED REJECTION', error.stack); + } + process.exit(1); +}); + +const magAppInstance = new MapAggTest('mappings'); + +@suite(timeout(20000), slow(10000)) +export class MappingSpec { + @test + async 'Any or unknown should create a dynamic field'() { + magAppInstance.testInterfaceAgainstPath(anyUnknownTest); + } + + @test + async 'Filterable tag should add raw field to strings'() { + magAppInstance.testInterfaceAgainstPath(filterableTagTest); + } + + @test + async 'Tags should be able to be paired'() { + magAppInstance.testInterfaceAgainstPath(pairedTagsTest); + } + + @test + async 'Inherited properties should inherit tags'() { + magAppInstance.testInterfaceAgainstPath(inheritedPropertyTest); + } + + @test + async 'Emums should work'() { + // Known issue: Enums only use text + // https://gitlab.com/openstapps/core-tools/-/issues/46 + magAppInstance.testInterfaceAgainstPath(enumTest); + } + + @test + 'Sortable tag should work'() { + magAppInstance.testInterfaceAgainstPath(sortableTagTest); + } + + /* + https://gitlab.com/openstapps/core-tools/-/merge_requests/29 + @test + async 'Wrapper types should inherit tags'() { + this.testInterfaceAgainstPath(typeWrapperInheritanceTest); + }*/ + + @test + async 'Object union types should work'() { + magAppInstance.testInterfaceAgainstPath(objectUnionTest); + } + + @test + async 'Type queries should work'() { + magAppInstance.testInterfaceAgainstPath(typeQueryTest); + } + + @test + async 'Impossible union should cause an error'() { + magAppInstance.testInterfaceAgainstPath(impossibleUnionTest); + } + + @test + async 'Index Signatures should work'() { + magAppInstance.testInterfaceAgainstPath(indexSignatureTest); + } + + @test + async 'Nested properties should work'() { + magAppInstance.testInterfaceAgainstPath(nestedTest); + } + + @test + async 'Generics should work'() { + magAppInstance.testInterfaceAgainstPath(genericTest); + } + + @test + async 'Missing premap should cause an error'() { + magAppInstance.testInterfaceAgainstPath(missingPremapTest); + } + + @test + async 'Default generics should fail (if they don\'t that\'s actually brilliant)'() { + magAppInstance.testInterfaceAgainstPath(defaultGenericTest); + } + + @test + async 'Explicit type annotations should work'() { + magAppInstance.testInterfaceAgainstPath(mapExplicitTypesTest); + } + + @test + async 'Double type annotations should cause an error'() { + magAppInstance.testInterfaceAgainstPath(doubleTypeConflictTest); + } + + @test + async 'Incompatible type annotations should cause an error and use defaults'() { + magAppInstance.testInterfaceAgainstPath(incompatibleTypeTest); + } + + @test + async 'Primitive types should have sensible defaults'() { + magAppInstance.testInterfaceAgainstPath(sensibleDefaultsTest); + } + + @test + async 'Invalid tags should cause an error'() { + magAppInstance.testInterfaceAgainstPath(invalidTagTest); + } +}