#include #include #include SCENARIO("the test suite is working") { REQUIRE(true); REQUIRE_FALSE(false); } struct TestConnection { std::string reason_ = ""; int status_ = 0; }; struct TestWsServer { void send_close(std::shared_ptr con, int status, const std::string &reason) { send_close_calls_++; con->reason_ = reason; con->status_ = status; } int send_close_calls_ = 0; }; SCENARIO("we have a websocket resource") { TestSession session; TestWsServer server; auto connection = std::make_shared(); GIVEN("the session is valid") { session.valid = true; WHEN("we open the connection") { tr::ws::on_open(server, session, connection); THEN("the session should post torrent torrent updates") { REQUIRE(session.post_torrent_updates_calls_ == 1); } } } GIVEN("the session is invalid") { WHEN("we open the connection") { tr::ws::on_open(server, session, connection); THEN("the server should close the connection") { REQUIRE(server.send_close_calls_ == 1); REQUIRE(connection->status_ == 1011); REQUIRE(connection->reason_ == "Session not valid"); } } } }