Skip to content

Commit

Permalink
chore(tests) : fix borked tests
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Selman <danscode@selman.org>
  • Loading branch information
dselman committed Dec 16, 2020
1 parent 4a9fa66 commit 15644b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
22 changes: 12 additions & 10 deletions packages/concerto-core/lib/introspect/classdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,20 @@ class ClassDeclaration extends Decorated {
if (idField.isOptional()) {
throw new IllegalModelException('Identifying fields cannot be optional.', this.modelFile, this.ast.location);
}
if (this.getSuperType()) {
const superType = this.getModelFile().getType(this.superType);

if(this.isSystemIdentified()) {
// check that the super type is also system identified
if(!superType.isSystemIdentified()) {
throw new IllegalModelException(`Super class has an explicit identifier ${superType.getIdentifierFieldName()} that cannot be redeclared.`, this.modelFile, this.ast.location);
if(this.superType) {
const superType = this.getModelFile().getType(this.superType);
if (superType && superType.getIdentifierFieldName() ) {
if(this.isSystemIdentified()) {
// check that the super type is also system identified
if(!superType.isSystemIdentified()) {
throw new IllegalModelException(`Super class ${superType.getFullyQualifiedName()} has an explicit identifier ${superType.getIdentifierFieldName()} that cannot be redeclared.`, this.modelFile, this.ast.location);
}
}
}
else {
if(superType.isExplicitlyIdentified()) {
throw new IllegalModelException(`Super class has an explicit identifier ${superType.getIdentifierFieldName()} that cannot be redeclared.`, this.modelFile, this.ast.location);
else {
if(superType.isExplicitlyIdentified()) {
throw new IllegalModelException(`Super class ${superType.getFullyQualifiedName()} has an explicit identifier ${superType.getIdentifierFieldName()} that cannot be redeclared.`, this.modelFile, this.ast.location);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class IdentifiedDeclaration extends ClassDeclaration {
constructor(modelFile, ast) {
super(modelFile, ast);
this._isIdentifiedDeclaration = true;
this.process();
}

/**
Expand All @@ -47,7 +48,7 @@ class IdentifiedDeclaration extends ClassDeclaration {
process() {
super.process();

if(!this.superType && !this.idField) {
if(this.superType === 'Concept' && !this.idField) {
this.idField = '$identifier';
this.addIdentifierField();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/concerto-core/test/introspect/classdeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('ClassDeclaration', () => {
let asset = introspectUtils.loadLastDeclaration('test/data/parser/classdeclaration.identifierextendsfromsupertype.cto', AssetDeclaration);
(() => {
asset.validate();
}).should.throw(/Super class has an explicit identifier a1 that cannot be redeclared/);
}).should.throw(/Super class com.testing.p1 has an explicit identifier a1 that cannot be redeclared/);
});

// TODO: This has been disabled pending major version bump and/or confirmation that this is illegal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ asset Order identified by sku {
}
`, 'test.cto');
}).should.throw(/Super class has an explicit identifier sku that cannot be redeclared./);
}).should.throw(/Super class test.Order has an explicit identifier sku that cannot be redeclared./);
});

it('should not allow overriding system identifier', () => {
Expand Down Expand Up @@ -153,7 +153,7 @@ asset Order identified by sku {
}
`, 'test.cto');
}).should.throw(/Super class has an explicit identifier sku that cannot be redeclared./);
}).should.throw(/Super class test.Order has an explicit identifier sku that cannot be redeclared./);
});

it('should not allow overriding explicit identifier with an explicit identifier', () => {
Expand All @@ -173,7 +173,7 @@ asset Order identified by sku {
}
`, 'test.cto');
}).should.throw(/Super class has an explicit identifier sku that cannot be redeclared./);
}).should.throw(/Super class test.Order has an explicit identifier sku that cannot be redeclared./);
});

it('should not allow field called $identifier', () => {
Expand Down

0 comments on commit 15644b5

Please sign in to comment.