diff --git a/toREST/include/torrents.hpp b/toREST/include/torrents.hpp index 9ff758b..da31362 100644 --- a/toREST/include/torrents.hpp +++ b/toREST/include/torrents.hpp @@ -122,6 +122,12 @@ void post(settings opts, torrent_session &session, response resp, request req) { } params.download_limit = down_limit; } + + if (request_object.find("name") != request_object.end()) { + auto obj = request_object.at("name"); + if(obj.is_string()) + params.name = obj; + } std::stringstream ss; ss << params.info_hash; diff --git a/toREST/tests/include/TorrentContext.hpp b/toREST/tests/include/TorrentContext.hpp index a40afa7..51e1e8e 100644 --- a/toREST/tests/include/TorrentContext.hpp +++ b/toREST/tests/include/TorrentContext.hpp @@ -29,6 +29,7 @@ public: auto paused = (params.flags & libtorrent::add_torrent_params::flag_paused) == libtorrent::add_torrent_params::flag_paused; status_.paused = paused; status_.save_path = params.save_path; + status_.name = params.name; upload_limit_ = params.upload_limit; download_limit_ = params.download_limit; } diff --git a/toREST/tests/stubs/SessionContext.cpp b/toREST/tests/stubs/SessionContext.cpp index dae902f..bffe453 100644 --- a/toREST/tests/stubs/SessionContext.cpp +++ b/toREST/tests/stubs/SessionContext.cpp @@ -33,6 +33,7 @@ std::string TestSessionSettings::get_str(int type) { if (type == listen_interfaces) { return listen_interfaces_; } + return ""; } void TestSessionSettings::set_str(int type, std::string value) { if (type == listen_interfaces) { diff --git a/toREST/tests/torrents_test.cpp b/toREST/tests/torrents_test.cpp index 3e408e3..4d2233d 100644 --- a/toREST/tests/torrents_test.cpp +++ b/toREST/tests/torrents_test.cpp @@ -19,7 +19,7 @@ SCENARIO("We are running a GET /session/torrents resource") { auto response = std::make_shared(); auto request = std::make_shared(); GIVEN("the server is not working properly") { - AND_WHEN("we recive a request") { + WHEN("we recive a request") { tr::session::torrents::get(torrent_session, response, request); THEN("the server should reply with service unavailable") { CommonResponse::service_unavailable(response); @@ -88,11 +88,13 @@ SCENARIO("We are running a POST /session/torrents resource") { request->content << nlohmann::json::object( {{"magnet_uri", magnet_uri}, {"save_path", "music"}}); - tr::session::torrents::post(settings, torrent_session, response, request); THEN("the server should reply created") { + tr::session::torrents::post(settings, torrent_session, response, request); CommonResponse::created(response, request, "/session/torrents/" + magnet_hash); REQUIRE(torrent_session.get_torrents().size() == 1); REQUIRE_FALSE(torrent_session.get_torrents()[0].status().paused); + REQUIRE(torrent_session.get_torrents()[0].upload_limit() == -1); + REQUIRE(torrent_session.get_torrents()[0].download_limit() == -1); REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/music"); } } @@ -106,20 +108,25 @@ SCENARIO("We are running a POST /session/torrents resource") { CommonResponse::created(response, request, "/session/torrents/" + magnet_hash); REQUIRE(torrent_session.get_torrents().size() == 1); REQUIRE(torrent_session.get_torrents()[0].status().paused); + REQUIRE(torrent_session.get_torrents()[0].upload_limit() == -1); + REQUIRE(torrent_session.get_torrents()[0].download_limit() == -1); REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/music"); } } - GIVEN("we specify up an ddown speed") { + GIVEN("we specify up an down speed") { + const std::string name = "Dent"; request->content << nlohmann::json::object( {{"magnet_uri", magnet_uri}, {"save_path", "music"}, {"up_speed", "100"}, - {"down_speed", "100"}}); + {"down_speed", "100"}, + {"name", name}}); THEN("the server should reply with bad request") { tr::session::torrents::post(settings, torrent_session, response, request); CommonResponse::created(response, request, "/session/torrents/" + magnet_hash); REQUIRE(torrent_session.get_torrents().size() == 1); REQUIRE_FALSE(torrent_session.get_torrents()[0].status().paused); + REQUIRE(torrent_session.get_torrents()[0].status().name == name); REQUIRE(torrent_session.get_torrents()[0].upload_limit() == 100); REQUIRE(torrent_session.get_torrents()[0].download_limit() == 100); REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/music");