From f7f0e0f9cabaa0d9a2dc245981afe0823f922ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Mon, 1 May 2017 22:17:47 +0200 Subject: [PATCH] More tests of torrens resource, also correct a bug --- toREST/include/torrents.hpp | 6 +++-- toREST/tests/include/TorrentContext.hpp | 23 ++++++++++++++++++- toREST/tests/stubs/TorrentContext.cpp | 13 +++++++++++ .../{torrents_test.hpp => torrents_test.cpp} | 10 ++++---- 4 files changed, 44 insertions(+), 8 deletions(-) rename toREST/tests/{torrents_test.hpp => torrents_test.cpp} (77%) diff --git a/toREST/include/torrents.hpp b/toREST/include/torrents.hpp index af9e85a..f60a628 100644 --- a/toREST/include/torrents.hpp +++ b/toREST/include/torrents.hpp @@ -31,10 +31,12 @@ void get(torrent_session &session, response resp, request req) { http_response.set_body(response_object); } else { 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); } *resp << http_response; } -}}} +} +} +} #endif diff --git a/toREST/tests/include/TorrentContext.hpp b/toREST/tests/include/TorrentContext.hpp index b1a9cbb..423a3fa 100644 --- a/toREST/tests/include/TorrentContext.hpp +++ b/toREST/tests/include/TorrentContext.hpp @@ -1,8 +1,29 @@ #ifndef _TR_TEST_TORRENT_CONTEXT_HPP_ #define _TR_TEST_TORRENT_CONTEXT_HPP_ +#include + +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 { - +public: + bool is_valid(); + InfoHash info_hash(); + TorrentStatus status(int type); + int query_name = 1; + int query_save_path = 2; + bool valid = true; }; #endif \ No newline at end of file diff --git a/toREST/tests/stubs/TorrentContext.cpp b/toREST/tests/stubs/TorrentContext.cpp index e69de29..cfa93b8 100644 --- a/toREST/tests/stubs/TorrentContext.cpp +++ b/toREST/tests/stubs/TorrentContext.cpp @@ -0,0 +1,13 @@ +#include + +InfoHash TestTorrent::info_hash() { + return InfoHash(); +} + +TorrentStatus TestTorrent::status(int type) { + return TorrentStatus(); +} + +bool TestTorrent::is_valid() { + return valid; +} \ No newline at end of file diff --git a/toREST/tests/torrents_test.hpp b/toREST/tests/torrents_test.cpp similarity index 77% rename from toREST/tests/torrents_test.hpp rename to toREST/tests/torrents_test.cpp index e95957d..3e6f32a 100644 --- a/toREST/tests/torrents_test.hpp +++ b/toREST/tests/torrents_test.cpp @@ -1,10 +1,11 @@ #include -#include #include +#include +#include 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 response = std::make_shared(); auto request = std::make_shared(); @@ -20,10 +21,9 @@ SCENARIO("We are running a GET /session resource") { torrent_session.valid = true; AND_WHEN("the session is paused the paused field is set to 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") { - REQUIRE(response->string() == ok_data_paused); - reply_is_200_ok(response); + CommonResponse::ok(response, {{"torrents", nlohmann::json::array()}}); } } }