From f293d54a6389a254d95515a2ba0518834ce1564a Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 26 Jun 2019 02:14:52 +0200 Subject: [PATCH] Added tests for Easy::Notification. --- README.adoc | 2 +- tests/entities/test_notification.cpp | 88 ++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 tests/entities/test_notification.cpp diff --git a/README.adoc b/README.adoc index 98848b7..1e936e7 100644 --- a/README.adoc +++ b/README.adoc @@ -404,7 +404,7 @@ strings and you can use unsupported fields in an `Entity` by converting it to * [x] Instance * [x] List * [x] Mention -* [ ] Notification +* [x] Notification * [ ] Poll * [ ] PushSubscription * [ ] Relationship diff --git a/tests/entities/test_notification.cpp b/tests/entities/test_notification.cpp new file mode 100644 index 0000000..326fed6 --- /dev/null +++ b/tests/entities/test_notification.cpp @@ -0,0 +1,88 @@ +/* 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/notification.hpp" +#include "easy/easy.hpp" + +using std::string; +using std::chrono::system_clock; + +using namespace Mastodon; + +SCENARIO ("Easy::Notification works as intended", "[entity]") +{ + GIVEN ("An Easy::Notification object") + { + Easy::Notification notification; + bool exception = false; + + WHEN ("It is initialized with valid notification data") + { + const string data = + "{\"id\" : \"1234\"," + "\"type\" : \"follow\"," + "\"account\" : " + "{\"acct\" : \"testaccount@likeable.space\"}," + " \"created_at\" : \"2019-06-25T15:52:08.000Z\"}"; + + try + { + notification.from_string(data); + } + catch (const std::exception &e) + { + exception = true; + } + + THEN ("No exception is thrown") + AND_THEN ("Notification is valid") + AND_THEN ("The attributes are set to the right values") + { + REQUIRE_FALSE(exception); + REQUIRE(notification.valid()); + REQUIRE(notification.id() == "1234"); + REQUIRE(notification.type() == Easy::notification_type::Follow); + REQUIRE(notification.account().acct() == + "testaccount@likeable.space"); + } + } + + WHEN ("It is initialized with an empty string") + { + try + { + notification.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(notification.valid()); + REQUIRE(notification.id() == ""); + } + } + } +}