|
|
|
@ -52,6 +52,8 @@ SCENARIO("We are running a POST /session/torrents resource") { |
|
|
|
auto settings = Config(); |
|
|
|
auto settings = Config(); |
|
|
|
auto response = std::make_shared<TestResponse>(); |
|
|
|
auto response = std::make_shared<TestResponse>(); |
|
|
|
auto request = std::make_shared<TestRequest>(); |
|
|
|
auto request = std::make_shared<TestRequest>(); |
|
|
|
|
|
|
|
const std::string magnet_hash = "c0b0a90089710812fe8c37385a4cc2978eabf3e8"; |
|
|
|
|
|
|
|
const auto magnet_uri = "magnet:?xt=urn:btih:" + magnet_hash + "&dn=Taylor Swift&tr=http://tracker.sout.no"; |
|
|
|
GIVEN("the server is not working properly") { |
|
|
|
GIVEN("the server is not working properly") { |
|
|
|
AND_WHEN("we recive a request") { |
|
|
|
AND_WHEN("we recive a request") { |
|
|
|
tr::session::torrents::post(settings, torrent_session, response, request); |
|
|
|
tr::session::torrents::post(settings, torrent_session, response, request); |
|
|
|
@ -64,30 +66,46 @@ SCENARIO("We are running a POST /session/torrents resource") { |
|
|
|
torrent_session.valid = true; |
|
|
|
torrent_session.valid = true; |
|
|
|
WHEN("we recive a valid request") { |
|
|
|
WHEN("we recive a valid request") { |
|
|
|
GIVEN("we use the default download directory") { |
|
|
|
GIVEN("we use the default download directory") { |
|
|
|
request->content << nlohmann::json::object({{"magnet_uri", "magnet:?xt=urn:btih:c0b0a90089710812fe8c37385a4cc2978eabf3e8&dn=Taylor Swift&tr=http://tracker.sout.no"}}); |
|
|
|
request->content << nlohmann::json::object({{"magnet_uri", magnet_uri}}); |
|
|
|
THEN("the server should reply with created") { |
|
|
|
THEN("the server should reply with created") { |
|
|
|
tr::session::torrents::post(settings, torrent_session, response, request); |
|
|
|
tr::session::torrents::post(settings, torrent_session, response, request); |
|
|
|
CommonResponse::created(response, request, "/session/torrents/hash"); |
|
|
|
CommonResponse::created(response, request, "/session/torrents/" + magnet_hash); |
|
|
|
|
|
|
|
REQUIRE(torrent_session.get_torrents().size() == 1); |
|
|
|
|
|
|
|
REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/toREST"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
GIVEN("we specify a absolute save path") { |
|
|
|
|
|
|
|
request->content << nlohmann::json::object( |
|
|
|
GIVEN("the torrent doesn't exist") { |
|
|
|
{{"magnet_uri", magnet_uri}, |
|
|
|
// tr::session::torrents::post(settings, torrent_session, response, request);
|
|
|
|
{"save_path", "/music"}}); |
|
|
|
// tr::session::torrents::get(torrent_session, response, request);
|
|
|
|
tr::session::torrents::post(settings, torrent_session, response, request); |
|
|
|
// CommonResponse::ok(response, {{"torrents", nlohmann::json::array()}});
|
|
|
|
THEN("the server should reply with bad request") { |
|
|
|
// }
|
|
|
|
CommonResponse::bad_request(response); |
|
|
|
// }
|
|
|
|
REQUIRE(torrent_session.get_torrents().size() == 0); |
|
|
|
// GIVEN("we have at least one torrent") {
|
|
|
|
} |
|
|
|
// auto t_torrent = TestTorrent();
|
|
|
|
|
|
|
|
// torrent_session.get_torrents().emplace_back(t_torrent);
|
|
|
|
|
|
|
|
// THEN("the server should reply with an array of torrents") {
|
|
|
|
|
|
|
|
// tr::session::torrents::get(torrent_session, response, request);
|
|
|
|
|
|
|
|
// CommonResponse::ok(response, {{"torrents", {torrent}}});
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
GIVEN("the torrent exists from before") { |
|
|
|
GIVEN("we specify a relative save path") { |
|
|
|
|
|
|
|
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 with bad request") { |
|
|
|
|
|
|
|
CommonResponse::created(response, request, "/session/torrents/" + magnet_hash); |
|
|
|
|
|
|
|
REQUIRE(torrent_session.get_torrents().size() == 1); |
|
|
|
|
|
|
|
REQUIRE((torrent_session.get_torrents()[0]).status().save_path == "/music"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// tr::session::torrents::get(torrent_session, response, request);
|
|
|
|
|
|
|
|
// CommonResponse::ok(response, {{"torrents", nlohmann::json::array()}});
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// GIVEN("we have at least one torrent") {
|
|
|
|
|
|
|
|
// auto t_torrent = TestTorrent();
|
|
|
|
|
|
|
|
// torrent_session.get_torrents().emplace_back(t_torrent);
|
|
|
|
|
|
|
|
// THEN("the server should reply with an array of torrents") {
|
|
|
|
|
|
|
|
// tr::session::torrents::get(torrent_session, response, request);
|
|
|
|
|
|
|
|
// CommonResponse::ok(response, {{"torrents", {torrent}}});
|
|
|
|
|
|
|
|
// };
|
|
|
|
} |
|
|
|
} |
|
|
|
WHEN("we recive an invalid request") { |
|
|
|
WHEN("we recive an invalid request") { |
|
|
|
GIVEN("the request doesn't contain valid json") { |
|
|
|
GIVEN("the request doesn't contain valid json") { |
|
|
|
|