Skip to content

Commit

Permalink
fix(aliasing): add new tests
Browse files Browse the repository at this point in the history
Signed-off-by: sanketshevkar <[email protected]>
  • Loading branch information
sanketshevkar committed Jan 16, 2025
1 parent 462236d commit 2d06623
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/concerto-core/test/introspect/mapdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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, '[email protected]');
modelManager.addCTOModel(parentModelCTO, '[email protected]');
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, '[email protected]');
const resolvedModelFileParent = new ModelFile(resolvedModelManager, resolvedMetamodelParent, '[email protected]');
resolvedModelManager.addModelFiles([resolvedModelFileChild, resolvedModelFileParent], ['[email protected]', '[email protected]']);
});

describe('#validate', () => {

it('should be able get validate a map key which is an imported scalar type which is aliased', () => {
const mapDeclaration = resolvedModelManager.getType('[email protected]');
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('[email protected]');
const value = mapDeclaration.getValue();
expect(value.validate.bind(value)).to.not.throw();
});
});
});

0 comments on commit 2d06623

Please sign in to comment.