-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: forward tags to scenario request handler (#483)
* feat!: Forward tags to scenario request handler * check for optional before usage * Add unit tests for forwarding tags * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Process review comments --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
0c594d9
commit a66f711
Showing
7 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "services/cucumber/CucumberRequestHandlers.hpp" | ||
|
||
namespace services | ||
{ | ||
void CucumberScenarioRequestHandler::BeginScenario(infra::JsonArray&, const infra::Function<void()>& onDone) | ||
{ | ||
onDone(); | ||
} | ||
|
||
void CucumberScenarioRequestHandler::EndScenario(const infra::Function<void()>& onDone) | ||
{ | ||
onDone(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
services/cucumber/test/TestCucumberWireProtocolController.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "infra/timer/test_helper/ClockFixture.hpp" | ||
#include "infra/util/BoundedString.hpp" | ||
#include "services/cucumber/CucumberContext.hpp" | ||
#include "services/cucumber/CucumberRequestHandlers.hpp" | ||
#include "services/cucumber/CucumberWireProtocolController.hpp" | ||
#include "services/cucumber/CucumberWireProtocolParser.hpp" | ||
#include "services/network/test_doubles/ConnectionMock.hpp" | ||
#include "gmock/gmock.h" | ||
#include <algorithm> | ||
|
||
namespace | ||
{ | ||
class CucumberScenarioRequestHandlerMock | ||
: public services::CucumberScenarioRequestHandler | ||
{ | ||
public: | ||
MOCK_METHOD(void, BeginScenario, (infra::JsonArray & tags, const infra::Function<void()>& onDone), (override)); | ||
MOCK_METHOD(void, EndScenario, (const infra::Function<void()>& onDone), (override)); | ||
}; | ||
|
||
class CucumberWireProtocolControllerTest | ||
: public testing::Test | ||
, public infra::ClockFixture | ||
{ | ||
public: | ||
void Request(infra::BoundedConstString request); | ||
void RequestWithoutScenarioTags(infra::BoundedConstString request); | ||
|
||
public: | ||
services::CucumberContext context; | ||
testing::StrictMock<services::ConnectionObserverMock> connectionObserver; | ||
testing::StrictMock<CucumberScenarioRequestHandlerMock> scenarioRequestHandler; | ||
services::CucumberWireProtocolController controller{ connectionObserver, scenarioRequestHandler }; | ||
services::CucumberWireProtocolParser parser; | ||
}; | ||
|
||
void CucumberWireProtocolControllerTest::Request(infra::BoundedConstString request) | ||
{ | ||
parser.ParseRequest(request); | ||
controller.HandleRequest(parser); | ||
} | ||
|
||
void CucumberWireProtocolControllerTest::RequestWithoutScenarioTags(infra::BoundedConstString request) | ||
{ | ||
parser.ParseRequest(request); | ||
parser.scenarioTags = infra::none; | ||
controller.HandleRequest(parser); | ||
} | ||
}; | ||
|
||
TEST_F(CucumberWireProtocolControllerTest, begin_scenario_with_uninitialized_tags_calls_with_empty_json_array) | ||
{ | ||
EXPECT_CALL(scenarioRequestHandler, BeginScenario(testing::Eq(infra::JsonArray()), testing::_)); | ||
Request(R"(["begin_scenario"])"); | ||
} | ||
|
||
TEST_F(CucumberWireProtocolControllerTest, begin_scenario_without_tags_calls_with_empty_json_array) | ||
{ | ||
EXPECT_CALL(scenarioRequestHandler, BeginScenario(testing::Eq(infra::JsonArray()), testing::_)); | ||
RequestWithoutScenarioTags(R"(["begin_scenario"])"); | ||
} | ||
|
||
TEST_F(CucumberWireProtocolControllerTest, begin_scenario_with_tags_forward_tags_as_json_array) | ||
{ | ||
EXPECT_CALL(scenarioRequestHandler, BeginScenario(testing::Eq(infra::JsonArray(R"(["tag1","tag2"])")), testing::_)); | ||
Request(R"(["begin_scenario",{"tags":["tag1","tag2"]}])"); | ||
} |