From d9fa8781363310dd03c65d5dc9aafd1757bd1c63 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 21 Jul 2019 02:33:52 +0200 Subject: [PATCH] Added tests for Easy::PushSubscription. --- README.adoc | 2 +- tests/entities/test_pushsubscription.cpp | 87 ++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 tests/entities/test_pushsubscription.cpp diff --git a/README.adoc b/README.adoc index c7e953f..92cae52 100644 --- a/README.adoc +++ b/README.adoc @@ -406,7 +406,7 @@ strings and you can use unsupported fields in an `Entity` by converting it to * [x] Mention * [x] Notification * [ ] Poll -* [ ] PushSubscription +* [x] PushSubscription * [ ] Relationship * [ ] Report ^(Deprecated)^ * [ ] Results diff --git a/tests/entities/test_pushsubscription.cpp b/tests/entities/test_pushsubscription.cpp new file mode 100644 index 0000000..72413b3 --- /dev/null +++ b/tests/entities/test_pushsubscription.cpp @@ -0,0 +1,87 @@ +/* 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 +#include "easy/entities/pushsubscription.hpp" +#include "easy/easy.hpp" + +using std::string; +using std::chrono::system_clock; + +using namespace Mastodon; + +SCENARIO ("Easy::PushSubscription works as intended", "[entity]") +{ + GIVEN ("An Easy::PushSubscription object") + { + Easy::PushSubscription pushsubscription; + bool exception = false; + + WHEN ("It is initialized with valid pushsubscription data") + { + const string data = + "{\"id\":\"1234\"," + "\"endpoint\":\"https://example.org/test\"," + "\"server_key\":\"1234\"," + "\"alerts\":{\"mention\":true}}"; + + try + { + pushsubscription.from_string(data); + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + AND_THEN ("PushSubscription is valid") + AND_THEN ("The attributes are set to the right values") + { + REQUIRE_FALSE(exception); + REQUIRE(pushsubscription.valid()); + REQUIRE(pushsubscription.id() == "1234"); + REQUIRE(pushsubscription.endpoint() == "https://example.org/test"); + REQUIRE(pushsubscription.server_key() == "1234"); + REQUIRE(pushsubscription.alerts()[0].type == Easy::notification_type::Mention); + } + } + + WHEN ("It is initialized with an empty string") + { + try + { + pushsubscription.from_string(""); + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + AND_THEN ("It is not valid") + AND_THEN ("id is empty") + { + REQUIRE_FALSE(exception); + REQUIRE_FALSE(pushsubscription.valid()); + REQUIRE(pushsubscription.id() == ""); + } + } + } +}