From 2d0662331ed3e0dde5408de8d719f1b2a3e273af Mon Sep 17 00:00:00 2001 From: sanketshevkar Date: Thu, 16 Jan 2025 18:34:44 +0530 Subject: [PATCH] fix(aliasing): add new tests Signed-off-by: sanketshevkar --- .../test/introspect/mapdeclaration.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/concerto-core/test/introspect/mapdeclaration.js b/packages/concerto-core/test/introspect/mapdeclaration.js index aa0dc1156..04f6565d3 100644 --- a/packages/concerto-core/test/introspect/mapdeclaration.js +++ b/packages/concerto-core/test/introspect/mapdeclaration.js @@ -26,8 +26,10 @@ const ParserUtil = require('./parserutility'); const ModelManager = require('../../lib/modelmanager'); const Util = require('../composer/composermodelutility'); const fs = require('fs'); +const path = require('path'); const sinon = require('sinon'); +const ModelFile = require('../../lib/introspect/modelfile'); const expect = require('chai').expect; @@ -787,3 +789,40 @@ describe('MapDeclaration', () => { }); }); }); + +describe('MapDeclration - Test for declarations using Import Aliasing', () => { + + let modelManager; + let resolvedModelManager; + + beforeEach(() => { + modelManager = new ModelManager({ strict: true, importAliasing: true, enableMapType: true}); + + const childModelCTO = fs.readFileSync(path.resolve(__dirname, '../data/aliasing/child.cto'), 'utf8'); + const parentModelCTO = fs.readFileSync(path.resolve(__dirname, '../data/aliasing/parent.cto'), 'utf8'); + + modelManager.addCTOModel(childModelCTO, 'child@1.0.0.cto'); + modelManager.addCTOModel(parentModelCTO, 'parent@1.0.0.cto'); + const resolvedMetamodelChild = modelManager.resolveMetaModel(modelManager.getAst().models[0]); + const resolvedMetamodelParent = modelManager.resolveMetaModel(modelManager.getAst().models[1]); + resolvedModelManager = new ModelManager({ strict: true, importAliasing: true, enableMapType: true}); + const resolvedModelFileChild = new ModelFile(resolvedModelManager, resolvedMetamodelChild, 'child@1.0.0.cto'); + const resolvedModelFileParent = new ModelFile(resolvedModelManager, resolvedMetamodelParent, 'parent@1.0.0.cto'); + resolvedModelManager.addModelFiles([resolvedModelFileChild, resolvedModelFileParent], ['child@1.0.0.cto', 'parent@1.0.0.cto']); + }); + + describe('#validate', () => { + + it('should be able get validate a map key which is an imported scalar type which is aliased', () => { + const mapDeclaration = resolvedModelManager.getType('parent@1.0.0.KidIndex'); + const key = mapDeclaration.getKey(); + expect(key.validate.bind(key)).to.not.throw(); + }); + + it('should be able get validate a map value which is an imported type which is aliased', () => { + const mapDeclaration = resolvedModelManager.getType('parent@1.0.0.KidIndex'); + const value = mapDeclaration.getValue(); + expect(value.validate.bind(value)).to.not.throw(); + }); + }); +});