Added tests for API::v1::statuses_id_favourite.

This commit is contained in:
tastytea 2019-04-19 01:58:57 +02:00
parent 5e721af0a1
commit 887b77d334
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
4 changed files with 75 additions and 1 deletions

View File

@ -218,7 +218,8 @@ the environment variable `MASTODON_CPP_ACCESS_TOKEN` to an access token with the
scopes *read*, *write* and *follow* for some tests.
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*.
default is *9hnrrVPriLiLVAhfVo*. You can select the status ID with
`MASTODON_CPP_STATUS_ID`, the default is *9hwnuJMq3eTdO4s1PU*.
Requirements for the test-user:

View File

@ -27,5 +27,7 @@ extern const string instance;
extern const char *access_token;
extern const char *env_user_id;
extern const string user_id;
extern const char *env_status_id;
extern const string status_id;
#endif // MASTODON_CPP_TEST_ENVIRONMENT_VARIABLES_HPP

View File

@ -29,3 +29,5 @@ const string instance = (env_instance ? env_instance : "likeable.space");
const char *access_token = getenv("MASTODON_CPP_ACCESS_TOKEN");
const char *env_user_id = getenv("MASTODON_CPP_USER_ID");
const string user_id = (env_user_id ? env_user_id : "9hnrrVPriLiLVAhfVo");
const char *env_status_id = getenv("MASTODON_CPP_STATUS_ID");
const string status_id = (env_status_id ? env_status_id : "9hwnuJMq3eTdO4s1PU");

View File

@ -0,0 +1,69 @@
/* 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/status.hpp"
#include "environment_variables.hpp"
using namespace Mastodon;
SCENARIO ("/api/v1/accounts/:id/favourite can be called successfully",
"[api][mastodon][pleroma][glitch-soc]")
{
REQUIRE (access_token != nullptr);
GIVEN ("instance = " + instance + ", status ID = " + status_id)
{
Mastodon::Easy::API masto(instance, access_token);
return_call ret;
Easy::Status status;
bool exception = false;
WHEN ("POST /api/v1/accounts/" + status_id + "/favourite is called")
{
try
{
ret = masto.post(API::v1::statuses_id_favourite,
{
{ "id", { status_id } },
});
status.from_string(ret.answer);
}
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(status.favourited() == true);
}
}
}
}