Added tests for API::v1::lists_id_accounts.

This commit is contained in:
tastytea 2019-04-25 15:39:50 +02:00
parent 91ef34faa4
commit e9ac12efe3
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
5 changed files with 87 additions and 2 deletions

View File

@ -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:

View File

@ -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

View File

@ -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");

View File

@ -19,7 +19,6 @@
#include <catch.hpp>
#include "mastodon-cpp.hpp"
#include "easy/easy.hpp"
#include "easy/entities/list.hpp"
#include "environment_variables.hpp"
using namespace Mastodon;

View File

@ -0,0 +1,81 @@
/* This file is part of mastodon-cpp.
* Copyright © 2019 tastytea <tastytea@tastytea.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <exception>
#include <string>
#include <catch.hpp>
#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() != "");
}
}
}
}