From 8b3eaf1e73aae8c9ebb5edb8fb54d5dc0708a13b Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 25 Apr 2019 17:25:39 +0200 Subject: [PATCH] Added tests for PUT and DELETE to API::v1::lists_id. --- README.md | 2 +- tests/main.cpp | 2 +- tests/test_api_v1_lists_id.cpp | 56 ++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9ef6eb5..85e2945 100644 --- a/README.md +++ b/README.md @@ -246,7 +246,7 @@ You can select the instance to use with `MASTODON_CPP_INSTANCE`, the default is default is *9hnrrVPriLiLVAhfVo*. You can select the status ID with `MASTODON_CPP_STATUS_ID`, the default is *9hwnuJMq3eTdO4s1PU*. You can select the filter ID with `MASTODON_CPP_FILTER_ID`. You can select the list ID with -`MASTODON_CPP_LIST_ID`, the default is *1*. +`MASTODON_CPP_LIST_ID`, the default is *2*. Requirements for the test-user: diff --git a/tests/main.cpp b/tests/main.cpp index 05966c9..d342ad1 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -34,4 +34,4 @@ const string status_id = (env_status_id ? env_status_id : "9hwnuJMq3eTdO4s1PU"); const char *env_filter_id = getenv("MASTODON_CPP_FILTER_ID"); const string filter_id = (env_filter_id ? env_filter_id : ""); const char *env_list_id = getenv("MASTODON_CPP_LIST_ID"); -const string list_id = (env_list_id ? env_list_id : "1"); +const string list_id = (env_list_id ? env_list_id : "2"); diff --git a/tests/test_api_v1_lists_id.cpp b/tests/test_api_v1_lists_id.cpp index e9a4c34..5b054b9 100644 --- a/tests/test_api_v1_lists_id.cpp +++ b/tests/test_api_v1_lists_id.cpp @@ -65,6 +65,62 @@ SCENARIO ("/api/v1/lists/:id can be called successfully", REQUIRE(list.id() == list_id); } } + + WHEN ("PUT /api/v1/lists/" + list_id + " is called") + { + try + { + ret = masto.put(API::v1::lists_id, + { + { "id", { list_id }}, + { "title", { "testlist" }} + }); + list.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(list.valid()); + + REQUIRE(list.title() == "testlist"); + } + } + + WHEN ("DELETE /api/v1/lists/donotdelete is called") + { + try + { + ret = masto.del(API::v1::lists_id, + {{ "id", { "donotdelete" }}}); + } + catch (const std::exception &e) + { + exception = true; + WARN(e.what()); + } + + THEN("No exception is thrown") + AND_THEN ("No unexpected errors are returned") + { + REQUIRE_FALSE(exception); + + REQUIRE(ret.error_code == 111); + REQUIRE(ret.http_error_code == 400); + } + } } }