|
|
|
|
@ -12,6 +12,12 @@ struct TestConnection {
|
|
|
|
|
int status_ = 0; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct TestMessage : public std::stringstream { |
|
|
|
|
std::string string() { |
|
|
|
|
return str(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct TestWsServer { |
|
|
|
|
void send_close(std::shared_ptr<TestConnection> con, int status, const std::string &reason) { |
|
|
|
|
send_close_calls_++; |
|
|
|
|
@ -44,4 +50,39 @@ SCENARIO("we have a websocket resource") {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
auto message = std::make_shared<TestMessage>(); |
|
|
|
|
GIVEN("we recive an json request") { |
|
|
|
|
WHEN("the json isn't valid") { |
|
|
|
|
*message << "Not valid"; |
|
|
|
|
THEN("the server should reject the action") { |
|
|
|
|
tr::ws::on_message(session, connection, message); |
|
|
|
|
REQUIRE(server.send_close_calls_ == 0); |
|
|
|
|
REQUIRE(session.post_torrent_updates_calls_ == 0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
WHEN("the json is valid but doesn't have any of the required fields") { |
|
|
|
|
*message << "{}"; |
|
|
|
|
THEN("the server should reject the action") { |
|
|
|
|
tr::ws::on_message(session, connection, message); |
|
|
|
|
REQUIRE(server.send_close_calls_ == 0); |
|
|
|
|
REQUIRE(session.post_torrent_updates_calls_ == 0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
WHEN("the json is valid and have the required fields but not of valid type") { |
|
|
|
|
*message << nlohmann::json({{"type", "N/A"}}); |
|
|
|
|
THEN("the server should reject the action") { |
|
|
|
|
tr::ws::on_message(session, connection, message); |
|
|
|
|
REQUIRE(server.send_close_calls_ == 0); |
|
|
|
|
REQUIRE(session.post_torrent_updates_calls_ == 0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
WHEN("the json is valid and have the required fields") { |
|
|
|
|
*message << nlohmann::json({{"type", "POST_TORRENT_UPDATES"}}); |
|
|
|
|
THEN("the server should post torrent updates") { |
|
|
|
|
tr::ws::on_message(session, connection, message); |
|
|
|
|
REQUIRE(server.send_close_calls_ == 0); |
|
|
|
|
REQUIRE(session.post_torrent_updates_calls_ == 1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |