mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-04-15 02:39:05 +00:00
feat: modernize core-tools
This commit is contained in:
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {slow, suite, test, timeout} from '@testdeck/mocha';
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable unicorn/prefer-module */
|
||||
/*
|
||||
* Copyright (C) 2018-2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
@@ -20,16 +21,15 @@ import {getTsconfigPath} from '../src/common';
|
||||
|
||||
process.on('unhandledRejection', (reason: unknown): void => {
|
||||
if (reason instanceof Error) {
|
||||
Logger.error('UNHANDLED REJECTION', reason.stack);
|
||||
void Logger.error('UNHANDLED REJECTION', reason.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
@suite(timeout(20000), slow(10000))
|
||||
@suite(timeout(20_000), slow(10_000))
|
||||
export class CommonSpec {
|
||||
@test
|
||||
async getTsconfigPath() {
|
||||
expect(getTsconfigPath(__dirname)).to.be.equal(cwd());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable unicorn/prefer-module */
|
||||
/*
|
||||
* Copyright (C) 2018-2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
@@ -13,19 +14,19 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {expect} from 'chai';
|
||||
import {resolve} from 'path';
|
||||
import {existsSync, unlinkSync} from 'fs';
|
||||
import {slow, suite, test, timeout} from '@testdeck/mocha';
|
||||
import {getProjectReflection} from '../src/common';
|
||||
import {createDiagram, createDiagramFromString} from '../src/uml/create-diagram';
|
||||
import {UMLConfig} from '../src/uml/uml-config';
|
||||
import {readDefinitions} from '../src/uml/read-definitions';
|
||||
import {LightweightDefinition} from '../src/uml/model/lightweight-definition';
|
||||
import {LightweightDefinition} from '../src/easy-ast/types/lightweight-definition';
|
||||
import nock = require('nock');
|
||||
import {lightweightDefinitionsFromPath} from '../src/easy-ast/easy-ast';
|
||||
import path from 'path';
|
||||
|
||||
@suite(timeout(15000), slow(5000))
|
||||
@suite(timeout(15_000), slow(5000))
|
||||
export class CreateDiagramSpec {
|
||||
plantUmlConfig: UMLConfig;
|
||||
|
||||
definitions: LightweightDefinition[];
|
||||
|
||||
constructor() {
|
||||
@@ -39,21 +40,20 @@ export class CreateDiagramSpec {
|
||||
showProperties: true,
|
||||
};
|
||||
|
||||
const projectReflection = getProjectReflection('./test/model', true);
|
||||
this.definitions = readDefinitions(projectReflection);
|
||||
this.definitions = lightweightDefinitionsFromPath('./test/model');
|
||||
}
|
||||
|
||||
@test
|
||||
async shouldRefuseRequest() {
|
||||
const testPlantUmlCode: string = 'class Test{\n}';
|
||||
const testPlantUmlCode = 'class Test{\n}';
|
||||
try {
|
||||
await createDiagramFromString(testPlantUmlCode, "http://plantuml:8080");
|
||||
} catch (e) {
|
||||
await createDiagramFromString(testPlantUmlCode, 'http://plantuml:8080');
|
||||
} catch (error) {
|
||||
expect([
|
||||
new Error('getaddrinfo ENOTFOUND plantuml plantuml:8080').message,
|
||||
new Error('getaddrinfo EAI_AGAIN plantuml plantuml:8080').message,
|
||||
new Error('getaddrinfo ENOTFOUND plantuml').message,
|
||||
]).to.include(e.message);
|
||||
]).to.include(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,18 +69,18 @@ export class CreateDiagramSpec {
|
||||
nock('http://plantuml:8080')
|
||||
.persist()
|
||||
.get(() => true)
|
||||
.reply(200, 'This will be the file content')
|
||||
.reply(200, 'This will be the file content');
|
||||
|
||||
let fileName = await createDiagram(this.definitions, this.plantUmlConfig, "http://plantuml:8080");
|
||||
let filePath = resolve(__dirname, '..', fileName);
|
||||
let fileName = await createDiagram(this.definitions, this.plantUmlConfig, 'http://plantuml:8080');
|
||||
let filePath = path.resolve(__dirname, '..', fileName);
|
||||
expect(await existsSync(filePath)).to.equal(true);
|
||||
|
||||
await unlinkSync(fileName);
|
||||
this.plantUmlConfig.showAssociations = false;
|
||||
|
||||
this.plantUmlConfig.showInheritance = false;
|
||||
fileName = await createDiagram(this.definitions, this.plantUmlConfig, "http://plantuml:8080");
|
||||
filePath = resolve(__dirname, '..', fileName);
|
||||
fileName = await createDiagram(this.definitions, this.plantUmlConfig, 'http://plantuml:8080');
|
||||
filePath = path.resolve(__dirname, '..', fileName);
|
||||
expect(await existsSync(filePath)).to.equal(true);
|
||||
await unlinkSync(fileName);
|
||||
|
||||
|
||||
37
test/easy-ast.spec.ts
Normal file
37
test/easy-ast.spec.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {expandPathToFilesSync, toUnixPath} from '../src/util/io';
|
||||
import {EasyAstSpecType} from './easy-ast/easy-ast-spec-type';
|
||||
import {lightweightProjectFromPath} from '../src/easy-ast/easy-ast';
|
||||
import {expect} from 'chai';
|
||||
import {omitBy} from 'lodash';
|
||||
|
||||
describe('Easy AST', async () => {
|
||||
for (const file of expandPathToFilesSync('./test/easy-ast', file => file.endsWith('ast-test.ts'))) {
|
||||
try {
|
||||
const test = (await import(file))['testConfig'] as EasyAstSpecType;
|
||||
|
||||
it(test.testName, () => {
|
||||
const project = omitBy(lightweightProjectFromPath(file, true)[toUnixPath(file)], (_value, key) =>
|
||||
key.startsWith('$'),
|
||||
);
|
||||
|
||||
expect(project).to.be.deep.equal(test.expected);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
68
test/easy-ast/alias-like.ast-test.ts
Normal file
68
test/easy-ast/alias-like.ast-test.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind';
|
||||
|
||||
type TestTypeAlias = number | string;
|
||||
|
||||
enum TestEnum {
|
||||
Foo,
|
||||
Bar,
|
||||
}
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
testName: `should resolve alias-likes`,
|
||||
expected: {
|
||||
TestTypeAlias: {
|
||||
name: 'TestTypeAlias',
|
||||
kind: LightweightDefinitionKind.ALIAS_LIKE,
|
||||
modifiers: ['type'],
|
||||
type: {
|
||||
flags: 1_048_576,
|
||||
specificationTypes: [
|
||||
{
|
||||
value: 'string',
|
||||
flags: 4,
|
||||
},
|
||||
{
|
||||
value: 'number',
|
||||
flags: 8,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
TestEnum: {
|
||||
name: 'TestEnum',
|
||||
kind: LightweightDefinitionKind.ALIAS_LIKE,
|
||||
modifiers: ['enum'],
|
||||
type: {
|
||||
flags: 1_048_576,
|
||||
specificationTypes: [
|
||||
{
|
||||
referenceName: 'Foo',
|
||||
value: 0,
|
||||
flags: 1280,
|
||||
},
|
||||
{
|
||||
referenceName: 'Bar',
|
||||
value: 1,
|
||||
flags: 1280,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
75
test/easy-ast/array-like.ast-test.ts
Normal file
75
test/easy-ast/array-like.ast-test.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/no-empty-interface */
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind';
|
||||
|
||||
interface Random {}
|
||||
|
||||
type TestArrayGeneric = Array<string>;
|
||||
type TestArrayLiteral = number[];
|
||||
type TestArrayReferenceGeneric = Array<Random>;
|
||||
type TestArrayReferenceLiteral = Random[];
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
testName: `should resolve array-likes`,
|
||||
expected: {
|
||||
TestArrayGeneric: {
|
||||
name: 'TestArrayGeneric',
|
||||
kind: LightweightDefinitionKind.ALIAS_LIKE,
|
||||
modifiers: ['type'],
|
||||
type: {
|
||||
value: 'string',
|
||||
flags: 4,
|
||||
isArray: true,
|
||||
},
|
||||
},
|
||||
TestArrayLiteral: {
|
||||
name: 'TestArrayLiteral',
|
||||
kind: LightweightDefinitionKind.ALIAS_LIKE,
|
||||
modifiers: ['type'],
|
||||
type: {
|
||||
value: 'number',
|
||||
flags: 8,
|
||||
isArray: true,
|
||||
},
|
||||
},
|
||||
TestArrayReferenceGeneric: {
|
||||
name: 'TestArrayReferenceGeneric',
|
||||
kind: LightweightDefinitionKind.ALIAS_LIKE,
|
||||
modifiers: ['type'],
|
||||
type: {
|
||||
referenceName: 'Random',
|
||||
flags: 524_288,
|
||||
isArray: true,
|
||||
},
|
||||
},
|
||||
TestArrayReferenceLiteral: {
|
||||
name: 'TestArrayReferenceLiteral',
|
||||
kind: LightweightDefinitionKind.ALIAS_LIKE,
|
||||
modifiers: ['type'],
|
||||
type: {
|
||||
referenceName: 'Random',
|
||||
flags: 524_288,
|
||||
isArray: true,
|
||||
},
|
||||
},
|
||||
Random: {
|
||||
name: 'Random',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['interface'],
|
||||
},
|
||||
},
|
||||
};
|
||||
59
test/easy-ast/class-like.ast-test.ts
Normal file
59
test/easy-ast/class-like.ast-test.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/no-inferrable-types */
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind';
|
||||
|
||||
interface TestInterface {
|
||||
foo: number;
|
||||
}
|
||||
|
||||
class TestClass {
|
||||
bar: string = 'test';
|
||||
}
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
testName: `should resolve class-likes`,
|
||||
expected: {
|
||||
TestInterface: {
|
||||
name: 'TestInterface',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['interface'],
|
||||
properties: {
|
||||
foo: {
|
||||
name: 'foo',
|
||||
type: {
|
||||
value: 'number',
|
||||
flags: 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
TestClass: {
|
||||
name: 'TestClass',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['class'],
|
||||
properties: {
|
||||
bar: {
|
||||
name: 'bar',
|
||||
type: {
|
||||
value: 'string',
|
||||
flags: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
161
test/easy-ast/comment.ast-test.ts
Normal file
161
test/easy-ast/comment.ast-test.ts
Normal file
@@ -0,0 +1,161 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars,jsdoc/check-tag-names */
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind';
|
||||
|
||||
/**
|
||||
* Class comment
|
||||
*
|
||||
* Class description
|
||||
*
|
||||
* More description
|
||||
*
|
||||
* @classTag classParameter1 classParameter2
|
||||
*/
|
||||
interface TestInterface {
|
||||
/**
|
||||
* Property comment
|
||||
*
|
||||
* Property description
|
||||
*
|
||||
* More description
|
||||
*
|
||||
* @propertyTag propertyParameter1 propertyParameter2
|
||||
*/
|
||||
foo: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class comment
|
||||
*
|
||||
* Class description
|
||||
*
|
||||
* More description
|
||||
*
|
||||
* @classTag classParameter1 classParameter2
|
||||
*/
|
||||
class TestClass {
|
||||
/**
|
||||
* Property comment
|
||||
*
|
||||
* Property description
|
||||
*
|
||||
* More description
|
||||
*
|
||||
* @propertyTag propertyParameter1 propertyParameter2
|
||||
*/
|
||||
foo = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum comment
|
||||
*
|
||||
* Enum description
|
||||
*
|
||||
* More description
|
||||
*
|
||||
* @enumTag enumParameter1
|
||||
*/
|
||||
enum TestAlias {}
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
testName: `should resolve comments`,
|
||||
expected: {
|
||||
TestInterface: {
|
||||
comment: {
|
||||
shortSummary: 'Class comment',
|
||||
description: 'Class description\n\nMore description',
|
||||
tags: [
|
||||
{
|
||||
name: 'classTag',
|
||||
parameters: ['classParameter1', 'classParameter2'],
|
||||
},
|
||||
],
|
||||
},
|
||||
name: 'TestInterface',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['interface'],
|
||||
properties: {
|
||||
foo: {
|
||||
comment: {
|
||||
shortSummary: 'Property comment',
|
||||
description: 'Property description\n\nMore description',
|
||||
tags: [
|
||||
{
|
||||
name: 'propertyTag',
|
||||
parameters: ['propertyParameter1', 'propertyParameter2'],
|
||||
},
|
||||
],
|
||||
},
|
||||
name: 'foo',
|
||||
type: {
|
||||
value: 'string',
|
||||
flags: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
TestClass: {
|
||||
comment: {
|
||||
shortSummary: 'Class comment',
|
||||
description: 'Class description\n\nMore description',
|
||||
tags: [
|
||||
{
|
||||
name: 'classTag',
|
||||
parameters: ['classParameter1', 'classParameter2'],
|
||||
},
|
||||
],
|
||||
},
|
||||
name: 'TestClass',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['class'],
|
||||
properties: {
|
||||
foo: {
|
||||
comment: {
|
||||
shortSummary: 'Property comment',
|
||||
description: 'Property description\n\nMore description',
|
||||
tags: [
|
||||
{
|
||||
name: 'propertyTag',
|
||||
parameters: ['propertyParameter1', 'propertyParameter2'],
|
||||
},
|
||||
],
|
||||
},
|
||||
name: 'foo',
|
||||
type: {
|
||||
value: 'number',
|
||||
flags: 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
TestAlias: {
|
||||
comment: {
|
||||
shortSummary: 'Enum comment',
|
||||
description: 'Enum description\n\nMore description',
|
||||
tags: [
|
||||
{
|
||||
name: 'enumTag',
|
||||
parameters: ['enumParameter1'],
|
||||
},
|
||||
],
|
||||
},
|
||||
name: 'TestAlias',
|
||||
kind: LightweightDefinitionKind.ALIAS_LIKE,
|
||||
modifiers: ['enum'],
|
||||
},
|
||||
},
|
||||
};
|
||||
66
test/easy-ast/default-generics.ast-test.ts
Normal file
66
test/easy-ast/default-generics.ast-test.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind';
|
||||
|
||||
interface Test1<T = number> {
|
||||
foo: T;
|
||||
}
|
||||
|
||||
interface Test2 {
|
||||
bar: Test1;
|
||||
}
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
testName: `should resolve default generics`,
|
||||
expected: {
|
||||
Test1: {
|
||||
name: 'Test1',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['interface'],
|
||||
typeParameters: ['T'],
|
||||
properties: {
|
||||
foo: {
|
||||
name: 'foo',
|
||||
type: {
|
||||
referenceName: 'T',
|
||||
flags: 262_144,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Test2: {
|
||||
name: 'Test2',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['interface'],
|
||||
properties: {
|
||||
bar: {
|
||||
name: 'bar',
|
||||
type: {
|
||||
referenceName: 'Test1',
|
||||
flags: 524_288,
|
||||
genericsTypes: [
|
||||
{
|
||||
value: 'number',
|
||||
flags: 8,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2019 StApps
|
||||
* Copyright (C) 2021 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.
|
||||
@@ -12,6 +12,9 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
export function testFunction(): boolean {
|
||||
return true;
|
||||
import {LightweightFile} from '../../src/easy-ast/types/lightweight-project';
|
||||
|
||||
interface EasyAstSpecType {
|
||||
testName: string;
|
||||
expected: LightweightFile;
|
||||
}
|
||||
73
test/easy-ast/enum-specified-value.ast-test.ts
Normal file
73
test/easy-ast/enum-specified-value.ast-test.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind';
|
||||
|
||||
enum TestAuto {
|
||||
Foo,
|
||||
Bar,
|
||||
}
|
||||
|
||||
enum TestSpecified {
|
||||
YES = 'yes',
|
||||
NO = 'no',
|
||||
}
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
testName: `should resolve auto and specified enums`,
|
||||
expected: {
|
||||
TestAuto: {
|
||||
name: 'TestAuto',
|
||||
kind: LightweightDefinitionKind.ALIAS_LIKE,
|
||||
modifiers: ['enum'],
|
||||
type: {
|
||||
flags: 1_048_576,
|
||||
specificationTypes: [
|
||||
{
|
||||
referenceName: 'Foo',
|
||||
value: 0,
|
||||
flags: 1280,
|
||||
},
|
||||
{
|
||||
referenceName: 'Bar',
|
||||
value: 1,
|
||||
flags: 1280,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
TestSpecified: {
|
||||
name: 'TestSpecified',
|
||||
kind: LightweightDefinitionKind.ALIAS_LIKE,
|
||||
modifiers: ['enum'],
|
||||
type: {
|
||||
flags: 1_048_576,
|
||||
specificationTypes: [
|
||||
{
|
||||
referenceName: 'YES',
|
||||
value: 'yes',
|
||||
flags: 1152,
|
||||
},
|
||||
{
|
||||
referenceName: 'NO',
|
||||
value: 'no',
|
||||
flags: 1152,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
80
test/easy-ast/generics.ast-test.ts
Normal file
80
test/easy-ast/generics.ast-test.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface,@typescript-eslint/no-unused-vars */
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind';
|
||||
|
||||
interface $Random {}
|
||||
|
||||
interface Generics {
|
||||
baz: Foo<number, $Random>;
|
||||
}
|
||||
|
||||
interface Foo<T, S> {
|
||||
foo: T;
|
||||
bar: S;
|
||||
}
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
testName: `should resolve generics`,
|
||||
expected: {
|
||||
Generics: {
|
||||
name: 'Generics',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['interface'],
|
||||
properties: {
|
||||
baz: {
|
||||
name: 'baz',
|
||||
type: {
|
||||
referenceName: 'Foo',
|
||||
flags: 524_288,
|
||||
genericsTypes: [
|
||||
{
|
||||
value: 'number',
|
||||
flags: 8,
|
||||
},
|
||||
{
|
||||
referenceName: '$Random',
|
||||
flags: 524_288,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Foo: {
|
||||
name: 'Foo',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['interface'],
|
||||
typeParameters: ['T', 'S'],
|
||||
properties: {
|
||||
foo: {
|
||||
name: 'foo',
|
||||
type: {
|
||||
referenceName: 'T',
|
||||
flags: 262_144,
|
||||
},
|
||||
},
|
||||
bar: {
|
||||
name: 'bar',
|
||||
type: {
|
||||
referenceName: 'S',
|
||||
flags: 262_144,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
69
test/easy-ast/index-signature.ast-test.ts
Normal file
69
test/easy-ast/index-signature.ast-test.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface,@typescript-eslint/no-unused-vars */
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind';
|
||||
|
||||
interface $Random {}
|
||||
|
||||
interface IndexSignatureObject {
|
||||
[key: string]: $Random;
|
||||
}
|
||||
|
||||
interface IndexSignaturePrimitive {
|
||||
[key: string]: number;
|
||||
}
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
testName: `should resolve index signatures`,
|
||||
expected: {
|
||||
IndexSignatureObject: {
|
||||
name: 'IndexSignatureObject',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['interface'],
|
||||
indexSignatures: {
|
||||
key: {
|
||||
name: 'key',
|
||||
indexSignatureType: {
|
||||
value: 'string',
|
||||
flags: 4,
|
||||
},
|
||||
type: {
|
||||
referenceName: '$Random',
|
||||
flags: 524_288,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
IndexSignaturePrimitive: {
|
||||
name: 'IndexSignaturePrimitive',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['interface'],
|
||||
indexSignatures: {
|
||||
key: {
|
||||
name: 'key',
|
||||
indexSignatureType: {
|
||||
value: 'string',
|
||||
flags: 4,
|
||||
},
|
||||
type: {
|
||||
value: 'number',
|
||||
flags: 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
82
test/easy-ast/ineritance.ast-test.ts
Normal file
82
test/easy-ast/ineritance.ast-test.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/no-inferrable-types */
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind';
|
||||
|
||||
interface $BaseInterface<T> {
|
||||
foo: T;
|
||||
}
|
||||
|
||||
interface $BaseInterface2 {
|
||||
bar: string;
|
||||
}
|
||||
|
||||
class $BaseClass {}
|
||||
|
||||
class InheritingClass extends $BaseClass implements $BaseInterface<number>, $BaseInterface2 {
|
||||
bar: string = '';
|
||||
|
||||
foo: number = 1;
|
||||
}
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
testName: `inheritance`,
|
||||
expected: {
|
||||
InheritingClass: {
|
||||
name: 'InheritingClass',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['class'],
|
||||
implementedDefinitions: [
|
||||
{
|
||||
referenceName: '$BaseInterface',
|
||||
genericsTypes: [
|
||||
{
|
||||
value: 'number',
|
||||
flags: 8,
|
||||
},
|
||||
],
|
||||
flags: 524_288,
|
||||
},
|
||||
{
|
||||
referenceName: '$BaseInterface2',
|
||||
flags: 524_288,
|
||||
},
|
||||
],
|
||||
extendedDefinitions: [
|
||||
{
|
||||
referenceName: '$BaseClass',
|
||||
flags: 524_288,
|
||||
},
|
||||
],
|
||||
properties: {
|
||||
foo: {
|
||||
name: 'foo',
|
||||
type: {
|
||||
value: 'number',
|
||||
flags: 8,
|
||||
},
|
||||
},
|
||||
bar: {
|
||||
name: 'bar',
|
||||
type: {
|
||||
value: 'string',
|
||||
flags: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
61
test/easy-ast/nested.ast-test.ts
Normal file
61
test/easy-ast/nested.ast-test.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface,@typescript-eslint/no-unused-vars */
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind';
|
||||
|
||||
interface NestedObject {
|
||||
nested: {
|
||||
deeplyNested: {
|
||||
aNumber: number;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
testName: `should handle nested/type literals`,
|
||||
expected: {
|
||||
NestedObject: {
|
||||
name: 'NestedObject',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['interface'],
|
||||
properties: {
|
||||
nested: {
|
||||
name: 'nested',
|
||||
type: {
|
||||
flags: 524_288,
|
||||
},
|
||||
properties: {
|
||||
deeplyNested: {
|
||||
name: 'deeplyNested',
|
||||
type: {
|
||||
flags: 524_288,
|
||||
},
|
||||
properties: {
|
||||
aNumber: {
|
||||
name: 'aNumber',
|
||||
type: {
|
||||
flags: 8,
|
||||
value: 'number',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
99
test/easy-ast/primitive-types.ast-test.ts
Normal file
99
test/easy-ast/primitive-types.ast-test.ts
Normal file
@@ -0,0 +1,99 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/no-explicit-any */
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind';
|
||||
|
||||
interface Test {
|
||||
number_type: number;
|
||||
string_type: string;
|
||||
boolean_type: boolean;
|
||||
any_type: any;
|
||||
unknown_type: unknown;
|
||||
null_type: null;
|
||||
undefined_type: undefined;
|
||||
}
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
testName: `should interpret primitive types correctly`,
|
||||
expected: {
|
||||
Test: {
|
||||
name: 'Test',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['interface'],
|
||||
properties: {
|
||||
number_type: {
|
||||
name: 'number_type',
|
||||
type: {
|
||||
value: 'number',
|
||||
flags: 8,
|
||||
},
|
||||
},
|
||||
string_type: {
|
||||
name: 'string_type',
|
||||
type: {
|
||||
value: 'string',
|
||||
flags: 4,
|
||||
},
|
||||
},
|
||||
boolean_type: {
|
||||
name: 'boolean_type',
|
||||
type: {
|
||||
value: 'boolean',
|
||||
flags: 1_048_592,
|
||||
specificationTypes: [
|
||||
{
|
||||
value: 'false',
|
||||
flags: 512,
|
||||
},
|
||||
{
|
||||
value: 'true',
|
||||
flags: 512,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
any_type: {
|
||||
name: 'any_type',
|
||||
type: {
|
||||
value: 'any',
|
||||
flags: 1,
|
||||
},
|
||||
},
|
||||
unknown_type: {
|
||||
name: 'unknown_type',
|
||||
type: {
|
||||
value: 'unknown',
|
||||
flags: 2,
|
||||
},
|
||||
},
|
||||
null_type: {
|
||||
name: 'null_type',
|
||||
type: {
|
||||
value: 'null',
|
||||
flags: 65_536,
|
||||
},
|
||||
},
|
||||
undefined_type: {
|
||||
name: 'undefined_type',
|
||||
type: {
|
||||
value: 'undefined',
|
||||
flags: 32_768,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
61
test/easy-ast/stack-overflow.ast-test.ts
Normal file
61
test/easy-ast/stack-overflow.ast-test.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/no-explicit-any */
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {EasyAstSpecType} from './easy-ast-spec-type';
|
||||
import {LightweightDefinitionKind} from '../../src/easy-ast/types/lightweight-definition-kind';
|
||||
|
||||
interface Foo<T extends Bar<string>> {
|
||||
bar: T;
|
||||
}
|
||||
|
||||
interface Bar<T> {
|
||||
foo: T;
|
||||
}
|
||||
|
||||
export const testConfig: EasyAstSpecType = {
|
||||
testName: `should ignore type constraints`,
|
||||
expected: {
|
||||
Foo: {
|
||||
name: 'Foo',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['interface'],
|
||||
typeParameters: ['T'],
|
||||
properties: {
|
||||
bar: {
|
||||
name: 'bar',
|
||||
type: {
|
||||
referenceName: 'T',
|
||||
flags: 262_144,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Bar: {
|
||||
name: 'Bar',
|
||||
kind: LightweightDefinitionKind.CLASS_LIKE,
|
||||
modifiers: ['interface'],
|
||||
typeParameters: ['T'],
|
||||
properties: {
|
||||
foo: {
|
||||
name: 'foo',
|
||||
type: {
|
||||
referenceName: 'T',
|
||||
flags: 262_144,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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[];
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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'],
|
||||
},
|
||||
};
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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'],
|
||||
},
|
||||
};
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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'],
|
||||
},
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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'],
|
||||
},
|
||||
};
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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'],
|
||||
},
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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'],
|
||||
},
|
||||
};
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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'],
|
||||
},
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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',
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "../../../node_modules/@openstapps/configuration/tsconfig.json"
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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: {}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap';
|
||||
|
||||
/**
|
||||
* @date
|
||||
*/
|
||||
export type SCISO8601Date = string
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface DateAndRange {
|
||||
/**
|
||||
* @date
|
||||
*/
|
||||
directDate: string;
|
||||
|
||||
dateAlias: SCISO8601Date;
|
||||
|
||||
type: ThingType.Date
|
||||
}
|
||||
|
||||
export const dateAndRangeTest: MapAggTestOptions = {
|
||||
name: ThingType.Date,
|
||||
map: {
|
||||
maps: {
|
||||
directDate: {
|
||||
type: ElasticsearchDataType.date,
|
||||
},
|
||||
dateAlias: {
|
||||
type: ElasticsearchDataType.date,
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<T = number> {
|
||||
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!`
|
||||
]
|
||||
};
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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"`
|
||||
]
|
||||
};
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap';
|
||||
|
||||
export type FilterableEnumType = 'a' | 'b' | 'c';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface FilterableTag {
|
||||
/**
|
||||
* @text
|
||||
* @filterable
|
||||
*/
|
||||
foo: string;
|
||||
|
||||
/**
|
||||
* @keyword
|
||||
* @filterable
|
||||
*/
|
||||
bar: string;
|
||||
|
||||
/**
|
||||
* @filterable
|
||||
*/
|
||||
baz: 'some literal'
|
||||
|
||||
/**
|
||||
* @filterable
|
||||
*/
|
||||
buz: FilterableEnumType
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
},
|
||||
buz: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
fields: {
|
||||
raw: {
|
||||
type: ElasticsearchDataType.keyword
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface Generics {
|
||||
foo: InterfaceWithDefaultGeneric<number>;
|
||||
baz: InterfaceWithStringGeneric<string>
|
||||
|
||||
type: ThingType.Generics;
|
||||
}
|
||||
|
||||
interface InterfaceWithDefaultGeneric<T = number> {
|
||||
bar: T;
|
||||
}
|
||||
|
||||
interface InterfaceWithStringGeneric<T> {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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`
|
||||
]
|
||||
};
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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`,
|
||||
]
|
||||
};
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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.*'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ThingType} from './types';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface InheritTags {
|
||||
/**
|
||||
* @inheritTags inherit tags::bar.baz
|
||||
*/
|
||||
foo: number,
|
||||
|
||||
bar: {
|
||||
/**
|
||||
* @float
|
||||
*/
|
||||
baz: number
|
||||
}
|
||||
|
||||
type: ThingType.InheritTags;
|
||||
}
|
||||
|
||||
export const inheritTagsTest: MapAggTestOptions = {
|
||||
name: ThingType.InheritTags,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.float
|
||||
},
|
||||
bar: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
baz: {
|
||||
type: ElasticsearchDataType.float
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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`
|
||||
]
|
||||
};
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @date
|
||||
*/
|
||||
esEpochMsDate: number
|
||||
|
||||
/**
|
||||
* @date
|
||||
*/
|
||||
esStringDate: 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
|
||||
},
|
||||
esEpochMsDate: {
|
||||
type: ElasticsearchDataType.date
|
||||
},
|
||||
esStringDate: {
|
||||
type: ElasticsearchDataType.date
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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`
|
||||
]
|
||||
};
|
||||
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface ObjectUnion {
|
||||
foo: Boo | Buu;
|
||||
|
||||
type: ThingType.ObjectUnion
|
||||
}
|
||||
|
||||
// we can't name them Bar or Baz, look here for more info:
|
||||
// https://gitlab.com/openstapps/core-tools/-/issues/48
|
||||
// or here
|
||||
// https://github.com/TypeStrong/typedoc/issues/1373
|
||||
interface Boo {
|
||||
a: boolean;
|
||||
intersection: string;
|
||||
}
|
||||
|
||||
interface Buu {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface TagsIgnoreCase {
|
||||
/**
|
||||
* @inheritTags inherit tags::bar.baz
|
||||
*/
|
||||
camelCase: number,
|
||||
|
||||
/**
|
||||
* @inherittags inherit tags::bar.baz
|
||||
*/
|
||||
lowerCase: number,
|
||||
|
||||
bar: {
|
||||
/**
|
||||
* @float
|
||||
*/
|
||||
baz: number
|
||||
}
|
||||
|
||||
type: ThingType.TagsIgnoreCase;
|
||||
}
|
||||
|
||||
export const tagsIgnoreCaseTest: MapAggTestOptions = {
|
||||
name: ThingType.TagsIgnoreCase,
|
||||
map: {
|
||||
maps: {
|
||||
camelCase: {
|
||||
type: ElasticsearchDataType.float
|
||||
},
|
||||
lowerCase: {
|
||||
type: ElasticsearchDataType.float
|
||||
},
|
||||
bar: {
|
||||
dynamic: 'strict',
|
||||
properties: {
|
||||
baz: {
|
||||
type: ElasticsearchDataType.float
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap';
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface TypeAlias {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
textProperty: ATextAlias,
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
keywordProperty: AKeywordAlias,
|
||||
|
||||
/**
|
||||
* @keyword
|
||||
*/
|
||||
overriddenTextAsKeyword: ATextAlias
|
||||
|
||||
type: ThingType.TypeAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
* @text
|
||||
*/
|
||||
type ATextAlias = string;
|
||||
|
||||
/**
|
||||
* @keyword
|
||||
*/
|
||||
type AKeywordAlias = string;
|
||||
|
||||
export const typeAliasTest: MapAggTestOptions = {
|
||||
name: ThingType.TypeAlias,
|
||||
map: {
|
||||
maps: {
|
||||
textProperty: {
|
||||
type: ElasticsearchDataType.text,
|
||||
},
|
||||
keywordProperty: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
},
|
||||
overriddenTextAsKeyword: {
|
||||
type: ElasticsearchDataType.keyword,
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {ThingType} from './types';
|
||||
import {MapAggTestOptions} from '../../MapAggTestOptions';
|
||||
import {ElasticsearchDataType} from '../../../../src/mappings/definitions/typemap';
|
||||
|
||||
export interface SCISO8601DateRange {
|
||||
bar: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* @indexable
|
||||
*/
|
||||
export interface TypeOverrides {
|
||||
foo: SCISO8601DateRange;
|
||||
|
||||
type: ThingType.TypeOverrides
|
||||
}
|
||||
|
||||
export const typeOverridesTest: MapAggTestOptions = {
|
||||
name: ThingType.TypeOverrides,
|
||||
map: {
|
||||
maps: {
|
||||
foo: {
|
||||
type: ElasticsearchDataType.date_range,
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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',
|
||||
Date = 'date',
|
||||
InheritTags = 'inherit tags',
|
||||
TagsIgnoreCase = 'tags ignore case',
|
||||
TypeAlias = 'type alias',
|
||||
TypeOverrides = 'type overrides',
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "../../../node_modules/@openstapps/configuration/tsconfig.json"
|
||||
}
|
||||
@@ -1,183 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2021 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {slow, suite, test, timeout} from '@testdeck/mocha';
|
||||
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';
|
||||
|
||||
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 '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 (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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -1,492 +0,0 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {LightweightClassDefinition} from '../../src/uml/model/lightweight-class-definition';
|
||||
import {LightweightDefinition} from '../../src/uml/model/lightweight-definition';
|
||||
import {LightweightEnumDefinition} from '../../src/uml/model/lightweight-enum-definition';
|
||||
|
||||
export const generatedModel: Array<LightweightDefinition | LightweightClassDefinition | LightweightEnumDefinition> = [
|
||||
{
|
||||
name: 'TestClass',
|
||||
type: 'class',
|
||||
properties: [
|
||||
{
|
||||
name: 'test2',
|
||||
optional: false,
|
||||
inherited: false,
|
||||
type: {
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: true,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'T',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'test4',
|
||||
optional: false,
|
||||
inherited: false,
|
||||
type: {
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: true,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'TestFirstUnion',
|
||||
},
|
||||
},
|
||||
],
|
||||
extendedDefinitions: [],
|
||||
implementedDefinitions: [],
|
||||
typeParameters: ['T'],
|
||||
},
|
||||
{
|
||||
name: 'TestSecondClass',
|
||||
type: 'class',
|
||||
properties: [
|
||||
{
|
||||
name: 'test2',
|
||||
optional: false,
|
||||
inherited: true,
|
||||
type: {
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: true,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'test4',
|
||||
optional: false,
|
||||
inherited: true,
|
||||
type: {
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: true,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'TestFirstUnion',
|
||||
},
|
||||
},
|
||||
],
|
||||
extendedDefinitions: ['TestClass'],
|
||||
implementedDefinitions: [],
|
||||
typeParameters: [],
|
||||
},
|
||||
{
|
||||
name: 'TestFirstEnum',
|
||||
values: ['TEST1', 'TEST2', 'TEST3'],
|
||||
},
|
||||
{
|
||||
name: 'TestSecondEnum',
|
||||
values: ['TEST1 = "one"', 'TEST2 = "two"', 'TEST3 = "three"'],
|
||||
},
|
||||
{
|
||||
name: 'TestInterface',
|
||||
type: 'interface',
|
||||
properties: [
|
||||
{
|
||||
name: 'articleBody',
|
||||
optional: false,
|
||||
inherited: false,
|
||||
type: {
|
||||
hasTypeInformation: false,
|
||||
isArray: true,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [
|
||||
{
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: true,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'string',
|
||||
},
|
||||
],
|
||||
genericsTypes: [],
|
||||
name: 'string',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'categorySpecificValues',
|
||||
optional: true,
|
||||
inherited: false,
|
||||
type: {
|
||||
hasTypeInformation: false,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: false,
|
||||
isReflection: true,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'object',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'inputType',
|
||||
optional: false,
|
||||
inherited: false,
|
||||
type: {
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: true,
|
||||
isPrimitive: false,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'multipleChoice',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'maintainer',
|
||||
optional: false,
|
||||
inherited: false,
|
||||
type: {
|
||||
hasTypeInformation: false,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: true,
|
||||
specificationTypes: [
|
||||
{
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: true,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'TestThirdUnion',
|
||||
},
|
||||
{
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: true,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'TestFirstEnum',
|
||||
},
|
||||
],
|
||||
genericsTypes: [],
|
||||
name: '',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'remainingAttendeeCapacity',
|
||||
optional: true,
|
||||
inherited: false,
|
||||
type: {
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: true,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'number',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'test1',
|
||||
optional: false,
|
||||
inherited: false,
|
||||
type: {
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: true,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [
|
||||
{
|
||||
hasTypeInformation: false,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: true,
|
||||
specificationTypes: [
|
||||
{
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: true,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'TestThirdUnion',
|
||||
},
|
||||
{
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: true,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'TestFirstEnum',
|
||||
},
|
||||
],
|
||||
genericsTypes: [],
|
||||
name: '',
|
||||
},
|
||||
],
|
||||
name: 'Array',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'test2',
|
||||
optional: false,
|
||||
inherited: false,
|
||||
type: {
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: true,
|
||||
isReflection: false,
|
||||
isTyped: true,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [
|
||||
{
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: true,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'string',
|
||||
},
|
||||
],
|
||||
name: 'TestClass',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'test3',
|
||||
optional: false,
|
||||
inherited: false,
|
||||
type: {
|
||||
hasTypeInformation: false,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: true,
|
||||
specificationTypes: [
|
||||
{
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: true,
|
||||
isPrimitive: false,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'test1',
|
||||
},
|
||||
{
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: true,
|
||||
isPrimitive: false,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'test2',
|
||||
},
|
||||
],
|
||||
genericsTypes: [],
|
||||
name: '',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'test4',
|
||||
optional: false,
|
||||
inherited: false,
|
||||
type: {
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: true,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'TestSecondClass',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'universityRole',
|
||||
optional: false,
|
||||
inherited: false,
|
||||
type: {
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: true,
|
||||
isReference: false,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [
|
||||
{
|
||||
hasTypeInformation: true,
|
||||
isArray: false,
|
||||
isLiteral: false,
|
||||
isPrimitive: false,
|
||||
isReference: true,
|
||||
isReflection: false,
|
||||
isTyped: false,
|
||||
isTypeParameter: false,
|
||||
isUnion: false,
|
||||
specificationTypes: [],
|
||||
genericsTypes: [],
|
||||
name: 'TestFirstEnum',
|
||||
},
|
||||
],
|
||||
genericsTypes: [],
|
||||
name: 'keyof TestFirstEnum',
|
||||
},
|
||||
},
|
||||
],
|
||||
extendedDefinitions: [],
|
||||
implementedDefinitions: [],
|
||||
typeParameters: [],
|
||||
},
|
||||
{
|
||||
name: 'TestSecondInterface',
|
||||
type: 'interface',
|
||||
properties: [],
|
||||
extendedDefinitions: [],
|
||||
implementedDefinitions: [],
|
||||
typeParameters: [],
|
||||
},
|
||||
{
|
||||
name: 'TestFirstUnion',
|
||||
values: ['test1', 'test2'],
|
||||
},
|
||||
{
|
||||
name: 'TestFourthUnion',
|
||||
values: [],
|
||||
},
|
||||
{
|
||||
name: 'TestSecondUnion',
|
||||
values: ['test3'],
|
||||
},
|
||||
{
|
||||
name: 'TestThirdUnion',
|
||||
values: ['TestFirstUnion', 'TestSecondUnion'],
|
||||
},
|
||||
];
|
||||
@@ -16,6 +16,7 @@ import {TestFirstUnion} from './test-union';
|
||||
|
||||
export class TestClass<T> {
|
||||
test2: T;
|
||||
|
||||
test4: TestFirstUnion;
|
||||
|
||||
constructor(type: T) {
|
||||
@@ -18,7 +18,7 @@ import {TestThirdUnion} from './test-union';
|
||||
|
||||
export interface TestInterface {
|
||||
articleBody: string[];
|
||||
categorySpecificValues?: { [s: string]: string };
|
||||
categorySpecificValues?: {[s: string]: string};
|
||||
inputType: 'multipleChoice';
|
||||
maintainer: TestThirdUnion | TestFirstEnum;
|
||||
remainingAttendeeCapacity?: number;
|
||||
@@ -19,6 +19,4 @@ export type TestSecondUnion = 'test3';
|
||||
|
||||
export type TestThirdUnion = TestFirstUnion | TestSecondUnion;
|
||||
|
||||
export type TestFourthUnion<T extends TestFirstUnion> = T extends TestFirstUnion
|
||||
? TestFirstUnion
|
||||
: never;
|
||||
export type TestFourthUnion<T extends TestFirstUnion> = T extends TestFirstUnion ? TestFirstUnion : never;
|
||||
4
test/model/tsconfig.json
Normal file
4
test/model/tsconfig.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../node_modules/@openstapps/configuration/tsconfig.json",
|
||||
"exclude": []
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018-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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {expect} from 'chai';
|
||||
import {slow, suite, test, timeout} from '@testdeck/mocha';
|
||||
import {getProjectReflection} from '../src/common';
|
||||
import {readDefinitions} from '../src/uml/read-definitions';
|
||||
import {generatedModel} from './model/generated-model';
|
||||
|
||||
@suite(timeout(10000), slow(5000))
|
||||
export class ReadDefinitionsSpec {
|
||||
@test
|
||||
async testReadDefinitions() {
|
||||
const projectReflection = getProjectReflection('./test/model', true);
|
||||
const definitions = readDefinitions(projectReflection);
|
||||
expect(definitions).to.be.deep.equal(generatedModel);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable unicorn/prefer-module */
|
||||
/*
|
||||
* Copyright (C) 2018-2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
@@ -15,21 +16,21 @@
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {expect} from 'chai';
|
||||
import {slow, suite, test, timeout} from '@testdeck/mocha';
|
||||
import {join} from 'path';
|
||||
import {Converter, getValidatableTypesFromReflection} from '../src/schema';
|
||||
import {Converter} from '../src/schema';
|
||||
import path from 'path';
|
||||
|
||||
process.on('unhandledRejection', (error: unknown) => {
|
||||
if (error instanceof Error) {
|
||||
Logger.error('UNHANDLED REJECTION', error.stack);
|
||||
void Logger.error('UNHANDLED REJECTION', error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
@suite(timeout(40000), slow(10000))
|
||||
@suite(timeout(40_000), slow(10_000))
|
||||
export class SchemaSpec {
|
||||
@test
|
||||
async getSchema() {
|
||||
const converter = new Converter(join(__dirname, '..', 'src', 'resources'));
|
||||
const converter = new Converter(path.join(__dirname, '..', 'src', 'resources'));
|
||||
|
||||
const schema = converter.getSchema('Foo', '0.0.1');
|
||||
expect(schema).to.be.deep.equal({
|
||||
@@ -38,21 +39,18 @@ export class SchemaSpec {
|
||||
additionalProperties: false,
|
||||
definitions: {
|
||||
FooType: {
|
||||
description: 'This is a simple type declaration for\nusage in the Foo interace.',
|
||||
enum: [
|
||||
'Foo',
|
||||
],
|
||||
type: 'string',
|
||||
},
|
||||
description: 'This is a simple type declaration for usage in the Foo interface.',
|
||||
const: 'Foo',
|
||||
type: 'string',
|
||||
},
|
||||
SCFoo: {
|
||||
additionalProperties: false,
|
||||
description: 'This is a simple interface declaration for\ntesting the schema generation and validation.',
|
||||
description:
|
||||
'This is a simple interface declaration for testing the schema generation and validation.',
|
||||
properties: {
|
||||
lorem: {
|
||||
description: 'Dummy parameter',
|
||||
enum: [
|
||||
'ipsum',
|
||||
],
|
||||
enum: ['lorem', 'ipsum'],
|
||||
type: 'string',
|
||||
},
|
||||
type: {
|
||||
@@ -60,20 +58,15 @@ export class SchemaSpec {
|
||||
description: 'String literal type property',
|
||||
},
|
||||
},
|
||||
required: [
|
||||
'lorem',
|
||||
'type',
|
||||
],
|
||||
required: ['lorem', 'type'],
|
||||
type: 'object',
|
||||
},
|
||||
},
|
||||
description: 'This is a simple interface declaration for\ntesting the schema generation and validation.',
|
||||
description: 'This is a simple interface declaration for testing the schema generation and validation.',
|
||||
properties: {
|
||||
lorem: {
|
||||
description: 'Dummy parameter',
|
||||
enum: [
|
||||
'ipsum',
|
||||
],
|
||||
enum: ['lorem', 'ipsum'],
|
||||
type: 'string',
|
||||
},
|
||||
type: {
|
||||
@@ -81,47 +74,8 @@ export class SchemaSpec {
|
||||
description: 'String literal type property',
|
||||
},
|
||||
},
|
||||
required: [
|
||||
'lorem',
|
||||
'type',
|
||||
],
|
||||
required: ['lorem', 'type'],
|
||||
type: 'object',
|
||||
});
|
||||
}
|
||||
|
||||
@test
|
||||
async getValidatableTypesFromReflection() {
|
||||
const reflection: any = {
|
||||
children: [
|
||||
{
|
||||
children: [
|
||||
{
|
||||
comment: {
|
||||
tags: [
|
||||
{
|
||||
tagName: 'validatable',
|
||||
},
|
||||
],
|
||||
},
|
||||
name: 'foo',
|
||||
},
|
||||
{
|
||||
name: 'bar',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
children: [
|
||||
{
|
||||
name: 'foobar',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const validatableTypes = getValidatableTypesFromReflection(reflection as any);
|
||||
|
||||
expect(validatableTypes).to.be.deep.equal(['foo']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable unicorn/prefer-module */
|
||||
/*
|
||||
* Copyright (C) 2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
@@ -17,37 +18,38 @@ import {expect} from 'chai';
|
||||
import {existsSync, mkdirSync, writeFileSync} from 'fs';
|
||||
import {JSONSchema7 as Schema} from 'json-schema';
|
||||
import {slow, suite, test, timeout} from '@testdeck/mocha';
|
||||
import {join} from 'path';
|
||||
import rimraf from 'rimraf';
|
||||
import {Foo} from '../src/resources/foo';
|
||||
import {Converter} from '../src/schema';
|
||||
import {Validator} from '../src/validate';
|
||||
import path from 'path';
|
||||
|
||||
process.on('unhandledRejection', (err: unknown) => {
|
||||
if (err instanceof Error) {
|
||||
Logger.error('UNHANDLED REJECTION', err.stack);
|
||||
process.on('unhandledRejection', (error: unknown) => {
|
||||
if (error instanceof Error) {
|
||||
void Logger.error('UNHANDLED REJECTION', error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
const tmpdir = join(__dirname, 'tmp');
|
||||
const tmpdir = path.join(__dirname, 'tmp');
|
||||
const fooInstance: Foo = {
|
||||
lorem: 'ipsum',
|
||||
type: 'Foo',
|
||||
};
|
||||
|
||||
@suite(timeout(40000), slow(5000))
|
||||
export class SchemaSpec {
|
||||
@suite(timeout(40_000), slow(5000))
|
||||
export class ValidateSpec {
|
||||
static converter: Converter;
|
||||
|
||||
static schema: Schema;
|
||||
|
||||
static before() {
|
||||
this.converter = new Converter(join(__dirname, '..', 'src', 'resources'));
|
||||
this.converter = new Converter(path.join(__dirname, '..', 'src', 'resources'));
|
||||
this.schema = this.converter.getSchema('Foo', '0.0.1');
|
||||
if (!existsSync(tmpdir)) {
|
||||
mkdirSync(tmpdir);
|
||||
}
|
||||
writeFileSync(join(tmpdir, 'SCFoo.json'), JSON.stringify(this.schema, null, 2));
|
||||
writeFileSync(path.join(tmpdir, 'SCFoo.json'), JSON.stringify(this.schema, undefined, 2));
|
||||
}
|
||||
|
||||
static after() {
|
||||
@@ -58,20 +60,20 @@ export class SchemaSpec {
|
||||
}
|
||||
|
||||
@test
|
||||
async validateBySchemaIdentifingString() {
|
||||
async validateBySchemaIdentifyingString() {
|
||||
const validator = new Validator();
|
||||
await validator.addSchemas(tmpdir);
|
||||
const validationResult = validator.validate(fooInstance, 'SCFoo');
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
expect(validationResult.errors, JSON.stringify(validationResult.errors, null, 2)).to.be.empty;
|
||||
expect(validationResult.errors, JSON.stringify(validationResult.errors, undefined, 2)).to.be.empty;
|
||||
}
|
||||
|
||||
@test
|
||||
async validateBySchemaInstance() {
|
||||
const validator = new Validator();
|
||||
const validationResult = validator.validate(fooInstance, SchemaSpec.schema);
|
||||
const validationResult = validator.validate(fooInstance, ValidateSpec.schema);
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
expect(validationResult.errors, JSON.stringify(validationResult.errors, null, 2)).to.be.empty;
|
||||
expect(validationResult.errors, JSON.stringify(validationResult.errors, undefined, 2)).to.be.empty;
|
||||
}
|
||||
|
||||
@test
|
||||
@@ -80,6 +82,6 @@ export class SchemaSpec {
|
||||
await validator.addSchemas(tmpdir);
|
||||
const validationResult = validator.validate(fooInstance);
|
||||
// tslint:disable-next-line: no-unused-expression
|
||||
expect(validationResult.errors, JSON.stringify(validationResult.errors, null, 2)).to.be.empty;
|
||||
expect(validationResult.errors, JSON.stringify(validationResult.errors, undefined, 2)).to.be.empty;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user