Added /api/v1/polls/:id and /api/v1/polls/:id/votes.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
416675a667
commit
1b514df555
@ -343,8 +343,8 @@ strings and you can use unsupported fields in an `Entity` by converting it to
|
||||
** [x] PUT /api/v1/push/subscription
|
||||
** [x] DELETE /api/v1/push/subscription
|
||||
* Polls
|
||||
** [ ] GET /api/v1/polls/:id
|
||||
** [ ] POST /api/v1/polls/:id/votes
|
||||
** [x] GET /api/v1/polls/:id
|
||||
** [x] POST /api/v1/polls/:id/votes
|
||||
* Reports
|
||||
** [x] GET /api/v1/reports ^(Deprecated)^
|
||||
** [x] POST /api/v1/reports
|
||||
|
@ -231,6 +231,11 @@ const return_call API::get(const Mastodon::API::v1 &call,
|
||||
strcall = "/api/v1/suggestions";
|
||||
break;
|
||||
}
|
||||
case v1::polls_id:
|
||||
{
|
||||
strcall = "/api/v1/polls/" + strid;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
ttdebug << "ERROR: Invalid argument.\n";
|
||||
|
@ -195,6 +195,11 @@ return_call API::post(const Mastodon::API::v1 &call,
|
||||
strcall = "/api/v1/filters";
|
||||
break;
|
||||
}
|
||||
case v1::polls_id_votes:
|
||||
{
|
||||
strcall = "/api/v1/polls/" + strid + "/votes";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
ttdebug << "ERROR: Invalid argument.\n";
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "easy/entities/token.hpp"
|
||||
#include "easy/entities/pushsubscription.hpp"
|
||||
#include "easy/entities/filter.hpp"
|
||||
#include "easy/entities/poll.hpp"
|
||||
|
||||
using namespace Mastodon;
|
||||
|
||||
@ -92,6 +93,7 @@ template struct Easy::return_entity<Easy::Tag>;
|
||||
template struct Easy::return_entity<Easy::Token>;
|
||||
template struct Easy::return_entity<Easy::PushSubscription>;
|
||||
template struct Easy::return_entity<Easy::Filter>;
|
||||
template struct Easy::return_entity<Easy::Poll>;
|
||||
|
||||
|
||||
template<typename T>
|
||||
|
@ -244,8 +244,8 @@ namespace Mastodon
|
||||
notifications_dismiss,
|
||||
push_subscription,
|
||||
|
||||
// polls_id,
|
||||
// polls_id_votes,
|
||||
polls_id,
|
||||
polls_id_votes,
|
||||
|
||||
reports,
|
||||
|
||||
|
76
tests/api/test_api_v1_polls_id.cpp
Normal file
76
tests/api/test_api_v1_polls_id.cpp
Normal file
@ -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 Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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/poll.hpp"
|
||||
#include "../environment_variables.hpp"
|
||||
|
||||
using namespace Mastodon;
|
||||
|
||||
SCENARIO ("/api/v1/polls/:id can be called successfully",
|
||||
"[api][auth][mastodon][pleroma][glitch-soc]")
|
||||
{
|
||||
REQUIRE (access_token != nullptr);
|
||||
|
||||
GIVEN ("instance = " + instance)
|
||||
{
|
||||
Mastodon::Easy::API masto(instance, access_token);
|
||||
return_call ret;
|
||||
Easy::Poll poll;
|
||||
bool exception = false;
|
||||
|
||||
WHEN ("GET /api/v1/polls/:id is called")
|
||||
{
|
||||
try
|
||||
{
|
||||
ret = masto.get(API::v1::polls_id,
|
||||
{{ "id", { "4823515" } }});
|
||||
if (ret.answer == "[]")
|
||||
{
|
||||
WARN("Poll not found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
poll.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(poll.valid());
|
||||
|
||||
REQUIRE(poll.id() != "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
80
tests/api/test_api_v1_polls_id_votes.cpp
Normal file
80
tests/api/test_api_v1_polls_id_votes.cpp
Normal file
@ -0,0 +1,80 @@
|
||||
/* 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 Affero 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero 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/poll.hpp"
|
||||
#include "../environment_variables.hpp"
|
||||
|
||||
using namespace Mastodon;
|
||||
|
||||
SCENARIO ("/api/v1/polls/:id/votes can be called successfully",
|
||||
"[api][auth][mastodon][pleroma][glitch-soc]")
|
||||
{
|
||||
REQUIRE (access_token != nullptr);
|
||||
|
||||
GIVEN ("instance = " + instance)
|
||||
{
|
||||
Mastodon::Easy::API masto(instance, access_token);
|
||||
return_call ret;
|
||||
Easy::Poll poll;
|
||||
bool exception = false;
|
||||
|
||||
WHEN ("POST /api/v1/polls/:id/votes is called")
|
||||
{
|
||||
try
|
||||
{
|
||||
ret = masto.post(API::v1::polls_id_votes,
|
||||
{
|
||||
{ "id", { "4823515" } },
|
||||
// TODO: Check if this is the right format.
|
||||
{ "choices", { "false", "false", "true",
|
||||
"false", "false" } }
|
||||
});
|
||||
if (ret.answer == "[]")
|
||||
{
|
||||
WARN("Poll not found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
poll.from_string(ret.answer);
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
exception = true;
|
||||
WARN(e.what());
|
||||
}
|
||||
|
||||
THEN("No exception is thrown")
|
||||
AND_THEN ("An error is returned")
|
||||
AND_THEN ("Answer is invalid")
|
||||
{
|
||||
REQUIRE_FALSE(exception);
|
||||
|
||||
REQUIRE(ret.error_code == 12);
|
||||
REQUIRE(ret.http_error_code != 200); // Pleroma returns 422.
|
||||
REQUIRE_FALSE(poll.valid());
|
||||
REQUIRE(poll.id() == "");
|
||||
REQUIRE(poll.error() == "Poll's author can't vote");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user