mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-10 19:52:53 +00:00
fix: filter tags override inherited type tags
This commit is contained in:
@@ -13,171 +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 {inheritTagsTest} from './mapping-model/mappings/src/inherit-tags';
|
||||
import {mapExplicitTypesTest} from './mapping-model/mappings/src/map-explicit-types';
|
||||
import {doubleTypeConflictTest} from './mapping-model/mappings/src/double-type-conflict';
|
||||
import {incompatibleTypeTest} from './mapping-model/mappings/src/incompatible-type';
|
||||
import {sensibleDefaultsTest} from './mapping-model/mappings/src/sensible-defaults';
|
||||
import {invalidTagTest} from './mapping-model/mappings/src/invalid-tag';
|
||||
import {missingPremapTest} from './mapping-model/mappings/src/missing-premap';
|
||||
import {defaultGenericTest} from './mapping-model/mappings/src/default-generics';
|
||||
import {genericTest} from './mapping-model/mappings/src/generics';
|
||||
import {nestedTest} from './mapping-model/mappings/src/nested';
|
||||
import {indexSignatureTest} from './mapping-model/mappings/src/index-signature';
|
||||
import {impossibleUnionTest} from './mapping-model/mappings/src/impossible-union';
|
||||
import {objectUnionTest} from './mapping-model/mappings/src/object-union';
|
||||
import {sortableTagTest} from './mapping-model/mappings/src/sortable-tag';
|
||||
import {enumTest} from './mapping-model/mappings/src/enum';
|
||||
import {inheritedPropertyTest} from './mapping-model/mappings/src/inherited-property';
|
||||
import {pairedTagsTest} from './mapping-model/mappings/src/paired-tags';
|
||||
import {filterableTagTest} from './mapping-model/mappings/src/filterable-tag';
|
||||
import {anyUnknownTest} from './mapping-model/mappings/src/any-unknown';
|
||||
import {tagsIgnoreCaseTest} from './mapping-model/mappings/src/tags-ignore-case';
|
||||
import {typeAliasTest} from './mapping-model/mappings/src/type-alias';
|
||||
import {dateAndRangeTest} from './mapping-model/mappings/src/date';
|
||||
import {typeOverridesTest} from './mapping-model/mappings/src/type-overrides';
|
||||
import {MapAggTestOptions} from './mapping-model/MapAggTestOptions';
|
||||
|
||||
process.on('unhandledRejection', (error: unknown) => {
|
||||
if (error instanceof Error) {
|
||||
void Logger.error('UNHANDLED REJECTION', error.stack);
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
describe('ES Mapping Gen', async () => {
|
||||
const magAppInstance = new MapAggTest('mappings');
|
||||
|
||||
const magAppInstance = new MapAggTest('mappings');
|
||||
/**
|
||||
* Expand a path to a list of all files deeply contained in it
|
||||
*/
|
||||
function expandPathToFilesSync(sourcePath: string, accept: (fileName: string) => boolean): string[] {
|
||||
const fullPath = path.resolve(sourcePath);
|
||||
const directory = statSync(fullPath);
|
||||
|
||||
@suite(timeout(20000), slow(10000))
|
||||
export class MappingSpec {
|
||||
@test
|
||||
async 'Any or unknown should create a dynamic field'() {
|
||||
magAppInstance.testInterfaceAgainstPath(anyUnknownTest);
|
||||
return directory.isDirectory()
|
||||
? ([] as string[]).concat(...readdirSync(fullPath).map(fragment =>
|
||||
expandPathToFilesSync(path.resolve(sourcePath, fragment), accept),
|
||||
))
|
||||
: [fullPath].filter(accept);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Filterable tag should add raw field to strings'() {
|
||||
magAppInstance.testInterfaceAgainstPath(filterableTagTest);
|
||||
for (const file of expandPathToFilesSync('./test/mapping-model/mappings/', file => file.endsWith('mapping-test.ts'))) {
|
||||
try {
|
||||
const test = (await import(file))['testConfig'] as MapAggTestOptions;
|
||||
|
||||
it(test.testName, function () {
|
||||
magAppInstance.testInterfaceAgainstPath(test)
|
||||
})
|
||||
} catch (error) {
|
||||
await Logger.error('UNHANDLED REJECTION', error.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Tags should be able to be paired'() {
|
||||
magAppInstance.testInterfaceAgainstPath(pairedTagsTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Inherited properties should inherit tags'() {
|
||||
magAppInstance.testInterfaceAgainstPath(inheritedPropertyTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Tags should ignore case'() {
|
||||
magAppInstance.testInterfaceAgainstPath(tagsIgnoreCaseTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Emums should work'() {
|
||||
// Known issue: Enums only use text
|
||||
// https://gitlab.com/openstapps/core-tools/-/issues/46
|
||||
magAppInstance.testInterfaceAgainstPath(enumTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Sortable tag should work'() {
|
||||
magAppInstance.testInterfaceAgainstPath(sortableTagTest);
|
||||
}
|
||||
|
||||
/*
|
||||
https://gitlab.com/openstapps/core-tools/-/merge_requests/29
|
||||
@test
|
||||
async 'Wrapper types should inherit tags'() {
|
||||
this.testInterfaceAgainstPath(typeWrapperInheritanceTest);
|
||||
}*/
|
||||
|
||||
@test
|
||||
async 'Inherit tags tag should work'() {
|
||||
magAppInstance.testInterfaceAgainstPath(inheritTagsTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Object union types should work'() {
|
||||
magAppInstance.testInterfaceAgainstPath(objectUnionTest);
|
||||
}
|
||||
|
||||
/*
|
||||
https://gitlab.com/openstapps/core-tools/-/issues/47
|
||||
@test
|
||||
async 'Type queries should work'() {
|
||||
magAppInstance.testInterfaceAgainstPath(typeQueryTest);
|
||||
}*/
|
||||
|
||||
@test
|
||||
async 'Type alias annotations should work'(){
|
||||
magAppInstance.testInterfaceAgainstPath(typeAliasTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Impossible union should cause an error'() {
|
||||
magAppInstance.testInterfaceAgainstPath(impossibleUnionTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Index Signatures should work'() {
|
||||
magAppInstance.testInterfaceAgainstPath(indexSignatureTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Nested properties should work'() {
|
||||
magAppInstance.testInterfaceAgainstPath(nestedTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Generics should work'() {
|
||||
magAppInstance.testInterfaceAgainstPath(genericTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Missing premap should cause an error'() {
|
||||
magAppInstance.testInterfaceAgainstPath(missingPremapTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Default generics should fail'() {
|
||||
magAppInstance.testInterfaceAgainstPath(defaultGenericTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Explicit type annotations should work'() {
|
||||
magAppInstance.testInterfaceAgainstPath(mapExplicitTypesTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Double type annotations should cause an error'() {
|
||||
magAppInstance.testInterfaceAgainstPath(doubleTypeConflictTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Incompatible type annotations should cause an error and use defaults'() {
|
||||
magAppInstance.testInterfaceAgainstPath(incompatibleTypeTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Primitive types should have sensible defaults'() {
|
||||
magAppInstance.testInterfaceAgainstPath(sensibleDefaultsTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Invalid tags should cause an error'() {
|
||||
magAppInstance.testInterfaceAgainstPath(invalidTagTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Dates and date ranges should have the correct type'() {
|
||||
magAppInstance.testInterfaceAgainstPath(dateAndRangeTest);
|
||||
}
|
||||
|
||||
@test
|
||||
async 'Premaps should support non-external types'() {
|
||||
magAppInstance.testInterfaceAgainstPath(typeOverridesTest);
|
||||
}
|
||||
}
|
||||
}).timeout(20_000).slow(10_000);
|
||||
|
||||
Reference in New Issue
Block a user