Added tests for API::v1::lists.
the build was successful
Details
the build was successful
Details
This commit is contained in:
parent
c3cdf6233a
commit
a2aa33cf27
|
@ -255,6 +255,7 @@ Requirements for the test-user:
|
||||||
* Have at least 1 public or unlisted status.
|
* Have at least 1 public or unlisted status.
|
||||||
* Have at least 1 post favourited.
|
* Have at least 1 post favourited.
|
||||||
* Have no follow requests.
|
* Have no follow requests.
|
||||||
|
* Have at least 1 list with at least one account in it.
|
||||||
|
|
||||||
### Packages
|
### Packages
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,10 @@ using std::uint64_t;
|
||||||
bool List::valid() const
|
bool List::valid() const
|
||||||
{
|
{
|
||||||
const std::vector<string> attributes =
|
const std::vector<string> attributes =
|
||||||
{{
|
{
|
||||||
"id",
|
"id",
|
||||||
"title"
|
"title"
|
||||||
}};
|
};
|
||||||
|
|
||||||
return Entity::check_valid(attributes);
|
return Entity::check_valid(attributes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ const Json::Value Easy::Entity::to_object() const
|
||||||
|
|
||||||
bool Easy::Entity::check_valid(const std::vector<string> &attributes) const
|
bool Easy::Entity::check_valid(const std::vector<string> &attributes) const
|
||||||
{
|
{
|
||||||
for (const string &attribute: attributes)
|
for (const string &attribute : attributes)
|
||||||
{
|
{
|
||||||
get(attribute);
|
get(attribute);
|
||||||
if (!was_set())
|
if (!was_set())
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
/* 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/list.hpp"
|
||||||
|
#include "environment_variables.hpp"
|
||||||
|
|
||||||
|
using namespace Mastodon;
|
||||||
|
|
||||||
|
SCENARIO ("/api/v1/lists can be called successfully",
|
||||||
|
"[api][mastodon][pleroma][glitch-soc]")
|
||||||
|
{
|
||||||
|
REQUIRE (access_token != nullptr);
|
||||||
|
|
||||||
|
GIVEN ("instance = " + instance)
|
||||||
|
{
|
||||||
|
Mastodon::Easy::API masto(instance, access_token);
|
||||||
|
return_call ret;
|
||||||
|
Easy::List list;
|
||||||
|
bool exception = false;
|
||||||
|
|
||||||
|
WHEN ("GET /api/v1/lists is called")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ret = masto.get(API::v1::lists);
|
||||||
|
if (ret.answer == "[]")
|
||||||
|
{
|
||||||
|
WARN("No favourites found.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list.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(list.valid());
|
||||||
|
|
||||||
|
REQUIRE(list.id() != "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Reference in New Issue