2022-05-07 17:22:39 +02:00
|
|
|
#include "providers/twitch/PubSubActions.hpp"
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "providers/twitch/PubSubClient.hpp"
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "providers/twitch/PubSubManager.hpp"
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "providers/twitch/pubsubmessages/AutoMod.hpp"
|
|
|
|
#include "providers/twitch/pubsubmessages/Whisper.hpp"
|
2024-01-06 13:18:37 +01:00
|
|
|
#include "providers/twitch/TwitchAccount.hpp"
|
2023-08-27 14:07:46 +02:00
|
|
|
#include "TestHelpers.hpp"
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
2022-12-31 15:41:01 +01:00
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
#include <chrono>
|
2023-08-27 14:07:46 +02:00
|
|
|
#include <optional>
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
using namespace chatterino;
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Server behaves normally and responds to pings (COMPLETE)
|
|
|
|
* Server doesn't respond to pings, client should disconnect (COMPLETE)
|
|
|
|
* Server randomly disconnects us, we should reconnect (COMPLETE)
|
|
|
|
* Client listens to more than 50 topics, so it opens 2 connections (COMPLETE)
|
|
|
|
* Server sends RECONNECT message to us, we should reconnect (INCOMPLETE, leaving for now since if we just ignore it and Twitch disconnects us we should already handle it properly)
|
|
|
|
* Listen that required authentication, but authentication is missing (COMPLETE)
|
|
|
|
* Listen that required authentication, but authentication is wrong (COMPLETE)
|
|
|
|
* Incoming Whisper message (COMPLETE)
|
|
|
|
* Incoming AutoMod message
|
|
|
|
* Incoming ChannelPoints message
|
|
|
|
* Incoming ChatModeratorAction message (COMPLETE)
|
|
|
|
**/
|
|
|
|
|
|
|
|
#define RUN_PUBSUB_TESTS
|
|
|
|
|
|
|
|
#ifdef RUN_PUBSUB_TESTS
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
class FTest : public PubSub
|
|
|
|
{
|
|
|
|
public:
|
2024-01-06 13:18:37 +01:00
|
|
|
explicit FTest(const char *path, std::chrono::seconds pingInterval,
|
|
|
|
QString token = "token")
|
2023-08-27 14:07:46 +02:00
|
|
|
: PubSub(QString("wss://127.0.0.1:9050%1").arg(path), pingInterval)
|
|
|
|
{
|
2024-01-06 13:18:37 +01:00
|
|
|
auto account = std::make_shared<TwitchAccount>("testaccount_420", token,
|
|
|
|
"clientid", "123456");
|
|
|
|
this->setAccount(account);
|
2023-08-27 14:07:46 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-05-07 17:22:39 +02:00
|
|
|
TEST(TwitchPubSubClient, ServerRespondsToPings)
|
|
|
|
{
|
2023-08-27 14:07:46 +02:00
|
|
|
FTest pubSub("", 1s);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.start();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
std::this_thread::sleep_for(50ms);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2024-01-06 13:18:37 +01:00
|
|
|
pubSub.listenToChannelModerationActions("123456");
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-05-26 14:54:23 +02:00
|
|
|
std::this_thread::sleep_for(150ms);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.listenResponses, 1);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
std::this_thread::sleep_for(2s);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 4);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.stop();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 4);
|
|
|
|
ASSERT_EQ(pubSub.diag.listenResponses, 1);
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TwitchPubSubClient, ServerDoesntRespondToPings)
|
|
|
|
{
|
2023-08-27 14:07:46 +02:00
|
|
|
FTest pubSub("/dont-respond-to-ping", 1s);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.start();
|
2024-01-06 13:18:37 +01:00
|
|
|
pubSub.listenToChannelModerationActions("123456");
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
std::this_thread::sleep_for(750ms);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 1);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
std::this_thread::sleep_for(500ms);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 2);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.stop();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 2);
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TwitchPubSubClient, DisconnectedAfter1s)
|
|
|
|
{
|
2023-08-27 14:07:46 +02:00
|
|
|
FTest pubSub("/disconnect-client-after-1s", 10s);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.start();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
std::this_thread::sleep_for(50ms);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.listenResponses, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2024-01-06 13:18:37 +01:00
|
|
|
pubSub.listenToChannelModerationActions("123456");
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
std::this_thread::sleep_for(500ms);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 2); // Listen RESPONSE & Pong
|
|
|
|
ASSERT_EQ(pubSub.diag.listenResponses, 1);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
std::this_thread::sleep_for(350ms);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 2);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
std::this_thread::sleep_for(600ms);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.listenResponses, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 4); // new listen & new pong
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.stop();
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TwitchPubSubClient, ExceedTopicLimit)
|
|
|
|
{
|
2023-08-27 14:07:46 +02:00
|
|
|
FTest pubSub("", 1s);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.start();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
for (auto i = 0; i < PubSubClient::MAX_LISTENS; ++i)
|
|
|
|
{
|
2024-01-06 13:18:37 +01:00
|
|
|
pubSub.listenToChannelModerationActions(QString("1%1").arg(i));
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(50ms);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
for (auto i = 0; i < PubSubClient::MAX_LISTENS; ++i)
|
|
|
|
{
|
2024-01-06 13:18:37 +01:00
|
|
|
pubSub.listenToChannelModerationActions(QString("2%1").arg(i));
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(50ms);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.stop();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TwitchPubSubClient, ExceedTopicLimitSingleStep)
|
|
|
|
{
|
2023-08-27 14:07:46 +02:00
|
|
|
FTest pubSub("", 1s);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.start();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
for (auto i = 0; i < PubSubClient::MAX_LISTENS * 2; ++i)
|
|
|
|
{
|
2024-01-06 13:18:37 +01:00
|
|
|
pubSub.listenToChannelModerationActions("123456");
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
2023-05-26 14:54:23 +02:00
|
|
|
std::this_thread::sleep_for(150ms);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.stop();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TwitchPubSubClient, ReceivedWhisper)
|
|
|
|
{
|
2023-08-27 14:07:46 +02:00
|
|
|
FTest pubSub("/receive-whisper", 1s);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.start();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ReceivedMessage<PubSubWhisperMessage> aReceivedWhisper;
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2024-01-06 13:18:37 +01:00
|
|
|
std::ignore = pubSub.whisper.received.connect(
|
2023-08-27 14:07:46 +02:00
|
|
|
[&aReceivedWhisper](const auto &whisperMessage) {
|
|
|
|
aReceivedWhisper = whisperMessage;
|
2022-05-07 17:22:39 +02:00
|
|
|
});
|
|
|
|
|
2024-01-06 13:18:37 +01:00
|
|
|
pubSub.listenToWhispers();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-05-26 14:54:23 +02:00
|
|
|
std::this_thread::sleep_for(150ms);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 3);
|
|
|
|
ASSERT_EQ(pubSub.diag.listenResponses, 1);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_TRUE(aReceivedWhisper);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(aReceivedWhisper->body, QString("me Kappa"));
|
|
|
|
ASSERT_EQ(aReceivedWhisper->fromUserLogin, QString("pajbot"));
|
|
|
|
ASSERT_EQ(aReceivedWhisper->fromUserID, QString("82008718"));
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.stop();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TwitchPubSubClient, ModeratorActionsUserBanned)
|
|
|
|
{
|
2023-08-27 14:07:46 +02:00
|
|
|
FTest pubSub("/moderator-actions-user-banned", 1s);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.start();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ReceivedMessage<BanAction> received;
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2024-01-06 13:18:37 +01:00
|
|
|
std::ignore =
|
|
|
|
pubSub.moderation.userBanned.connect([&received](const auto &action) {
|
2023-08-27 14:07:46 +02:00
|
|
|
received = action;
|
2022-05-07 17:22:39 +02:00
|
|
|
});
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.listenResponses, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2024-01-06 13:18:37 +01:00
|
|
|
pubSub.listenToChannelModerationActions("123456");
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
std::this_thread::sleep_for(50ms);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 3);
|
|
|
|
ASSERT_EQ(pubSub.diag.listenResponses, 1);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_TRUE(received);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
ActionUser expectedTarget{"140114344", "1xelerate", "", QColor()};
|
|
|
|
ActionUser expectedSource{"117691339", "mm2pl", "", QColor()};
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(received->reason, QString());
|
|
|
|
ASSERT_EQ(received->duration, 0);
|
|
|
|
ASSERT_EQ(received->target, expectedTarget);
|
|
|
|
ASSERT_EQ(received->source, expectedSource);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.stop();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TwitchPubSubClient, MissingToken)
|
|
|
|
{
|
|
|
|
// The token that's required is "xD"
|
2024-01-06 13:18:37 +01:00
|
|
|
FTest pubSub("/authentication-required", 1s, "");
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.start();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2024-01-06 13:18:37 +01:00
|
|
|
pubSub.listenToChannelModerationActions("123456");
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-05-26 14:54:23 +02:00
|
|
|
std::this_thread::sleep_for(150ms);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.listenResponses, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.failedListenResponses, 1);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.stop();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TwitchPubSubClient, WrongToken)
|
|
|
|
{
|
|
|
|
// The token that's required is "xD"
|
2023-08-27 14:07:46 +02:00
|
|
|
FTest pubSub("/authentication-required", 1s);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.start();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2024-01-06 13:18:37 +01:00
|
|
|
pubSub.listenToChannelModerationActions("123456");
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
std::this_thread::sleep_for(50ms);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.listenResponses, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.failedListenResponses, 1);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.stop();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TwitchPubSubClient, CorrectToken)
|
|
|
|
{
|
|
|
|
// The token that's required is "xD"
|
2024-01-06 13:18:37 +01:00
|
|
|
FTest pubSub("/authentication-required", 1s, "xD");
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.start();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2024-01-06 13:18:37 +01:00
|
|
|
pubSub.listenToChannelModerationActions("123456");
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
std::this_thread::sleep_for(50ms);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 2);
|
|
|
|
ASSERT_EQ(pubSub.diag.listenResponses, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.failedListenResponses, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.stop();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TwitchPubSubClient, AutoModMessageHeld)
|
|
|
|
{
|
2023-08-27 14:07:46 +02:00
|
|
|
FTest pubSub("/automod-held", 1s);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.start();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ReceivedMessage<PubSubAutoModQueueMessage> received;
|
|
|
|
ReceivedMessage<QString> channelID;
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2024-01-06 13:18:37 +01:00
|
|
|
std::ignore = pubSub.moderation.autoModMessageCaught.connect(
|
2023-08-27 14:07:46 +02:00
|
|
|
[&](const auto &msg, const QString &incomingChannelID) {
|
|
|
|
received = msg;
|
|
|
|
channelID = incomingChannelID;
|
2022-05-07 17:22:39 +02:00
|
|
|
});
|
|
|
|
|
2024-01-06 13:18:37 +01:00
|
|
|
pubSub.listenToAutomod("117166826");
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
std::this_thread::sleep_for(50ms);
|
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
|
|
|
ASSERT_EQ(pubSub.diag.messagesReceived, 3);
|
|
|
|
ASSERT_EQ(pubSub.diag.listenResponses, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.failedListenResponses, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_TRUE(received);
|
|
|
|
ASSERT_TRUE(channelID);
|
2022-05-07 17:22:39 +02:00
|
|
|
|
|
|
|
ASSERT_EQ(channelID, "117166826");
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(received->messageText, "kurwa");
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
pubSub.stop();
|
2022-05-07 17:22:39 +02:00
|
|
|
|
2023-08-27 14:07:46 +02:00
|
|
|
ASSERT_EQ(pubSub.diag.connectionsOpened, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsClosed, 1);
|
|
|
|
ASSERT_EQ(pubSub.diag.connectionsFailed, 0);
|
2022-05-07 17:22:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|