diff --git a/README.md b/README.md index 9e5f080..20ace4b 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/tests/environment_variables.hpp b/tests/environment_variables.hpp index b574bd5..86fcf4d 100644 --- a/tests/environment_variables.hpp +++ b/tests/environment_variables.hpp @@ -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 diff --git a/tests/main.cpp b/tests/main.cpp index b8fc3fd..51a8225 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -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"); diff --git a/tests/test_api_v1_statuses_id_favourite.cpp b/tests/test_api_v1_statuses_id_favourite.cpp new file mode 100644 index 0000000..79a6cc5 --- /dev/null +++ b/tests/test_api_v1_statuses_id_favourite.cpp @@ -0,0 +1,69 @@ +/* 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/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); + } + } + } +}