Browse Source

More tests of torrens resource, also correct a bug

master
Jørgen Lien Sellæg 9 years ago
parent
commit
f7f0e0f9ca
  1. 6
      toREST/include/torrents.hpp
  2. 23
      toREST/tests/include/TorrentContext.hpp
  3. 13
      toREST/tests/stubs/TorrentContext.cpp
  4. 10
      toREST/tests/torrents_test.cpp

6
toREST/include/torrents.hpp

@ -31,10 +31,12 @@ void get(torrent_session &session, response resp, request req) {
http_response.set_body(response_object); http_response.set_body(response_object);
} else { } else {
auto response_code = http::code(http::service_unavailable); auto response_code = http::code(http::service_unavailable);
http_response.set_body({{response_code.first, response_code.second}}); http_response.set_body({{"code", response_code.first}, {"status", response_code.second}});
http_response.set_status(response_code.first); http_response.set_status(response_code.first);
} }
*resp << http_response; *resp << http_response;
} }
}}} }
}
}
#endif #endif

23
toREST/tests/include/TorrentContext.hpp

@ -1,8 +1,29 @@
#ifndef _TR_TEST_TORRENT_CONTEXT_HPP_ #ifndef _TR_TEST_TORRENT_CONTEXT_HPP_
#define _TR_TEST_TORRENT_CONTEXT_HPP_ #define _TR_TEST_TORRENT_CONTEXT_HPP_
#include <string>
class InfoHash {
public:
std::string to_string() { return "banana"; }
};
class TorrentStatus {
public:
bool paused = false;
bool is_seeding = false;
int state = 0;
int priority = 0;
std::string name = "N/A";
};
class TestTorrent { class TestTorrent {
public:
bool is_valid();
InfoHash info_hash();
TorrentStatus status(int type);
int query_name = 1;
int query_save_path = 2;
bool valid = true;
}; };
#endif #endif

13
toREST/tests/stubs/TorrentContext.cpp

@ -0,0 +1,13 @@
#include <TorrentContext.hpp>
InfoHash TestTorrent::info_hash() {
return InfoHash();
}
TorrentStatus TestTorrent::status(int type) {
return TorrentStatus();
}
bool TestTorrent::is_valid() {
return valid;
}

10
toREST/tests/torrents_test.hpp → toREST/tests/torrents_test.cpp

@ -1,10 +1,11 @@
#include <Catch/fakeit.hpp> #include <Catch/fakeit.hpp>
#include <SessionContext.hpp>
#include <ServerContext.hpp> #include <ServerContext.hpp>
#include <SessionContext.hpp>
#include <torrents.hpp>
using namespace std; using namespace std;
SCENARIO("We are running a GET /session resource") { SCENARIO("We are running a GET /session/torrents resource") {
auto torrent_session = TestSession(); auto torrent_session = TestSession();
auto response = std::make_shared<TestResponse>(); auto response = std::make_shared<TestResponse>();
auto request = std::make_shared<TestRequest>(); auto request = std::make_shared<TestRequest>();
@ -20,10 +21,9 @@ SCENARIO("We are running a GET /session resource") {
torrent_session.valid = true; torrent_session.valid = true;
AND_WHEN("the session is paused the paused field is set to true") { AND_WHEN("the session is paused the paused field is set to true") {
torrent_session.paused = true; torrent_session.paused = true;
tr::session::get(torrent_session, response, request); tr::session::torrents::get(torrent_session, response, request);
THEN("the server should reply with resource data") { THEN("the server should reply with resource data") {
REQUIRE(response->string() == ok_data_paused); CommonResponse::ok(response, {{"torrents", nlohmann::json::array()}});
reply_is_200_ok(response);
} }
} }
} }
Loading…
Cancel
Save