|
@@ -2,6 +2,7 @@
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
#include "../include/JsonCommander.h"
|
|
|
+#include "../include/Notifications.h"
|
|
|
#include "FileManagerMock.h"
|
|
|
|
|
|
namespace {
|
|
@@ -1196,4 +1197,118 @@ TEST(DeleteFile, DisabledInConfig) {
|
|
|
EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
|
|
|
}
|
|
|
|
|
|
+TEST(Notifications, NoMessage) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "notifications";
|
|
|
+
|
|
|
+ Notifications::messages.clear();
|
|
|
+ Notifications::userTimeStamps.clear();
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["error"].asString(), "");
|
|
|
+ EXPECT_TRUE(response.json["messages"].isNull());
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Notifications, OneMessage) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "notifications";
|
|
|
+
|
|
|
+ Notifications::messages.clear();
|
|
|
+ Notifications::userTimeStamps.clear();
|
|
|
+ Notifications::newNotification("asdf");
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["error"].asString(), "");
|
|
|
+ EXPECT_TRUE(response.json["messages"].isArray());
|
|
|
+ EXPECT_EQ(response.json["messages"][0], "asdf");
|
|
|
+
|
|
|
+ // cleaning up
|
|
|
+ Notifications::messages.clear();
|
|
|
+ Notifications::userTimeStamps.clear();
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Notifications, OneMessageMultipleTimesCalled) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "notifications";
|
|
|
+
|
|
|
+ Notifications::messages.clear();
|
|
|
+ Notifications::userTimeStamps.clear();
|
|
|
+ Notifications::newNotification("asdf");
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["error"].asString(), "");
|
|
|
+ EXPECT_TRUE(response.json["messages"].isArray());
|
|
|
+ EXPECT_EQ(response.json["messages"][0], "asdf");
|
|
|
+
|
|
|
+ // make suhre that timestamp from message is older
|
|
|
+ Notifications::messages.at(0).first--;
|
|
|
+
|
|
|
+ response = jsonCommander.execute(message);
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["error"].asString(), "");
|
|
|
+ EXPECT_TRUE(response.json["messages"].isNull());
|
|
|
+
|
|
|
+ // cleaning up
|
|
|
+ Notifications::messages.clear();
|
|
|
+ Notifications::userTimeStamps.clear();
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Notifications, TwoMessages) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "notifications";
|
|
|
+
|
|
|
+ Notifications::messages.clear();
|
|
|
+ Notifications::userTimeStamps.clear();
|
|
|
+ Notifications::newNotification("asdf");
|
|
|
+ Notifications::newNotification("qwer");
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["error"].asString(), "");
|
|
|
+ EXPECT_TRUE(response.json["messages"].isArray());
|
|
|
+ EXPECT_EQ(response.json["messages"][0], "asdf");
|
|
|
+ EXPECT_EQ(response.json["messages"][1], "qwer");
|
|
|
+
|
|
|
+ // cleaning up
|
|
|
+ Notifications::messages.clear();
|
|
|
+ Notifications::userTimeStamps.clear();
|
|
|
+}
|
|
|
+
|
|
|
} // namespace
|