Skip to content

Commit

Permalink
refactor(agents): Add error check to InstanceAgentsImpl.registerAgent…
Browse files Browse the repository at this point in the history
…Prototype
  • Loading branch information
jcowman2 committed Oct 4, 2019
1 parent c8e1c9f commit 88cae2b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/agents/impl/instance-agents-impl.ts
Expand Up @@ -362,6 +362,10 @@ class InstanceAgentsImpl implements InstanceAgentsInternal {
if (protoId !== undefined) {
if (am === undefined || am.meta.protoId !== undefined) {
return protoId;
} else {
throw new RegalError(
"Failed registering the agent's prototype because a bad protoId was already set"
);
}
} else {
protoId = StaticPrototypeRegistry.getPrototypeIdOrDefault(agent);
Expand Down
10 changes: 10 additions & 0 deletions test/unit/agents.test.ts
Expand Up @@ -1993,6 +1993,16 @@ describe("Agents", function() {
RegalError
);
});

it("Throws a RegalError if an agent's protoId is forced to some value", function() {
Game.init(MD);
const myGame = buildGameInstance();

const _d = new Dummy("D1", 1);
_d.meta.protoId = "foo" as any;

expect(() => myGame.using(_d)).to.throw(RegalError);
});
});
});

Expand Down

0 comments on commit 88cae2b

Please sign in to comment.