Skip to content

Commit

Permalink
fix(jsonpopulator) Added test case for abstract object - I769
Browse files Browse the repository at this point in the history
Signed-off-by: kshitij79 <kshitijpathania@gmail.com>
  • Loading branch information
kshitij79 committed Mar 20, 2024
1 parent 571faf6 commit 85e5949
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/concerto-core/test/serializer/jsonpopulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ describe('JSONPopulator', () => {
o String assetId
}
`);
modelManager.addCTOModel(`
namespace org.acme.abstract
abstract asset Asset3 {
o String assetId
}
asset Asset4 extends Asset3 {}
map AssetByName {
o String
o Asset3
}
concept MyContainerAsset3 {
o AssetByName assetByName
}
`);
assetDeclaration1 = modelManager.getType('org.acme.MyContainerAsset1').getProperty('myAsset');
relationshipDeclaration1 = modelManager.getType('org.acme.MyTx1').getProperty('myAsset');
relationshipDeclaration2 = modelManager.getType('org.acme.MyTx2').getProperty('myAssets');
Expand Down Expand Up @@ -479,6 +493,29 @@ describe('JSONPopulator', () => {
jsonPopulator.visit(modelManager.getType('org.acme.MyContainerAsset2'), options);
}).should.throw(/Expected value at path `\$.rootObj.myAssets\[0\].assetValue` to be of type `Integer`/);
});

it('should be able to deserialise a map that uses abstract types as values', () => {

Check failure on line 497 in packages/concerto-core/test/serializer/jsonpopulator.js

View workflow job for this annotation

GitHub Actions / Unit Tests (16.x, ubuntu-latest)

Trailing spaces not allowed

Check failure on line 497 in packages/concerto-core/test/serializer/jsonpopulator.js

View workflow job for this annotation

GitHub Actions / Unit Tests (18.x, ubuntu-latest)

Trailing spaces not allowed
let options = {
jsonStack: new TypedStack({
$class: 'org.acme.abstract.MyContainerAsset3',
assetByName: {
'asset3': {
$class: 'org.acme.abstract.Asset4'
}
}
}),
resourceStack: new TypedStack({}),
factory: mockFactory,
modelManager: modelManager
};

let mockResource1 = sinon.createStubInstance(Resource);
mockFactory.newResource.withArgs('org.acme.abstract', 'MyAsset4', 'asset3').returns(mockResource1);
(() => {
jsonPopulator.visit(modelManager.getType('org.acme.abstract.MyContainerAsset3'), options);
}).should.not.throw();
});

});

describe('#visitField', () => {
Expand Down

0 comments on commit 85e5949

Please sign in to comment.