From 88cae2b43e0f67644086e977e928f020a5fd33b8 Mon Sep 17 00:00:00 2001 From: jcowman2 Date: Thu, 3 Oct 2019 22:52:49 -0500 Subject: [PATCH] refactor(agents): Add error check to InstanceAgentsImpl.registerAgentPrototype --- src/agents/impl/instance-agents-impl.ts | 4 ++++ test/unit/agents.test.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/agents/impl/instance-agents-impl.ts b/src/agents/impl/instance-agents-impl.ts index 54a9e17..c30e185 100644 --- a/src/agents/impl/instance-agents-impl.ts +++ b/src/agents/impl/instance-agents-impl.ts @@ -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); diff --git a/test/unit/agents.test.ts b/test/unit/agents.test.ts index eb1962c..7ad5787 100644 --- a/test/unit/agents.test.ts +++ b/test/unit/agents.test.ts @@ -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); + }); }); });