diff --git a/README.md b/README.md index 94cf003..9ef6eb5 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,8 @@ You can select the instance to use with `MASTODON_CPP_INSTANCE`, the default is *likeable.space*. You can select the user ID with `MASTODON_CPP_USER_ID`, the default is *9hnrrVPriLiLVAhfVo*. You can select the status ID with `MASTODON_CPP_STATUS_ID`, the default is *9hwnuJMq3eTdO4s1PU*. You can select -the filter ID with `MASTODON_CPP_FILTER_ID`. +the filter ID with `MASTODON_CPP_FILTER_ID`. You can select the list ID with +`MASTODON_CPP_LIST_ID`, the default is *1*. Requirements for the test-user: diff --git a/tests/environment_variables.hpp b/tests/environment_variables.hpp index 6519ab4..0f9e22c 100644 --- a/tests/environment_variables.hpp +++ b/tests/environment_variables.hpp @@ -31,5 +31,7 @@ extern const char *env_status_id; extern const string status_id; extern const char *env_filter_id; extern const string filter_id; +extern const char *env_list_id; +extern const string list_id; #endif // MASTODON_CPP_TEST_ENVIRONMENT_VARIABLES_HPP diff --git a/tests/main.cpp b/tests/main.cpp index 0c58a79..05966c9 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -33,3 +33,5 @@ const char *env_status_id = getenv("MASTODON_CPP_STATUS_ID"); const string status_id = (env_status_id ? env_status_id : "9hwnuJMq3eTdO4s1PU"); const char *env_filter_id = getenv("MASTODON_CPP_FILTER_ID"); const string filter_id = (env_filter_id ? env_filter_id : ""); +const char *env_list_id = getenv("MASTODON_CPP_LIST_ID"); +const string list_id = (env_list_id ? env_list_id : "1"); diff --git a/tests/test_api_v1_accounts_id_lists.cpp b/tests/test_api_v1_accounts_id_lists.cpp index e12166f..a6fb7bb 100644 --- a/tests/test_api_v1_accounts_id_lists.cpp +++ b/tests/test_api_v1_accounts_id_lists.cpp @@ -19,7 +19,6 @@ #include #include "mastodon-cpp.hpp" #include "easy/easy.hpp" -#include "easy/entities/list.hpp" #include "environment_variables.hpp" using namespace Mastodon; diff --git a/tests/test_api_v1_lists_id_accounts.cpp b/tests/test_api_v1_lists_id_accounts.cpp new file mode 100644 index 0000000..851452e --- /dev/null +++ b/tests/test_api_v1_lists_id_accounts.cpp @@ -0,0 +1,81 @@ +/* This file is part of mastodon-cpp. + * Copyright © 2019 tastytea + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include "mastodon-cpp.hpp" +#include "easy/easy.hpp" +#include "easy/entities/account.hpp" +#include "environment_variables.hpp" + +using namespace Mastodon; + +SCENARIO ("/api/v1/lists/:id/accounts can be called successfully", + "[api][mastodon][pleroma][glitch-soc]") +{ + REQUIRE (access_token != nullptr); + + GIVEN ("instance = " + instance + ", list ID = " + list_id) + { + Mastodon::Easy::API masto(instance, access_token); + return_call ret; + Easy::Account account; + bool exception = false; + + WHEN ("GET /api/v1/lists/" + list_id + "/accounts is called") + { + try + { + ret = masto.get(API::v1::lists_id_accounts, + { + { "id", { list_id }}, + { "limit", { "5" }} + }); + if (ret.answer == "[]") + { + WARN("No accounts 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") + 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() != ""); + } + } + } +} +