Skip to content

Commit

Permalink
fix: allow handoffs with no controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTWF committed Sep 19, 2022
1 parent 9fd900d commit 3ef062a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/plugin/handoff/HandoffCollectionFactory.cpp
Expand Up @@ -43,7 +43,6 @@ namespace UKControllerPlugin::Handoff {
{
return order.is_object() && order.contains("id") && order.at("id").is_number_integer() &&
order.contains("controller_positions") && order.at("controller_positions").is_array() &&
!order.at("controller_positions").empty() &&
controllerFactory.CreateSharedFromJsonById(order.at("controller_positions")) != nullptr;
}
} // namespace UKControllerPlugin::Handoff
20 changes: 9 additions & 11 deletions test/plugin/handoff/HandoffCollectionFactoryTest.cpp
Expand Up @@ -39,6 +39,13 @@ namespace UKControllerPluginTest::Handoff {
EXPECT_TRUE(HandoffOrderValid(data, this->factory));
}

TEST_F(HandoffCollectionFactoryTest, HandoffOrderIsValidIfControllersEmpty)
{
const nlohmann::json data = {{"id", 1}, {"controller_positions", nlohmann::json::array()}};

EXPECT_TRUE(HandoffOrderValid(data, this->factory));
}

TEST_F(HandoffCollectionFactoryTest, HandoffOrderIsInvalidIfNoId)
{
const nlohmann::json data = {{"controller_positions", nlohmann::json::array({1, 2})}};
Expand Down Expand Up @@ -67,13 +74,6 @@ namespace UKControllerPluginTest::Handoff {
EXPECT_FALSE(HandoffOrderValid(data, this->factory));
}

TEST_F(HandoffCollectionFactoryTest, HandoffOrderIsInvalidIfControllerPositionsEmpty)
{
const nlohmann::json data = {{"id", 1}, {"controller_positions", nlohmann::json::array()}};

EXPECT_FALSE(HandoffOrderValid(data, this->factory));
}

TEST_F(HandoffCollectionFactoryTest, HandoffOrderIsInvalidIfControllerPositionNotInteger)
{
const nlohmann::json data = {{"id", 1}, {"controller_positions", nlohmann::json::array({"abc"})}};
Expand All @@ -97,7 +97,7 @@ namespace UKControllerPluginTest::Handoff {
{
nlohmann::json handoffs = nlohmann::json::array();
handoffs.push_back(nlohmann::json{{"id", 1}, {"controller_positions", nlohmann::json::array({1, 2})}});
handoffs.push_back(nlohmann::json{{"id", 2}, {"controller_positions", nlohmann::json::array({1})}});
handoffs.push_back(nlohmann::json{{"id", 2}, {"controller_positions", nlohmann::json::array()}});

auto collection = Create(this->factory, handoffs);
EXPECT_EQ(2, collection->Count());
Expand All @@ -109,9 +109,7 @@ namespace UKControllerPluginTest::Handoff {

auto handoff2 = collection->Get(2);
EXPECT_EQ(2, handoff2->id);
EXPECT_EQ(1, handoff2->order->CountPositions());
EXPECT_TRUE(handoff2->order->PositionInHierarchy(*controllers.FetchPositionById(1)));
EXPECT_FALSE(handoff2->order->PositionInHierarchy(*controllers.FetchPositionById(2)));
EXPECT_EQ(0, handoff2->order->CountPositions());
}

TEST_F(HandoffCollectionFactoryTest, ItReturnsAnEmptyCollectionIfHandoffsNotValid)
Expand Down

0 comments on commit 3ef062a

Please sign in to comment.