diff --git a/package-lock.json b/package-lock.json
index e8f6e918..3cec2d9d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -274,9 +274,9 @@
"dev": true
},
"@types/mocha": {
- "version": "8.2.3",
- "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.2.3.tgz",
- "integrity": "sha512-ekGvFhFgrc2zYQoX4JeZPmVzZxw6Dtllga7iGHzfbYIYkAMUx/sAFP2GdFpLff+vdHXu5fl7WX9AT+TtqYcsyw==",
+ "version": "9.0.0",
+ "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-9.0.0.tgz",
+ "integrity": "sha512-scN0hAWyLVAvLR9AyW7HoFF5sJZglyBsbPuHO4fv7JRvfmPBMfp1ozWqOf/e4wwPNxezBZXRfWzMb6iFLgEVRA==",
"dev": true
},
"@types/node": {
@@ -355,15 +355,15 @@
}
},
"acorn": {
- "version": "8.4.1",
- "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.4.1.tgz",
- "integrity": "sha512-asabaBSkEKosYKMITunzX177CXxQ4Q8BSSzMTKD+FefUhipQC70gfW5SiUDhYQ3vk8G+81HqQk7Fv9OXwwn9KA==",
+ "version": "8.5.0",
+ "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.5.0.tgz",
+ "integrity": "sha512-yXbYeFy+jUuYd3/CDcg2NkIYE991XYX/bje7LmjJigUciaeO1JR4XxXgCIV1/Zc/dRuFEyw1L0pbA+qynJkW5Q==",
"dev": true
},
"acorn-walk": {
- "version": "8.1.1",
- "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.1.1.tgz",
- "integrity": "sha512-FbJdceMlPHEAWJOILDk1fXD8lnTlEIWFkqtfk+MvmL5q/qlHfN7GEHcsFZWt/Tea9jRNPWUZG4G976nqAAmU9w==",
+ "version": "8.2.0",
+ "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz",
+ "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==",
"dev": true
},
"add-stream": {
@@ -1850,9 +1850,9 @@
}
},
"mocha": {
- "version": "9.0.3",
- "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.0.3.tgz",
- "integrity": "sha512-hnYFrSefHxYS2XFGtN01x8un0EwNu2bzKvhpRFhgoybIvMaOkkL60IVPmkb5h6XDmUl4IMSB+rT5cIO4/4bJgg==",
+ "version": "9.1.1",
+ "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.1.1.tgz",
+ "integrity": "sha512-0wE74YMgOkCgBUj8VyIDwmLUjTsS13WV1Pg7l0SHea2qzZzlq7MDnfbPsHKcELBRk3+izEVkRofjmClpycudCA==",
"dev": true,
"requires": {
"@ungap/promise-all-settled": "1.1.2",
diff --git a/package.json b/package.json
index 948bada2..642956cb 100644
--- a/package.json
+++ b/package.json
@@ -35,11 +35,11 @@
"@openstapps/configuration": "0.27.0",
"@testdeck/mocha": "0.1.2",
"@types/chai": "4.2.21",
- "@types/mocha": "8.2.3",
+ "@types/mocha": "9.0.0",
"@types/node": "14.17.9",
"@types/rimraf": "3.0.1",
"conventional-changelog-cli": "2.1.1",
- "mocha": "9.0.3",
+ "mocha": "9.1.1",
"chai": "4.3.4",
"nock": "13.1.1",
"prepend-file-cli": "1.0.6",
diff --git a/src/config/typemap.ts b/src/config/typemap.ts
index 3b6ec45f..2815131f 100644
--- a/src/config/typemap.ts
+++ b/src/config/typemap.ts
@@ -67,4 +67,17 @@ export const typemap: ElasticsearchTypemap = {
},
};
+/**
+ * If the string is a tag type
+ */
+export function isTagType(str: string): boolean {
+ for (const key in typemap) {
+ if (typemap.hasOwnProperty(key) && typeof typemap[key][str] !== 'undefined') {
+ return true;
+ }
+ }
+
+ return false;
+}
+
export const dynamicTypes = ['any', 'unknown'];
diff --git a/src/mapping.ts b/src/mapping.ts
index 17fb0087..f157b262 100644
--- a/src/mapping.ts
+++ b/src/mapping.ts
@@ -31,7 +31,7 @@ import {
import {fieldmap, filterableMap, filterableTagName} from './config/fieldmap';
import {premaps} from './config/premap';
import {settings} from './config/settings';
-import {dynamicTypes, ElasticsearchDataType, typemap} from './config/typemap';
+import {dynamicTypes, ElasticsearchDataType, isTagType, typemap} from './config/typemap';
import {AggregationSchema, ESNestedAggregation} from './types/aggregation';
import {
ElasticsearchDynamicTemplate,
@@ -275,7 +275,11 @@ function handleDeclarationReflection(decl: DeclarationReflection,
}
} else if (decl.type instanceof Type) { // if the object is a type, so we are dealing with a PROPERTY
// get inherited tags
- const tags = (inheritedTags ?? []).length > 0 ? inheritedTags! : getCommentTags(decl, path, topTypeName);
+ const tags = (inheritedTags ?? []).length > 0
+ ? (typeof inheritedTags!.find(it => isTagType(it.tagName)) !== 'undefined'
+ ? inheritedTags!
+ : [...inheritedTags ?? [], ...getCommentTags(decl, path, topTypeName)])
+ : getCommentTags(decl, path, topTypeName);
return handleType(decl.type, new Map(generics), path, topTypeName, tags);
} else if (decl.kindString === 'Enumeration member') {
diff --git a/test/aggregations.spec.ts b/test/aggregations.spec.ts
index 026c38e2..16e6e206 100644
--- a/test/aggregations.spec.ts
+++ b/test/aggregations.spec.ts
@@ -13,59 +13,38 @@
* this program. If not, see .
*/
import {Logger} from '@openstapps/logger';
-import {slow, suite, test, timeout} from '@testdeck/mocha';
+import {readdirSync, statSync} from 'fs';
+import path from 'path';
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';
+import {MapAggTestOptions} from './mapping-model/MapAggTestOptions';
-process.on('unhandledRejection', (error: unknown) => {
- if (error instanceof Error) {
- void Logger.error('UNHANDLED REJECTION', error.stack);
- }
- process.exit(1);
-});
+describe('ES Aggregation Gen', async () => {
+ const magAppInstance = new MapAggTest('aggregations');
-const magAppInstance = new MapAggTest('aggregations');
+ /**
+ * Expand a path to a list of all files deeply contained in it
+ */
+ function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
+ const fullPath = path.resolve(sourcePath);
+ const directory = statSync(fullPath);
-@suite(timeout(20000), slow(10000))
-export class AggregationsSpec {
- @test
- async 'Aggregation tag should propagate on arrays'() {
- magAppInstance.testInterfaceAgainstPath(aggArrayTest);
+ return directory.isDirectory()
+ ? ([] as string[]).concat(...readdirSync(fullPath).map(fragment =>
+ expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
+ ))
+ : [fullPath].filter(accept);
}
- @test
- async 'Should work on nested properties'() {
- magAppInstance.testInterfaceAgainstPath(aggNestedTest);
- }
+ for (const file of expandPathToFilesSync('./test/mapping-model/aggregations/', file => file.endsWith('agg-test.ts'))) {
+ try {
+ const test = (await import(file))['testConfig'] as MapAggTestOptions;
- @test
- async 'Global option should work'() {
- magAppInstance.testInterfaceAgainstPath(aggGlobalTest);
+ it(test.testName, function () {
+ magAppInstance.testInterfaceAgainstPath(test);
+ });
+ } catch (error) {
+ await Logger.error('UNHANDLED REJECTION', error.stack);
+ process.exit(1);
+ }
}
-
- @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);
- }
-}
+}).timeout(20_000).slow(10_000);
diff --git a/test/mapping-model/MapAggTestOptions.ts b/test/mapping-model/MapAggTestOptions.ts
index 1150260f..d1699927 100644
--- a/test/mapping-model/MapAggTestOptions.ts
+++ b/test/mapping-model/MapAggTestOptions.ts
@@ -16,6 +16,7 @@
import {ElasticsearchDynamicTemplate, ElasticsearchValue} from '../../src/types/mapping';
export interface MapAggTestOptions {
+ testName: string;
name: string;
agg?: {
fields?: string[];
diff --git a/test/mapping-model/aggregations/src/agg-array.ts b/test/mapping-model/aggregations/src/agg-array.agg-test.ts
similarity index 89%
rename from test/mapping-model/aggregations/src/agg-array.ts
rename to test/mapping-model/aggregations/src/agg-array.agg-test.ts
index ea3085e8..23536429 100644
--- a/test/mapping-model/aggregations/src/agg-array.ts
+++ b/test/mapping-model/aggregations/src/agg-array.agg-test.ts
@@ -29,7 +29,8 @@ export interface AggArray {
}
type Foo = 'A' | 'B' | 'C';
-export const aggArrayTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Aggregation tag should propagate on arrays',
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.agg-test.ts
similarity index 91%
rename from test/mapping-model/aggregations/src/agg-global-nested.ts
rename to test/mapping-model/aggregations/src/agg-global-nested.agg-test.ts
index cc956902..e3eee5e2 100644
--- a/test/mapping-model/aggregations/src/agg-global-nested.ts
+++ b/test/mapping-model/aggregations/src/agg-global-nested.agg-test.ts
@@ -30,7 +30,8 @@ export interface AggGlobalNested {
type: ThingType.AggGlobalNested;
}
-export const aggGlobalNestedTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Global aggregations when nested',
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.agg-test.ts
similarity index 91%
rename from test/mapping-model/aggregations/src/agg-global.ts
rename to test/mapping-model/aggregations/src/agg-global.agg-test.ts
index f09093ef..eab4931c 100644
--- a/test/mapping-model/aggregations/src/agg-global.ts
+++ b/test/mapping-model/aggregations/src/agg-global.agg-test.ts
@@ -28,7 +28,8 @@ export interface AggGlobal {
type: ThingType.AggGlobal;
}
-export const aggGlobalTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Global option should work',
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.agg-test.ts
similarity index 90%
rename from test/mapping-model/aggregations/src/agg-inherited-global.ts
rename to test/mapping-model/aggregations/src/agg-inherited-global.agg-test.ts
index d131ccc9..382edc21 100644
--- a/test/mapping-model/aggregations/src/agg-inherited-global.ts
+++ b/test/mapping-model/aggregations/src/agg-inherited-global.agg-test.ts
@@ -31,7 +31,8 @@ interface Foo {
bar: string;
}
-export const aggInheritedGlobalTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Inherited global aggregations should work',
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.agg-test.ts
similarity index 89%
rename from test/mapping-model/aggregations/src/agg-inherited-overwritten.ts
rename to test/mapping-model/aggregations/src/agg-inherited-overwritten.agg-test.ts
index f103e67f..bd33453e 100644
--- a/test/mapping-model/aggregations/src/agg-inherited-overwritten.ts
+++ b/test/mapping-model/aggregations/src/agg-inherited-overwritten.agg-test.ts
@@ -36,7 +36,8 @@ interface Foo {
bar: string;
}
-export const aggInheritedOverwrittenTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Inherited aggregations should work when overwritten',
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.agg-test.ts
similarity index 90%
rename from test/mapping-model/aggregations/src/agg-inherited.ts
rename to test/mapping-model/aggregations/src/agg-inherited.agg-test.ts
index 2d1a8af7..d4ac43cd 100644
--- a/test/mapping-model/aggregations/src/agg-inherited.ts
+++ b/test/mapping-model/aggregations/src/agg-inherited.agg-test.ts
@@ -31,7 +31,8 @@ interface Foo {
bar: string;
}
-export const aggInheritedTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Inherited aggregations should work',
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.agg-test.ts
similarity index 90%
rename from test/mapping-model/aggregations/src/agg-nested.ts
rename to test/mapping-model/aggregations/src/agg-nested.agg-test.ts
index 2b64d6fc..8b693490 100644
--- a/test/mapping-model/aggregations/src/agg-nested.ts
+++ b/test/mapping-model/aggregations/src/agg-nested.agg-test.ts
@@ -30,7 +30,8 @@ export interface AggNested {
type: ThingType.AggNested;
}
-export const aggNestedTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Should work on nested properties',
name: ThingType.AggNested,
agg: {
fields: ['nested.foo'],
diff --git a/test/mapping-model/mappings/src/any-unknown.ts b/test/mapping-model/mappings/src/any-unknown.mapping-test.ts
similarity index 90%
rename from test/mapping-model/mappings/src/any-unknown.ts
rename to test/mapping-model/mappings/src/any-unknown.mapping-test.ts
index 6fd86060..a4b5059b 100644
--- a/test/mapping-model/mappings/src/any-unknown.ts
+++ b/test/mapping-model/mappings/src/any-unknown.mapping-test.ts
@@ -27,7 +27,8 @@ export interface AnyUnknown {
type: ThingType.AnyUnknown
}
-export const anyUnknownTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Any or unknown should create a dynamic field',
name: ThingType.AnyUnknown,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/date.ts b/test/mapping-model/mappings/src/date.mapping-test.ts
similarity index 91%
rename from test/mapping-model/mappings/src/date.ts
rename to test/mapping-model/mappings/src/date.mapping-test.ts
index 863e95a8..f1fb2f8f 100644
--- a/test/mapping-model/mappings/src/date.ts
+++ b/test/mapping-model/mappings/src/date.mapping-test.ts
@@ -36,7 +36,8 @@ export interface DateAndRange {
type: ThingType.Date
}
-export const dateAndRangeTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Dates and date ranges should have the correct type',
name: ThingType.Date,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/default-generics.ts b/test/mapping-model/mappings/src/default-generics.mapping-test.ts
similarity index 93%
rename from test/mapping-model/mappings/src/default-generics.ts
rename to test/mapping-model/mappings/src/default-generics.mapping-test.ts
index 88b20b7e..1f6e1b2c 100644
--- a/test/mapping-model/mappings/src/default-generics.ts
+++ b/test/mapping-model/mappings/src/default-generics.mapping-test.ts
@@ -30,7 +30,8 @@ interface InterfaceWithDefaultGeneric {
bar: T;
}
-export const defaultGenericTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Default generics should fail',
name: ThingType.DefaultGeneric,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/double-type-conflict.ts b/test/mapping-model/mappings/src/double-type-conflict.mapping-test.ts
similarity index 93%
rename from test/mapping-model/mappings/src/double-type-conflict.ts
rename to test/mapping-model/mappings/src/double-type-conflict.mapping-test.ts
index 034bbeaf..1414c488 100644
--- a/test/mapping-model/mappings/src/double-type-conflict.ts
+++ b/test/mapping-model/mappings/src/double-type-conflict.mapping-test.ts
@@ -36,7 +36,8 @@ export interface DoubleTypeConflict {
type: ThingType.DoubleTypeConflict;
}
-export const doubleTypeConflictTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Double type annotations should cause an error',
name: ThingType.DoubleTypeConflict,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/enum.ts b/test/mapping-model/mappings/src/enum.mapping-test.ts
similarity index 86%
rename from test/mapping-model/mappings/src/enum.ts
rename to test/mapping-model/mappings/src/enum.mapping-test.ts
index 62b233c3..2617780a 100644
--- a/test/mapping-model/mappings/src/enum.ts
+++ b/test/mapping-model/mappings/src/enum.mapping-test.ts
@@ -40,7 +40,10 @@ enum Baz {
f = 'f',
}
-export const enumTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ // Known issue: Enums only use text
+ // https://gitlab.com/openstapps/core-tools/-/issues/46
+ testName: 'Emums should work',
name: ThingType.Enum,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/filterable-tag.ts b/test/mapping-model/mappings/src/filterable-tag.mapping-test.ts
similarity index 94%
rename from test/mapping-model/mappings/src/filterable-tag.ts
rename to test/mapping-model/mappings/src/filterable-tag.mapping-test.ts
index 7ddcb345..86f9b792 100644
--- a/test/mapping-model/mappings/src/filterable-tag.ts
+++ b/test/mapping-model/mappings/src/filterable-tag.mapping-test.ts
@@ -48,7 +48,8 @@ export interface FilterableTag {
type: ThingType.FilterableTag
}
-export const filterableTagTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Filterable tag should add raw field to strings',
name: ThingType.FilterableTag,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/generics.ts b/test/mapping-model/mappings/src/generics.mapping-test.ts
similarity index 94%
rename from test/mapping-model/mappings/src/generics.ts
rename to test/mapping-model/mappings/src/generics.mapping-test.ts
index f0be68dd..bba84d4f 100644
--- a/test/mapping-model/mappings/src/generics.ts
+++ b/test/mapping-model/mappings/src/generics.mapping-test.ts
@@ -35,7 +35,8 @@ interface InterfaceWithStringGeneric {
bar: T;
}
-export const genericTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Generics should work',
name: ThingType.Generics,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/impossible-union.ts b/test/mapping-model/mappings/src/impossible-union.mapping-test.ts
similarity index 92%
rename from test/mapping-model/mappings/src/impossible-union.ts
rename to test/mapping-model/mappings/src/impossible-union.mapping-test.ts
index 8bb9ee13..d143c966 100644
--- a/test/mapping-model/mappings/src/impossible-union.ts
+++ b/test/mapping-model/mappings/src/impossible-union.mapping-test.ts
@@ -26,7 +26,8 @@ export interface ImpossibleUnion {
type: ThingType.ImpossibleUnion
}
-export const impossibleUnionTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Impossible union should cause an error',
name: ThingType.ImpossibleUnion,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/incompatible-type.ts b/test/mapping-model/mappings/src/incompatible-type.mapping-test.ts
similarity index 93%
rename from test/mapping-model/mappings/src/incompatible-type.ts
rename to test/mapping-model/mappings/src/incompatible-type.mapping-test.ts
index 34eb2ecb..b0b26108 100644
--- a/test/mapping-model/mappings/src/incompatible-type.ts
+++ b/test/mapping-model/mappings/src/incompatible-type.mapping-test.ts
@@ -45,7 +45,8 @@ export interface DoubleTypeConflict {
type: ThingType.IncompatibleType;
}
-export const incompatibleTypeTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Incompatible type annotations should cause an error and use defaults',
name: ThingType.IncompatibleType,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/index-signature.ts b/test/mapping-model/mappings/src/index-signature.mapping-test.ts
similarity index 94%
rename from test/mapping-model/mappings/src/index-signature.ts
rename to test/mapping-model/mappings/src/index-signature.mapping-test.ts
index ea9afeeb..882c3966 100644
--- a/test/mapping-model/mappings/src/index-signature.ts
+++ b/test/mapping-model/mappings/src/index-signature.mapping-test.ts
@@ -31,7 +31,8 @@ export interface IndexSignature {
type: ThingType.IndexSignature;
}
-export const indexSignatureTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Index Signatures should work',
name: ThingType.IndexSignature,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/inferred-type-filterable.mapping-test.ts b/test/mapping-model/mappings/src/inferred-type-filterable.mapping-test.ts
new file mode 100644
index 00000000..bd91b4ee
--- /dev/null
+++ b/test/mapping-model/mappings/src/inferred-type-filterable.mapping-test.ts
@@ -0,0 +1,60 @@
+/*
+ * 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 {ElasticsearchDataType} from '../../../../src/config/typemap';
+import {MapAggTestOptions} from '../../MapAggTestOptions';
+import {ThingType} from './types';
+
+/**
+ * @date
+ */
+export type SCISO8601Date = string;
+
+/**
+ * @indexable
+ */
+export interface InferredTypeFilterable {
+ /**
+ * @filterable
+ */
+ foo: SCISO8601Date;
+
+ /**
+ * // no tag
+ */
+ bar: SCISO8601Date;
+
+ type: ThingType.InferredTypeFilterable
+}
+
+export const testConfig: MapAggTestOptions = {
+ testName: 'filterable tags should not override inferred tags',
+ name: ThingType.InferredTypeFilterable,
+ map: {
+ maps: {
+ foo: {
+ type: ElasticsearchDataType.date,
+ fields: {
+ raw: {
+ type: ElasticsearchDataType.keyword,
+ }
+ }
+ },
+ bar: {
+ type: ElasticsearchDataType.date,
+ }
+ }
+ }
+};
diff --git a/test/mapping-model/mappings/src/inherit-tags.ts b/test/mapping-model/mappings/src/inherit-tags.mapping-test.ts
similarity index 93%
rename from test/mapping-model/mappings/src/inherit-tags.ts
rename to test/mapping-model/mappings/src/inherit-tags.mapping-test.ts
index 8d4bdb20..22e3b545 100644
--- a/test/mapping-model/mappings/src/inherit-tags.ts
+++ b/test/mapping-model/mappings/src/inherit-tags.mapping-test.ts
@@ -36,7 +36,8 @@ export interface InheritTags {
type: ThingType.InheritTags;
}
-export const inheritTagsTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Inherit tags tag should work',
name: ThingType.InheritTags,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/inherited-property.ts b/test/mapping-model/mappings/src/inherited-property.mapping-test.ts
similarity index 92%
rename from test/mapping-model/mappings/src/inherited-property.ts
rename to test/mapping-model/mappings/src/inherited-property.mapping-test.ts
index 4f0ffb83..8453d2b3 100644
--- a/test/mapping-model/mappings/src/inherited-property.ts
+++ b/test/mapping-model/mappings/src/inherited-property.mapping-test.ts
@@ -38,7 +38,8 @@ interface Bar {
baz: number;
}
-export const inheritedPropertyTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Inherited properties should inherit tags',
name: ThingType.InheritedProperty,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/invalid-tag.ts b/test/mapping-model/mappings/src/invalid-tag.mapping-test.ts
similarity index 92%
rename from test/mapping-model/mappings/src/invalid-tag.ts
rename to test/mapping-model/mappings/src/invalid-tag.mapping-test.ts
index 40c7fda0..eafa7d27 100644
--- a/test/mapping-model/mappings/src/invalid-tag.ts
+++ b/test/mapping-model/mappings/src/invalid-tag.mapping-test.ts
@@ -29,7 +29,8 @@ export interface InvalidTag {
type: ThingType.InvalidTag;
}
-export const invalidTagTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Invalid tags should cause an error',
name: ThingType.InvalidTag,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/map-explicit-types.ts b/test/mapping-model/mappings/src/map-explicit-types.mapping-test.ts
similarity index 94%
rename from test/mapping-model/mappings/src/map-explicit-types.ts
rename to test/mapping-model/mappings/src/map-explicit-types.mapping-test.ts
index 62336a1e..3e2241bc 100644
--- a/test/mapping-model/mappings/src/map-explicit-types.ts
+++ b/test/mapping-model/mappings/src/map-explicit-types.mapping-test.ts
@@ -54,7 +54,8 @@ export interface MapExplicitTypes {
type: ThingType.MapExplicitTypes;
}
-export const mapExplicitTypesTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Explicit type annotations should work',
name: ThingType.MapExplicitTypes,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/missing-premap.ts b/test/mapping-model/mappings/src/missing-premap.mapping-test.ts
similarity index 93%
rename from test/mapping-model/mappings/src/missing-premap.ts
rename to test/mapping-model/mappings/src/missing-premap.mapping-test.ts
index 7414b824..ba23aa94 100644
--- a/test/mapping-model/mappings/src/missing-premap.ts
+++ b/test/mapping-model/mappings/src/missing-premap.mapping-test.ts
@@ -29,7 +29,8 @@ export interface MissingPremap {
type: ThingType.MissingPremap;
}
-export const missingPremapTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Missing premap should cause an error',
name: ThingType.MissingPremap,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/nested.ts b/test/mapping-model/mappings/src/nested.mapping-test.ts
similarity index 94%
rename from test/mapping-model/mappings/src/nested.ts
rename to test/mapping-model/mappings/src/nested.mapping-test.ts
index 6ea3d260..6d6d1033 100644
--- a/test/mapping-model/mappings/src/nested.ts
+++ b/test/mapping-model/mappings/src/nested.mapping-test.ts
@@ -37,7 +37,8 @@ export interface Nested {
type: ThingType.Nested;
}
-export const nestedTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Nested properties should work',
name: ThingType.Nested,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/object-union.ts b/test/mapping-model/mappings/src/object-union.mapping-test.ts
similarity index 94%
rename from test/mapping-model/mappings/src/object-union.ts
rename to test/mapping-model/mappings/src/object-union.mapping-test.ts
index 176046d0..17f15997 100644
--- a/test/mapping-model/mappings/src/object-union.ts
+++ b/test/mapping-model/mappings/src/object-union.mapping-test.ts
@@ -40,7 +40,8 @@ interface Buu {
intersection: string;
}
-export const objectUnionTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Object union types should work',
name: ThingType.ObjectUnion,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/paired-tags.ts b/test/mapping-model/mappings/src/paired-tags.mapping-test.ts
similarity index 94%
rename from test/mapping-model/mappings/src/paired-tags.ts
rename to test/mapping-model/mappings/src/paired-tags.mapping-test.ts
index 8945bf9f..bdd7c169 100644
--- a/test/mapping-model/mappings/src/paired-tags.ts
+++ b/test/mapping-model/mappings/src/paired-tags.mapping-test.ts
@@ -37,7 +37,8 @@ export interface PairedTags {
type: ThingType.PairedTags;
}
-export const pairedTagsTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Tags should be able to be paired',
name: ThingType.PairedTags,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/sensible-defaults.ts b/test/mapping-model/mappings/src/sensible-defaults.mapping-test.ts
similarity index 93%
rename from test/mapping-model/mappings/src/sensible-defaults.ts
rename to test/mapping-model/mappings/src/sensible-defaults.mapping-test.ts
index 547a4422..4d4da243 100644
--- a/test/mapping-model/mappings/src/sensible-defaults.ts
+++ b/test/mapping-model/mappings/src/sensible-defaults.mapping-test.ts
@@ -31,7 +31,8 @@ export interface SensibleDefaults {
type: ThingType.SensibleDefaultType;
}
-export const sensibleDefaultsTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Primitive types should have sensible defaults',
name: ThingType.SensibleDefaultType,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/sortable-tag.ts b/test/mapping-model/mappings/src/sortable-tag.mapping-test.ts
similarity index 95%
rename from test/mapping-model/mappings/src/sortable-tag.ts
rename to test/mapping-model/mappings/src/sortable-tag.mapping-test.ts
index 6d55eeeb..ca261727 100644
--- a/test/mapping-model/mappings/src/sortable-tag.ts
+++ b/test/mapping-model/mappings/src/sortable-tag.mapping-test.ts
@@ -39,7 +39,8 @@ export interface SortableTag {
type: ThingType.SortableTag
}
-export const sortableTagTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Sortable tag should work',
name: ThingType.SortableTag,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/tags-ignore-case.ts b/test/mapping-model/mappings/src/tags-ignore-case.mapping-test.ts
similarity index 94%
rename from test/mapping-model/mappings/src/tags-ignore-case.ts
rename to test/mapping-model/mappings/src/tags-ignore-case.mapping-test.ts
index 5ee18da3..cdf8bb42 100644
--- a/test/mapping-model/mappings/src/tags-ignore-case.ts
+++ b/test/mapping-model/mappings/src/tags-ignore-case.mapping-test.ts
@@ -40,7 +40,8 @@ export interface TagsIgnoreCase {
type: ThingType.TagsIgnoreCase;
}
-export const tagsIgnoreCaseTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Tags should ignore case',
name: ThingType.TagsIgnoreCase,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/type-alias.ts b/test/mapping-model/mappings/src/type-alias.mapping-test.ts
similarity index 93%
rename from test/mapping-model/mappings/src/type-alias.ts
rename to test/mapping-model/mappings/src/type-alias.mapping-test.ts
index aaa6a9d7..fef4e47c 100644
--- a/test/mapping-model/mappings/src/type-alias.ts
+++ b/test/mapping-model/mappings/src/type-alias.mapping-test.ts
@@ -49,7 +49,8 @@ type ATextAlias = string;
*/
type AKeywordAlias = string;
-export const typeAliasTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Type alias annotations should work',
name: ThingType.TypeAlias,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/type-overrides.ts b/test/mapping-model/mappings/src/type-overrides.mapping-test.ts
similarity index 91%
rename from test/mapping-model/mappings/src/type-overrides.ts
rename to test/mapping-model/mappings/src/type-overrides.mapping-test.ts
index a400cf1c..95695685 100644
--- a/test/mapping-model/mappings/src/type-overrides.ts
+++ b/test/mapping-model/mappings/src/type-overrides.mapping-test.ts
@@ -30,7 +30,8 @@ export interface TypeOverrides {
type: ThingType.TypeOverrides
}
-export const typeOverridesTest: MapAggTestOptions = {
+export const testConfig: MapAggTestOptions = {
+ testName: 'Premaps should support non-external types',
name: ThingType.TypeOverrides,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/type-query.ts b/test/mapping-model/mappings/src/type-query.mapping-test.disabled.ts
similarity index 87%
rename from test/mapping-model/mappings/src/type-query.ts
rename to test/mapping-model/mappings/src/type-query.mapping-test.disabled.ts
index abe76e91..4485eead 100644
--- a/test/mapping-model/mappings/src/type-query.ts
+++ b/test/mapping-model/mappings/src/type-query.mapping-test.disabled.ts
@@ -32,7 +32,9 @@ enum Bar {
'c'
}
-export const typeQueryTest: MapAggTestOptions = {
+// https://gitlab.com/openstapps/core-tools/-/issues/47
+export const testConfig: MapAggTestOptions = {
+ testName: 'Type queries should work',
name: ThingType.TypeQuery,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/type-wrapper-inheritance.ts b/test/mapping-model/mappings/src/type-wrapper-inheritance.mapping-test.disabled.ts
similarity index 90%
rename from test/mapping-model/mappings/src/type-wrapper-inheritance.ts
rename to test/mapping-model/mappings/src/type-wrapper-inheritance.mapping-test.disabled.ts
index 7e650443..e7990746 100644
--- a/test/mapping-model/mappings/src/type-wrapper-inheritance.ts
+++ b/test/mapping-model/mappings/src/type-wrapper-inheritance.mapping-test.disabled.ts
@@ -43,7 +43,9 @@ type NumberWrapper = number;
type StringWrapper = string;
type StringLiteralWrapper = 'foo';
-export const typeWrapperInheritanceTest: MapAggTestOptions = {
+// https://gitlab.com/openstapps/core-tools/-/merge_requests/29
+export const testConfig: MapAggTestOptions = {
+ testName: 'Wrapper types should inherit tags',
name: ThingType.TypeWrapperInheritance,
map: {
maps: {
diff --git a/test/mapping-model/mappings/src/types.ts b/test/mapping-model/mappings/src/types.ts
index 514e141b..e22cd6b2 100644
--- a/test/mapping-model/mappings/src/types.ts
+++ b/test/mapping-model/mappings/src/types.ts
@@ -34,6 +34,7 @@ export enum ThingType {
PairedTags = 'paired tags',
FilterableTag = 'filterable tag',
AnyUnknown = 'any unknown',
+ InferredTypeFilterable = 'inferred type filterable',
Date = 'date',
InheritTags = 'inherit tags',
TagsIgnoreCase = 'tags ignore case',
diff --git a/test/mapping.spec.ts b/test/mapping.spec.ts
index 41bb6e89..e04e3519 100644
--- a/test/mapping.spec.ts
+++ b/test/mapping.spec.ts
@@ -13,171 +13,38 @@
* this program. If not, see .
*/
import {Logger} from '@openstapps/logger';
-import {slow, suite, test, timeout} from '@testdeck/mocha';
+import {readdirSync, statSync} from 'fs';
+import path from 'path';
import {MapAggTest} from './mapping-model/MapAggTest';
-import {inheritTagsTest} from './mapping-model/mappings/src/inherit-tags';
-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 {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';
-import {tagsIgnoreCaseTest} from './mapping-model/mappings/src/tags-ignore-case';
-import {typeAliasTest} from './mapping-model/mappings/src/type-alias';
-import {dateAndRangeTest} from './mapping-model/mappings/src/date';
-import {typeOverridesTest} from './mapping-model/mappings/src/type-overrides';
+import {MapAggTestOptions} from './mapping-model/MapAggTestOptions';
-process.on('unhandledRejection', (error: unknown) => {
- if (error instanceof Error) {
- void Logger.error('UNHANDLED REJECTION', error.stack);
- }
- process.exit(1);
-});
+describe('ES Mapping Gen', async () => {
+ const magAppInstance = new MapAggTest('mappings');
-const magAppInstance = new MapAggTest('mappings');
+ /**
+ * Expand a path to a list of all files deeply contained in it
+ */
+ function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
+ const fullPath = path.resolve(sourcePath);
+ const directory = statSync(fullPath);
-@suite(timeout(20000), slow(10000))
-export class MappingSpec {
- @test
- async 'Any or unknown should create a dynamic field'() {
- magAppInstance.testInterfaceAgainstPath(anyUnknownTest);
+ return directory.isDirectory()
+ ? ([] as string[]).concat(...readdirSync(fullPath).map(fragment =>
+ expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
+ ))
+ : [fullPath].filter(accept);
}
- @test
- async 'Filterable tag should add raw field to strings'() {
- magAppInstance.testInterfaceAgainstPath(filterableTagTest);
+ for (const file of expandPathToFilesSync('./test/mapping-model/mappings/', file => file.endsWith('mapping-test.ts'))) {
+ try {
+ const test = (await import(file))['testConfig'] as MapAggTestOptions;
+
+ it(test.testName, function () {
+ magAppInstance.testInterfaceAgainstPath(test)
+ })
+ } catch (error) {
+ await Logger.error('UNHANDLED REJECTION', error.stack);
+ process.exit(1);
+ }
}
-
- @test
- async 'Tags should be able to be paired'() {
- magAppInstance.testInterfaceAgainstPath(pairedTagsTest);
- }
-
- @test
- async 'Inherited properties should inherit tags'() {
- magAppInstance.testInterfaceAgainstPath(inheritedPropertyTest);
- }
-
- @test
- async 'Tags should ignore case'() {
- magAppInstance.testInterfaceAgainstPath(tagsIgnoreCaseTest);
- }
-
- @test
- async 'Emums should work'() {
- // Known issue: Enums only use text
- // https://gitlab.com/openstapps/core-tools/-/issues/46
- magAppInstance.testInterfaceAgainstPath(enumTest);
- }
-
- @test
- async '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 'Inherit tags tag should work'() {
- magAppInstance.testInterfaceAgainstPath(inheritTagsTest);
- }
-
- @test
- async 'Object union types should work'() {
- magAppInstance.testInterfaceAgainstPath(objectUnionTest);
- }
-
- /*
- https://gitlab.com/openstapps/core-tools/-/issues/47
- @test
- async 'Type queries should work'() {
- magAppInstance.testInterfaceAgainstPath(typeQueryTest);
- }*/
-
- @test
- async 'Type alias annotations should work'(){
- magAppInstance.testInterfaceAgainstPath(typeAliasTest);
- }
-
- @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'() {
- 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);
- }
-
- @test
- async 'Dates and date ranges should have the correct type'() {
- magAppInstance.testInterfaceAgainstPath(dateAndRangeTest);
- }
-
- @test
- async 'Premaps should support non-external types'() {
- magAppInstance.testInterfaceAgainstPath(typeOverridesTest);
- }
-}
+}).timeout(20_000).slow(10_000);