diff --git a/toREST/src/main.cxx b/toREST/src/main.cxx index 662b48c..7f83fa2 100644 --- a/toREST/src/main.cxx +++ b/toREST/src/main.cxx @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) { HttpServer http_server(http_port, http_threads); libtorrent::session session; - const auto stats_metrics = libtorrent::session_stats_metrics(); + http_server.default_resource["GET"] = [](std::shared_ptr resp, std::shared_ptr req) { auto response = http::response(); response.set_status(http::not_found); @@ -47,10 +47,15 @@ int main(int argc, char *argv[]) { http_server.resource["^/session/torrents(\\?.*)?\\/?$"]["GET"] = [&](std::shared_ptr resp, std::shared_ptr req) { tr::session::torrents::get(session, resp, req); }; + http_server.resource["^/session/torrents(\\?.*)?\\/?$"]["POST"] = [&](std::shared_ptr resp, std::shared_ptr req) { tr::session::torrents::post(options, session, resp, req); }; + http_server.resource["^/session/torrents(\\?.*)?\\/?$"]["DELETE"] = [&](std::shared_ptr resp, std::shared_ptr req) { + tr::session::torrents::del(session, resp, req); + }; + std::thread server_thread([&http_server]() { http_server.start(); }); diff --git a/toREST/tests/torrents_test.cpp b/toREST/tests/torrents_test.cpp index 1c86f8f..a749f8e 100644 --- a/toREST/tests/torrents_test.cpp +++ b/toREST/tests/torrents_test.cpp @@ -136,6 +136,25 @@ SCENARIO("We are running a POST /session/torrents resource") { REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/music"); } } + 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", 90}, + {"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/" + torrent_id); + 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() == 90); + REQUIRE(torrent_session.get_torrents()[0].download_limit() == 100); + REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/music"); + } + } } WHEN("we recive an invalid request") { GIVEN("the request doesn't contain valid json") {