From a2aa33cf27d99cb375ecb8e5284dca38c485e627 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 25 Apr 2019 14:25:37 +0200 Subject: [PATCH] Added tests for API::v1::lists. --- README.md | 1 + src/easy/entities/list.cpp | 4 +- src/easy/entity.cpp | 2 +- tests/test_api_v1_lists.cpp | 76 +++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 tests/test_api_v1_lists.cpp diff --git a/README.md b/README.md index 6845196..94cf003 100644 --- a/README.md +++ b/README.md @@ -255,6 +255,7 @@ Requirements for the test-user: * Have at least 1 public or unlisted status. * Have at least 1 post favourited. * Have no follow requests. +* Have at least 1 list with at least one account in it. ### Packages diff --git a/src/easy/entities/list.cpp b/src/easy/entities/list.cpp index 8404015..19fc8a6 100644 --- a/src/easy/entities/list.cpp +++ b/src/easy/entities/list.cpp @@ -24,10 +24,10 @@ using std::uint64_t; bool List::valid() const { const std::vector attributes = - {{ + { "id", "title" - }}; + }; return Entity::check_valid(attributes); } diff --git a/src/easy/entity.cpp b/src/easy/entity.cpp index bee9bd9..6072044 100644 --- a/src/easy/entity.cpp +++ b/src/easy/entity.cpp @@ -100,7 +100,7 @@ const Json::Value Easy::Entity::to_object() const bool Easy::Entity::check_valid(const std::vector &attributes) const { - for (const string &attribute: attributes) + for (const string &attribute : attributes) { get(attribute); if (!was_set()) diff --git a/tests/test_api_v1_lists.cpp b/tests/test_api_v1_lists.cpp new file mode 100644 index 0000000..22e31a3 --- /dev/null +++ b/tests/test_api_v1_lists.cpp @@ -0,0 +1,76 @@ +/* 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/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() != ""); + } + } + } +} +