3 changed files with 66 additions and 0 deletions
@ -0,0 +1,32 @@
|
||||
#ifndef _TR_TORRENT_HPP_ |
||||
#define _TR_TORRENT_HPP_ |
||||
|
||||
#include <http.hpp> |
||||
|
||||
namespace tr { |
||||
namespace session { |
||||
namespace torrents { |
||||
namespace id { |
||||
template <class torrent_session, class request, class response> |
||||
void get(torrent_session &session, response resp, request req) { |
||||
auto http_response = http::response(); |
||||
const auto respond = [&](http::status status) { |
||||
const auto response_code = http::code(status); |
||||
http_response.set_body({{"code", response_code.first}, {"status", response_code.second}}); |
||||
http_response.set_status(response_code.first); |
||||
*resp << http_response; |
||||
}; |
||||
|
||||
if (!session.is_valid()) { |
||||
return respond(http::service_unavailable); |
||||
} |
||||
} |
||||
|
||||
template <class settings, class torrent_session, class request, class response> |
||||
void patch(settings opts, torrent_session &session, response resp, request req) { |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
#endif |
||||
@ -0,0 +1,25 @@
|
||||
#include <ServerContext.hpp> |
||||
#include <SessionContext.hpp> |
||||
#include <TorrentContext.hpp> |
||||
#include <torrent.hpp> |
||||
|
||||
SCENARIO("We are running a GET /session/torrents/id resource") { |
||||
auto torrent_session = TestSession(); |
||||
auto response = std::make_shared<TestResponse>(); |
||||
auto request = std::make_shared<TestRequest>(); |
||||
GIVEN("the server is not working properly") { |
||||
WHEN("we recive a request") { |
||||
tr::session::torrents::id::get(torrent_session, response, request); |
||||
THEN("the server should reply with service unavailable") { |
||||
CommonResponse::service_unavailable(response); |
||||
} |
||||
} |
||||
} |
||||
GIVEN("the server is working properly") { |
||||
torrent_session.valid = true; |
||||
THEN("the server should reply with service unavailable") { |
||||
tr::session::torrents::id::get(torrent_session, response, request); |
||||
CommonResponse::ok(response, {}); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue