diff --git a/tests/test_api_v1_accounts_id.cpp b/tests/test_api_v1_accounts_id.cpp index a5ab685..2f8c16c 100644 --- a/tests/test_api_v1_accounts_id.cpp +++ b/tests/test_api_v1_accounts_id.cpp @@ -26,88 +26,45 @@ using namespace Mastodon; SCENARIO ("/api/v1/accounts/:id can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("instance, user id and return_call") - { - const char *envinstance = std::getenv("MASTODON_CPP_INSTANCE"); - const string instance = (envinstance ? envinstance : "likeable.space"); - const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); - const string user_id = - (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + const char *envinstance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (envinstance ? envinstance : "likeable.space"); + const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); + const string user_id = (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + GIVEN ("instance = " + instance + ", user ID = " + user_id) + { + Mastodon::Easy::API masto(instance, ""); return_call ret; + Easy::Account account; bool exception = false; - GIVEN ("Mastodon::API") + WHEN ("/api/v1/accounts/" + user_id + " is called") { - Mastodon::API masto(instance, ""); - bool username_found = false; - - WHEN ("/api/v1/accounts/" + user_id + " is called") + try { - try - { - ret = masto.get(API::v1::accounts_id, - {{ "id", { user_id }}}); - username_found = - ret.answer.find("\"username\":\"") - != std::string::npos; - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("The answer makes sense") - { - REQUIRE(username_found); - } + ret = masto.get(API::v1::accounts_id, + {{ "id", { user_id }}}); + account = Easy::Account(ret.answer); } - } - - GIVEN ("Mastodon::Easy::API") - { - Mastodon::Easy::API masto(instance, ""); - Easy::Account account; - - WHEN ("/api/v1/accounts/" + user_id + " is called") + catch (const std::exception &e) { - try - { - ret = masto.get(API::v1::accounts_id, - {{ "id", { user_id }}}); - account = Easy::Account(ret.answer); - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("Answer is valid") - { - REQUIRE(account.valid()); - } - THEN ("The answer makes sense") - { - REQUIRE(account.username() != ""); - } + exception = true; + WARN(e.what()); + } + + THEN("No exception is thrown") + AND_THEN ("No errors are returned") + AND_THEN ("Answer is valid") + AND_THEN ("The answer makes sense") + { + REQUIRE_FALSE(exception); + + REQUIRE(ret.error_code == 0); + REQUIRE(ret.http_error_code == 200); + + REQUIRE(account.valid()); + + REQUIRE(account.id() == user_id); } } } diff --git a/tests/test_api_v1_accounts_id_follow.cpp b/tests/test_api_v1_accounts_id_follow.cpp index 651d03b..399a2ee 100644 --- a/tests/test_api_v1_accounts_id_follow.cpp +++ b/tests/test_api_v1_accounts_id_follow.cpp @@ -27,103 +27,52 @@ using namespace Mastodon; SCENARIO ("/api/v1/accounts/:id/follow can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("instance, access token, user id and return_call") + const char *env_instance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (env_instance ? env_instance : "likeable.space"); + const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); + const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); + const string user_id = (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + + GIVEN ("instance = " + instance + ", user ID = " + user_id) { - const char *env_instance = std::getenv("MASTODON_CPP_INSTANCE"); - const string instance = - (env_instance ? env_instance : "likeable.space"); - const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); - const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); - const string user_id = - (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); - + Mastodon::Easy::API masto(instance, access_token); return_call ret; + Easy::Relationship relationship; bool exception = false; - bool following_found = false; - bool error_found = false; - // You can't follow yourself, so we look for errors too. REQUIRE (access_token != nullptr); - GIVEN ("Mastodon::API") + WHEN ("/api/v1/accounts/" + user_id + "/follow is called") { - Mastodon::API masto(instance, access_token); - - WHEN ("/api/v1/accounts/" + user_id + "/follow is called") + try { - try - { - ret = masto.post(API::v1::accounts_id_follow, - { - { "id", { user_id } }, - }); - following_found = - ret.answer.find("\"following\":\"") - != std::string::npos; - error_found = following_found = - ret.answer.find("\"error") - != std::string::npos; - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No unexpected errors are returned") - { - REQUIRE((ret.error_code == 0 - || ret.error_code == 111)); - REQUIRE((ret.http_error_code == 200 - || ret.http_error_code == 500)); - } - THEN ("The answer makes sense") - { - REQUIRE((following_found || error_found)); - } + ret = masto.post(API::v1::accounts_id_follow, + { + { "id", { user_id } }, + }); + relationship.from_string(ret.answer); } - } - - GIVEN ("Mastodon::Easy::API") - { - Mastodon::Easy::API masto(instance, access_token); - Easy::Relationship relationship; - - WHEN ("/api/v1/accounts/" + user_id + "/follow is called") + catch (const std::exception &e) { - try - { - ret = masto.post(API::v1::accounts_id_follow, - { - { "id", { user_id } }, - }); - relationship.from_string(ret.answer); - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No unexpected errors are returned") - { - REQUIRE((ret.error_code == 0 - || ret.error_code == 111)); - REQUIRE((ret.http_error_code == 200 - || ret.http_error_code == 500)); - } - THEN ("The answer makes sense") - { - REQUIRE((relationship.following() - || relationship.error() != "")); - } + exception = true; + WARN(e.what()); + } + + THEN("No exception is thrown") + AND_THEN ("No unexpected errors are returned") + AND_THEN ("The answer makes sense") + { + REQUIRE_FALSE(exception); + + // You can't follow yourself, so we look for errors too. + REQUIRE((ret.error_code == 0 + || ret.error_code == 111)); + REQUIRE((ret.http_error_code == 200 + || ret.http_error_code == 500)); + + REQUIRE((relationship.following() + || relationship.error() != "")); } } } diff --git a/tests/test_api_v1_accounts_id_followers.cpp b/tests/test_api_v1_accounts_id_followers.cpp index 3e9b720..d8db85a 100644 --- a/tests/test_api_v1_accounts_id_followers.cpp +++ b/tests/test_api_v1_accounts_id_followers.cpp @@ -27,111 +27,60 @@ using namespace Mastodon; SCENARIO ("/api/v1/accounts/:id/followers can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("instance, access token, user id and return_call") - { - const char *env_instance = std::getenv("MASTODON_CPP_INSTANCE"); - const string instance = - (env_instance ? env_instance : "likeable.space"); - const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); - const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); - const string user_id = - (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + const char *env_instance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (env_instance ? env_instance : "likeable.space"); + const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); + const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); + const string user_id = (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + GIVEN ("instance = " + instance + ", user ID = " + user_id) + { + Mastodon::Easy::API masto(instance, access_token); return_call ret; + Easy::Account account; bool exception = false; - bool username_found = false; REQUIRE (access_token != nullptr); - GIVEN ("Mastodon::API") + WHEN ("/api/v1/accounts/" + user_id + "/followers is called") { - Mastodon::API masto(instance, access_token); - - WHEN ("/api/v1/accounts/" + user_id + "/followers is called") + try { - try + ret = masto.get(API::v1::accounts_id_followers, + { + { "id", { user_id } }, + { "limit", { "5" } } + }); + if (ret.answer == "[]") { - ret = masto.get(API::v1::accounts_id_followers, - { - { "id", { user_id } }, - { "limit", { "5" } } - }); - if (ret.answer == "[]") - { - WARN("No followers found."); - } - username_found = - ret.answer.find("\"username\":\"") - != std::string::npos; + WARN("No followers found."); } - catch (const std::exception &e) + else { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("The answer makes sense") - { - REQUIRE(username_found); + account.from_string + (Easy::json_array_to_vector(ret.answer).front()); } } - } - - GIVEN ("Mastodon::Easy::API") - { - Mastodon::Easy::API masto(instance, access_token); - Easy::Account account; - - WHEN ("/api/v1/accounts/" + user_id + "/followers is called") + catch (const std::exception &e) { - try - { - ret = masto.get(API::v1::accounts_id_followers, - { - { "id", { user_id } }, - { "limit", { "5" } } - }); - if (ret.answer == "[]") - { - WARN("No followers found."); - } - else - { - account.from_string - (Easy::json_array_to_vector(ret.answer).front()); - } - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("Answer is valid") - { - REQUIRE(account.valid()); - } - THEN ("The answer makes sense") - { - REQUIRE(account.username() != ""); - } + exception = true; + WARN(e.what()); + } + + THEN("No exception is thrown") + AND_THEN ("No errors are returned") + AND_THEN ("Answer is valid") + AND_THEN ("The answer makes sense") + { + REQUIRE_FALSE(exception); + + REQUIRE(ret.error_code == 0); + REQUIRE(ret.http_error_code == 200); + REQUIRE(account.valid()); + + REQUIRE(account.username() != ""); } } } } + diff --git a/tests/test_api_v1_accounts_id_following.cpp b/tests/test_api_v1_accounts_id_following.cpp index 5035ca0..243c1a7 100644 --- a/tests/test_api_v1_accounts_id_following.cpp +++ b/tests/test_api_v1_accounts_id_following.cpp @@ -27,110 +27,59 @@ using namespace Mastodon; SCENARIO ("/api/v1/accounts/:id/following can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("instance, access token, user id and return_call") - { - const char *env_instance = std::getenv("MASTODON_CPP_INSTANCE"); - const string instance = - (env_instance ? env_instance : "likeable.space"); - const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); - const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); - const string user_id = - (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + const char *env_instance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (env_instance ? env_instance : "likeable.space"); + const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); + const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); + const string user_id = (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + GIVEN ("instance = " + instance + ", user ID = " + user_id) + { + Mastodon::Easy::API masto(instance, access_token); return_call ret; + Easy::Account account; bool exception = false; - bool username_found = false; REQUIRE (access_token != nullptr); - GIVEN ("Mastodon::API") + WHEN ("/api/v1/accounts/" + user_id + "/following is called") { - Mastodon::API masto(instance, access_token); - - WHEN ("/api/v1/accounts/" + user_id + "/following is called") + try { - try + ret = masto.get(API::v1::accounts_id_following, + { + { "id", { user_id } }, + { "limit", { "5" } } + }); + if (ret.answer == "[]") { - ret = masto.get(API::v1::accounts_id_following, - { - { "id", { user_id } }, - { "limit", { "5" } } - }); - if (ret.answer == "[]") - { - WARN("No followed found."); - } - username_found = - ret.answer.find("\"username\":\"") - != std::string::npos; + WARN("No followed found."); } - catch (const std::exception &e) + else { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("The answer makes sense") - { - REQUIRE(username_found); + account.from_string + (Easy::json_array_to_vector(ret.answer).front()); } } - } - - GIVEN ("Mastodon::Easy::API") - { - Mastodon::Easy::API masto(instance, access_token); - Easy::Account account; - - WHEN ("/api/v1/accounts/" + user_id + "/following is called") + catch (const std::exception &e) { - try - { - ret = masto.get(API::v1::accounts_id_following, - { - { "id", { user_id } }, - { "limit", { "5" } } - }); - if (ret.answer == "[]") - { - WARN("No followed found."); - } - else - { - account.from_string - (Easy::json_array_to_vector(ret.answer).front()); - } - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("Answer is valid") - { - REQUIRE(account.valid()); - } - THEN ("The answer makes sense") - { - REQUIRE(account.username() != ""); - } + exception = true; + WARN(e.what()); + } + + THEN("No exception is thrown") + AND_THEN ("No errors are returned") + AND_THEN ("Answer is valid") + AND_THEN ("The answer makes sense") + { + REQUIRE_FALSE(exception); + + REQUIRE(ret.error_code == 0); + REQUIRE(ret.http_error_code == 200); + + REQUIRE(account.valid()); + + REQUIRE(account.username() != ""); } } } diff --git a/tests/test_api_v1_accounts_id_statuses.cpp b/tests/test_api_v1_accounts_id_statuses.cpp index 4e852f8..ef738f6 100644 --- a/tests/test_api_v1_accounts_id_statuses.cpp +++ b/tests/test_api_v1_accounts_id_statuses.cpp @@ -27,111 +27,61 @@ using namespace Mastodon; SCENARIO ("/api/v1/accounts/:id/statuses can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("instance, access token, user id and return_call") - { - const char *env_instance = std::getenv("MASTODON_CPP_INSTANCE"); - const string instance = - (env_instance ? env_instance : "likeable.space"); - const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); - const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); - const string user_id = - (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + const char *env_instance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (env_instance ? env_instance : "likeable.space"); + const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); + const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); + const string user_id = (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + GIVEN ("instance = " + instance + ", user ID = " + user_id) + { + Mastodon::Easy::API masto(instance, access_token); return_call ret; + Easy::Status status; bool exception = false; - bool content_found = false; REQUIRE (access_token != nullptr); - GIVEN ("Mastodon::API") + WHEN ("/api/v1/accounts/" + user_id + "/statuses is called") { - Mastodon::API masto(instance, access_token); - - WHEN ("/api/v1/accounts/" + user_id + "/statuses is called") + try { - try + ret = masto.get(API::v1::accounts_id_statuses, + { + { "id", { user_id } }, + { "limit", { "5" } } + }); + if (ret.answer == "[]") { - ret = masto.get(API::v1::accounts_id_statuses, - { - { "id", { user_id } }, - { "limit", { "5" } } - }); - if (ret.answer == "[]") - { - WARN("No statuses found."); - } - content_found = - ret.answer.find("\"content\":\"") - != std::string::npos; + WARN("No statuses found."); } - catch (const std::exception &e) + else { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("The answer makes sense") - { - REQUIRE(content_found); + status.from_string + (Easy::json_array_to_vector(ret.answer).front()); } } - } - - GIVEN ("Mastodon::Easy::API") - { - Mastodon::Easy::API masto(instance, access_token); - Easy::Status status; - - WHEN ("/api/v1/accounts/" + user_id + "/statuses is called") + catch (const std::exception &e) { - try - { - ret = masto.get(API::v1::accounts_id_statuses, - { - { "id", { user_id } }, - { "limit", { "5" } } - }); - if (ret.answer == "[]") - { - WARN("No statuses found."); - } - else - { - status.from_string - (Easy::json_array_to_vector(ret.answer).front()); - } - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("Answer is valid") - { - REQUIRE(status.valid()); - } - THEN ("The answer makes sense") - { - REQUIRE(status.content() != ""); - } + exception = true; + WARN(e.what()); + } + + THEN("No exception is thrown") + AND_THEN ("No errors are returned") + AND_THEN ("Answer is valid") + AND_THEN ("The answer makes sense") + { + REQUIRE_FALSE(exception); + + REQUIRE(ret.error_code == 0); + REQUIRE(ret.http_error_code == 200); + + REQUIRE(status.valid()); + + REQUIRE(status.content() != ""); } } } } + diff --git a/tests/test_api_v1_accounts_id_unfollow.cpp b/tests/test_api_v1_accounts_id_unfollow.cpp index ca93503..9190fea 100644 --- a/tests/test_api_v1_accounts_id_unfollow.cpp +++ b/tests/test_api_v1_accounts_id_unfollow.cpp @@ -27,103 +27,50 @@ using namespace Mastodon; SCENARIO ("/api/v1/accounts/:id/unfollow can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("instance, access token, user id and return_call") + const char *env_instance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (env_instance ? env_instance : "likeable.space"); + const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); + const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); + const string user_id = (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + + GIVEN ("instance = " + instance + ", user ID = " + user_id) { - const char *env_instance = std::getenv("MASTODON_CPP_INSTANCE"); - const string instance = - (env_instance ? env_instance : "likeable.space"); - const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); - const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); - const string user_id = - (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); - + Mastodon::Easy::API masto(instance, access_token); return_call ret; + Easy::Relationship relationship; bool exception = false; - bool following_found = true; - bool error_found = false; - - // You can't unfollow yourself, so we look for errors too. REQUIRE (access_token != nullptr); - GIVEN ("Mastodon::API") + WHEN ("/api/v1/accounts/" + user_id + "/unfollow is called") { - Mastodon::API masto(instance, access_token); - - WHEN ("/api/v1/accounts/" + user_id + "/unfollow is called") + try { - try - { - ret = masto.post(API::v1::accounts_id_unfollow, - { - { "id", { user_id } }, - }); - following_found = - ret.answer.find("\"following\":\"") - != std::string::npos; - error_found = following_found = - ret.answer.find("\"error") - != std::string::npos; - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No unexpected errors are returned") - { - REQUIRE((ret.error_code == 0 - || ret.error_code == 111)); - REQUIRE((ret.http_error_code == 200 - || ret.http_error_code == 500)); - } - THEN ("The answer makes sense") - { - REQUIRE((!following_found || error_found)); - } + ret = masto.post(API::v1::accounts_id_unfollow, + { + { "id", { user_id } }, + }); + relationship.from_string(ret.answer); } - } - - GIVEN ("Mastodon::Easy::API") - { - Mastodon::Easy::API masto(instance, access_token); - Easy::Relationship relationship; - - WHEN ("/api/v1/accounts/" + user_id + "/unfollow is called") + catch (const std::exception &e) { - try - { - ret = masto.post(API::v1::accounts_id_unfollow, - { - { "id", { user_id } }, - }); - relationship.from_string(ret.answer); - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No unexpected errors are returned") - { - REQUIRE((ret.error_code == 0 - || ret.error_code == 111)); - REQUIRE((ret.http_error_code == 200 - || ret.http_error_code == 500)); - } - THEN ("The answer makes sense") - { - REQUIRE((!relationship.following() - || relationship.error() != "")); - } + exception = true; + WARN(e.what()); + } + THEN("No exception is thrown") + AND_THEN ("No unexpected errors are returned") + AND_THEN ("The answer makes sense") + { + REQUIRE_FALSE(exception); + + // You can't unfollow yourself, so we look for errors too. + REQUIRE((ret.error_code == 0 + || ret.error_code == 111)); + REQUIRE((ret.http_error_code == 200 + || ret.http_error_code == 500)); + + REQUIRE((!relationship.following() + || relationship.error() != "")); } } } diff --git a/tests/test_api_v1_accounts_relationships.cpp b/tests/test_api_v1_accounts_relationships.cpp index 79b94b7..2368650 100644 --- a/tests/test_api_v1_accounts_relationships.cpp +++ b/tests/test_api_v1_accounts_relationships.cpp @@ -27,108 +27,58 @@ using namespace Mastodon; SCENARIO ("/api/v1/accounts/relationships can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("instance, access token, user id and return_call") - { - const char *env_instance = std::getenv("MASTODON_CPP_INSTANCE"); - const string instance = - (env_instance ? env_instance : "likeable.space"); - const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); - const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); - const string user_id = - (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + const char *env_instance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (env_instance ? env_instance : "likeable.space"); + const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); + const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); + const string user_id = (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + GIVEN ("instance = " + instance + ", user ID = " + user_id) + { + Mastodon::Easy::API masto(instance, access_token); return_call ret; + Easy::Relationship relationship; bool exception = false; - bool id_found = false; REQUIRE (access_token != nullptr); - GIVEN ("Mastodon::API") + WHEN ("/api/v1/accounts/relationships is called") { - Mastodon::API masto(instance, access_token); - - WHEN ("/api/v1/accounts/relationships is called") + try { - try + ret = masto.get(API::v1::accounts_relationships, + { + { "id", { user_id } }, + }); + if (ret.answer == "[]") { - ret = masto.get(API::v1::accounts_relationships, - { - { "id", { user_id } }, - }); - if (ret.answer == "[]") - { - WARN("No relationships found."); - } - id_found = - ret.answer.find("\"id\":\"") - != std::string::npos; + WARN("No relationships found."); } - catch (const std::exception &e) + else { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("The answer makes sense") - { - REQUIRE(id_found); + relationship.from_string + (Easy::json_array_to_vector(ret.answer).front()); } } - } - - GIVEN ("Mastodon::Easy::API") - { - Mastodon::Easy::API masto(instance, access_token); - Easy::Relationship relationship; - - WHEN ("/api/v1/accounts/relationships is called") + catch (const std::exception &e) { - try - { - ret = masto.get(API::v1::accounts_relationships, - { - { "id", { user_id } }, - }); - if (ret.answer == "[]") - { - WARN("No relationships found."); - } - else - { - relationship.from_string - (Easy::json_array_to_vector(ret.answer).front()); - } - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("Answer is valid") - { - REQUIRE(relationship.valid()); - } - THEN ("The answer makes sense") - { - REQUIRE(relationship.id() != ""); - } + exception = true; + WARN(e.what()); + } + + THEN("No exception is thrown") + AND_THEN ("No errors are returned") + AND_THEN ("Answer is valid") + AND_THEN ("The answer makes sense") + { + REQUIRE_FALSE(exception); + + REQUIRE(ret.error_code == 0); + REQUIRE(ret.http_error_code == 200); + + REQUIRE(relationship.valid()); + + REQUIRE(relationship.id() != ""); } } } diff --git a/tests/test_api_v1_accounts_update_credentials.cpp b/tests/test_api_v1_accounts_update_credentials.cpp index c88a3d8..9791a14 100644 --- a/tests/test_api_v1_accounts_update_credentials.cpp +++ b/tests/test_api_v1_accounts_update_credentials.cpp @@ -27,87 +27,48 @@ using namespace Mastodon; SCENARIO ("/api/v1/accounts/update_credentials can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("instance, access token and return_call") + const char *envinstance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (envinstance ? envinstance : "likeable.space"); + const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); + const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); + const string user_id = (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + + GIVEN ("instance = " + instance + ", user ID = " + user_id) { - const char *envinstance = std::getenv("MASTODON_CPP_INSTANCE"); - const string instance = (envinstance ? envinstance : "likeable.space"); - const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); + Mastodon::Easy::API masto(instance, access_token); return_call ret; + Easy::Account account; bool exception = false; - bool display_name_found = false; REQUIRE (access_token != nullptr); - GIVEN ("Mastodon::API") + WHEN ("/api/v1/accounts/update_credentials is called") { - Mastodon::API masto(instance, access_token); - - WHEN ("/api/v1/accounts/update_credentials is called") + try { - try - { - ret = masto.patch(API::v1::accounts_update_credentials, - {{ "display_name", { "testaccount" } }}); - display_name_found = - ret.answer.find("\"display_name\":\"testaccount\"") - != std::string::npos; - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("The answer makes sense") - { - REQUIRE(display_name_found); - } + ret = masto.patch(API::v1::accounts_update_credentials, + {{ "display_name", { "testaccount" } }}); + account = Easy::Account(ret.answer); } - } - - GIVEN ("Mastodon::Easy::API") - { - Mastodon::Easy::API masto(instance, access_token); - Easy::Account account; - - WHEN ("/api/v1/accounts/update_credentials is called") + catch (const std::exception &e) { - try - { - ret = masto.patch(API::v1::accounts_update_credentials, - {{ "display_name", { "testaccount" } }}); - account = Easy::Account(ret.answer); - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("Answer is valid") - { - REQUIRE(account.valid()); - } - THEN ("The answer makes sense") - { - REQUIRE(account.display_name() == "testaccount"); - } + exception = true; + WARN(e.what()); + } + + THEN("No exception is thrown") + AND_THEN ("No errors are returned") + AND_THEN ("Answer is valid") + AND_THEN ("The answer makes sense") + { + REQUIRE_FALSE(exception); + + REQUIRE(ret.error_code == 0); + REQUIRE(ret.http_error_code == 200); + + REQUIRE(account.valid()); + + REQUIRE(account.id() == user_id); } } } diff --git a/tests/test_api_v1_accounts_verify_credentials.cpp b/tests/test_api_v1_accounts_verify_credentials.cpp index 188a0c5..3b83d13 100644 --- a/tests/test_api_v1_accounts_verify_credentials.cpp +++ b/tests/test_api_v1_accounts_verify_credentials.cpp @@ -27,85 +27,49 @@ using namespace Mastodon; SCENARIO ("/api/v1/accounts/verify_credentials can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("instance, access token and return_call") + const char *envinstance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (envinstance ? envinstance : "likeable.space"); + const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); + const char *env_user_id = std::getenv("MASTODON_CPP_USER_ID"); + const string user_id = (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo"); + + GIVEN ("instance = " + instance + ", user ID = " + user_id) { - const char *envinstance = std::getenv("MASTODON_CPP_INSTANCE"); - const string instance = (envinstance ? envinstance : "likeable.space"); - const char *access_token = std::getenv("MASTODON_CPP_ACCESS_TOKEN"); + Mastodon::Easy::API masto(instance, access_token); return_call ret; + Easy::Account account; bool exception = false; - bool username_found = false; REQUIRE (access_token != nullptr); - GIVEN ("Mastodon::API") + WHEN ("/api/v1/accounts/verify_credentials is called") { - Mastodon::API masto(instance, access_token); - - WHEN ("/api/v1/accounts/verify_credentials is called") + try { - try - { - ret = masto.get(API::v1::accounts_verify_credentials); - username_found = ret.answer.find( - "\"username\":\"testaccount\"") != std::string::npos; - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("The answer makes sense") - { - REQUIRE(username_found); - } + ret = masto.get(API::v1::accounts_verify_credentials); + account = Easy::Account(ret.answer); } - } - - GIVEN ("Mastodon::Easy::API") - { - Mastodon::Easy::API masto(instance, access_token); - Easy::Account account; - - WHEN ("/api/v1/accounts/verify_credentials is called") + catch (const std::exception &e) { - try - { - ret = masto.get(API::v1::accounts_verify_credentials); - account = Easy::Account(ret.answer); - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("Answer is valid") - { - REQUIRE(account.valid()); - } - THEN ("The answer makes sense") - { - REQUIRE(account.username() == "testaccount"); - } + exception = true; + WARN(e.what()); + } + + THEN("No exception is thrown") + AND_THEN ("No errors are returned") + AND_THEN ("Answer is valid") + AND_THEN ("The answer makes sense") + { + REQUIRE_FALSE(exception); + + REQUIRE(ret.error_code == 0); + REQUIRE(ret.http_error_code == 200); + + REQUIRE(account.valid()); + + REQUIRE(account.id() == user_id); } } } } + diff --git a/tests/test_api_v1_instance.cpp b/tests/test_api_v1_instance.cpp index c086974..3451de3 100644 --- a/tests/test_api_v1_instance.cpp +++ b/tests/test_api_v1_instance.cpp @@ -26,83 +26,43 @@ using namespace Mastodon; SCENARIO ("/api/v1/instance can be called successfully", "[api][mastodon][pleroma][glitch-soc]") { - GIVEN ("instance and return_call") + const char *envinstance = std::getenv("MASTODON_CPP_INSTANCE"); + const string instance = (envinstance ? envinstance : "likeable.space"); + GIVEN ("instance = " + instance) { - const char *envinstance = std::getenv("MASTODON_CPP_INSTANCE"); - const string instance = (envinstance ? envinstance : "likeable.space"); + Mastodon::Easy::API masto(instance, ""); return_call ret; + Easy::Instance instance_; bool exception = false; - GIVEN ("Mastodon::API") + WHEN ("/api/v1/instance is called") { - Mastodon::API masto(instance, ""); - bool uri_found = false; - - WHEN ("/api/v1/instance is called") + try { - try - { - ret = masto.get(API::v1::instance); - uri_found = - ret.answer.find("\"uri\":\"https://likeable.space\"") - != std::string::npos; - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("The answer makes sense") - { - REQUIRE(uri_found); - } + ret = masto.get(API::v1::instance); + instance_ = Easy::Instance(ret.answer); } - } - - GIVEN ("Mastodon::Easy::API") - { - Mastodon::Easy::API masto(instance, ""); - Easy::Instance instance_; - - WHEN ("/api/v1/instance is called") + catch (const std::exception &e) { - try - { - ret = masto.get(API::v1::instance); - instance_ = Easy::Instance(ret.answer); - } - catch (const std::exception &e) - { - exception = true; - WARN(e.what()); - } - THEN("No exception is thrown") - { - REQUIRE_FALSE(exception); - } - THEN ("No errors are returned") - { - REQUIRE(ret.error_code == 0); - REQUIRE(ret.http_error_code == 200); - } - THEN ("Answer is valid") - { - REQUIRE(instance_.valid()); - } - THEN ("The answer makes sense") - { - REQUIRE(instance_.uri() == "https://likeable.space"); - } + exception = true; + WARN(e.what()); + } + + THEN("No exception is thrown") + AND_THEN ("No errors are returned") + AND_THEN ("Answer is valid") + AND_THEN ("The answer makes sense") + { + REQUIRE_FALSE(exception); + + REQUIRE(ret.error_code == 0); + REQUIRE(ret.http_error_code == 200); + + REQUIRE(instance_.valid()); + + REQUIRE(instance_.uri() == ("https://" + instance)); } } } } + diff --git a/tests/test_basics.cpp b/tests/test_basics.cpp index 70571af..15d83b4 100644 --- a/tests/test_basics.cpp +++ b/tests/test_basics.cpp @@ -22,6 +22,7 @@ SCENARIO ("Instantiating API classes works") { bool exception = false; + WHEN ("Mastodon::API") { try @@ -32,6 +33,7 @@ SCENARIO ("Instantiating API classes works") { exception = true; } + THEN ("No exception is thrown") { REQUIRE_FALSE(exception); @@ -48,6 +50,7 @@ SCENARIO ("Instantiating API classes works") { exception = true; } + THEN ("No exception is thrown") { REQUIRE_FALSE(exception);