fix: filter tags override inherited type tags

This commit is contained in:
Wieland Schöbl
2021-09-28 12:49:02 +00:00
parent 61b1fde0ec
commit f0401e1889
41 changed files with 218 additions and 257 deletions

View File

@@ -13,59 +13,38 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Logger} from '@openstapps/logger';
import {slow, suite, test, timeout} from '@testdeck/mocha';
import {readdirSync, statSync} from 'fs';
import path from 'path';
import {MapAggTest} from './mapping-model/MapAggTest';
import {aggArrayTest} from './mapping-model/aggregations/src/agg-array';
import {aggNestedTest} from './mapping-model/aggregations/src/agg-nested';
import {aggGlobalTest} from './mapping-model/aggregations/src/agg-global';
import {aggGlobalNestedTest} from './mapping-model/aggregations/src/agg-global-nested';
import {aggInheritedTest} from './mapping-model/aggregations/src/agg-inherited';
import {aggInheritedGlobalTest} from './mapping-model/aggregations/src/agg-inherited-global';
import {aggInheritedOverwrittenTest} from './mapping-model/aggregations/src/agg-inherited-overwritten';
import {MapAggTestOptions} from './mapping-model/MapAggTestOptions';
process.on('unhandledRejection', (error: unknown) => {
if (error instanceof Error) {
void Logger.error('UNHANDLED REJECTION', error.stack);
}
process.exit(1);
});
describe('ES Aggregation Gen', async () => {
const magAppInstance = new MapAggTest('aggregations');
const magAppInstance = new MapAggTest('aggregations');
/**
* Expand a path to a list of all files deeply contained in it
*/
function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
const fullPath = path.resolve(sourcePath);
const directory = statSync(fullPath);
@suite(timeout(20000), slow(10000))
export class AggregationsSpec {
@test
async 'Aggregation tag should propagate on arrays'() {
magAppInstance.testInterfaceAgainstPath(aggArrayTest);
return directory.isDirectory()
? ([] as string[]).concat(...readdirSync(fullPath).map(fragment =>
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
))
: [fullPath].filter(accept);
}
@test
async 'Should work on nested properties'() {
magAppInstance.testInterfaceAgainstPath(aggNestedTest);
}
for (const file of expandPathToFilesSync('./test/mapping-model/aggregations/', file => file.endsWith('agg-test.ts'))) {
try {
const test = (await import(file))['testConfig'] as MapAggTestOptions;
@test
async 'Global option should work'() {
magAppInstance.testInterfaceAgainstPath(aggGlobalTest);
it(test.testName, function () {
magAppInstance.testInterfaceAgainstPath(test);
});
} catch (error) {
await Logger.error('UNHANDLED REJECTION', error.stack);
process.exit(1);
}
}
@test
async 'Global aggregations when nested'() {
magAppInstance.testInterfaceAgainstPath(aggGlobalNestedTest);
}
@test
async 'Inherited aggregations should work'() {
magAppInstance.testInterfaceAgainstPath(aggInheritedTest);
}
@test
async 'Inherited global aggregations should work'() {
magAppInstance.testInterfaceAgainstPath(aggInheritedGlobalTest);
}
@test
async 'Inherited aggregations should work when overwritten'() {
magAppInstance.testInterfaceAgainstPath(aggInheritedOverwrittenTest);
}
}
}).timeout(20_000).slow(10_000);