Skip to content

Commit

Permalink
Merge pull request #478 from VATSIM-UK/remove-key-from-handoffs
Browse files Browse the repository at this point in the history
Remove key from handoffs
  • Loading branch information
AndyTWF authored Jul 31, 2022
2 parents 94e874e + 51b9018 commit 2918980
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/plugin/handoff/HandoffCollectionFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace UKControllerPlugin::Handoff {
-> bool
{
return order.is_object() && order.contains("id") && order.at("id").is_number_integer() &&
order.contains("key") && order.at("key").is_string() && order.contains("controller_positions") &&
order.at("controller_positions").is_array() && !order.at("controller_positions").empty() &&
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
51 changes: 12 additions & 39 deletions test/plugin/handoff/HandoffCollectionFactoryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,79 +34,56 @@ namespace UKControllerPluginTest::Handoff {

TEST_F(HandoffCollectionFactoryTest, HandoffOrderIsValid)
{
const nlohmann::json data = {
{"id", 1}, {"key", "handoff_key"}, {"controller_positions", nlohmann::json::array({1, 2})}};
const nlohmann::json data = {{"id", 1}, {"controller_positions", nlohmann::json::array({1, 2})}};

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

TEST_F(HandoffCollectionFactoryTest, HandoffOrderIsInvalidIfNoId)
{
const nlohmann::json data = {{"key", "handoff_key"}, {"controller_positions", nlohmann::json::array({1, 2})}};
const nlohmann::json data = {{"controller_positions", nlohmann::json::array({1, 2})}};

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

TEST_F(HandoffCollectionFactoryTest, HandoffOrderIsInvalidIfIdNotInteger)
{
const nlohmann::json data = {
{"id", "abc"}, {"key", "handoff_key"}, {"controller_positions", nlohmann::json::array({1, 2})}};

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

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

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

TEST_F(HandoffCollectionFactoryTest, HandoffOrderIsInvalidIfKeyNotString)
{
const nlohmann::json data = {{"id", 1}, {"key", 123}, {"controller_positions", nlohmann::json::array({1, 2})}};
const nlohmann::json data = {{"id", "abc"}, {"controller_positions", nlohmann::json::array({1, 2})}};

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

TEST_F(HandoffCollectionFactoryTest, HandoffOrderIsInvalidIfNoControllerPositions)
{
const nlohmann::json data = {
{"id", 1},
{"key", "handoff_key"},
};
const nlohmann::json data = {{"id", 1}};

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

TEST_F(HandoffCollectionFactoryTest, HandoffOrderIsInvalidIfControllerPositionsNotArray)
{
const nlohmann::json data = {
{"id", 1}, {"key", "handoff_key"}, {"controller_positions", nlohmann::json::object()}};
const nlohmann::json data = {{"id", 1}, {"controller_positions", nlohmann::json::object()}};

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

TEST_F(HandoffCollectionFactoryTest, HandoffOrderIsInvalidIfControllerPositionsEmpty)
{
const nlohmann::json data = {
{"id", 1}, {"key", "handoff_key"}, {"controller_positions", nlohmann::json::array()}};
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}, {"key", "handoff_key"}, {"controller_positions", nlohmann::json::array({"abc"})}};
const nlohmann::json data = {{"id", 1}, {"controller_positions", nlohmann::json::array({"abc"})}};

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

TEST_F(HandoffCollectionFactoryTest, HandoffOrderIsInvalidIfControllerPositionIsNotValid)
{
const nlohmann::json data = {
{"id", 1}, {"key", "handoff_key"}, {"controller_positions", nlohmann::json::array({1, 2, 55})}};
const nlohmann::json data = {{"id", 1}, {"controller_positions", nlohmann::json::array({1, 2, 55})}};

EXPECT_FALSE(HandoffOrderValid(data, this->factory));
}
Expand All @@ -119,10 +96,8 @@ namespace UKControllerPluginTest::Handoff {
TEST_F(HandoffCollectionFactoryTest, ItReturnsACollectionOfHandoffs)
{
nlohmann::json handoffs = nlohmann::json::array();
handoffs.push_back(
nlohmann::json{{"id", 1}, {"key", "handoff_key"}, {"controller_positions", nlohmann::json::array({1, 2})}});
handoffs.push_back(
nlohmann::json{{"id", 2}, {"key", "handoff_key_2"}, {"controller_positions", nlohmann::json::array({1})}});
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})}});

auto collection = Create(this->factory, handoffs);
EXPECT_EQ(2, collection->Count());
Expand All @@ -148,10 +123,8 @@ namespace UKControllerPluginTest::Handoff {
TEST_F(HandoffCollectionFactoryTest, ItIgnoresBadHandoffOrders)
{
nlohmann::json handoffs = nlohmann::json::array();
handoffs.push_back(
nlohmann::json{{"id", 1}, {"key", "handoff_key"}, {"controller_positions", nlohmann::json::array({1, 2})}});
handoffs.push_back(
nlohmann::json{{"id", 2}, {"key", "handoff_key_2"}, {"controller_positions", nlohmann::json::array({55})}});
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({55})}});

auto collection = Create(this->factory, handoffs);
EXPECT_EQ(1, collection->Count());
Expand Down

0 comments on commit 2918980

Please sign in to comment.