feat: add snapshot tests for eventsub messages (#5965)

This commit is contained in:
nerix
2025-02-21 21:33:29 +01:00
committed by GitHub
parent bb4c6d6f6e
commit a86df7087d
17 changed files with 885 additions and 21 deletions
+2
View File
@@ -27,6 +27,7 @@
#include <unordered_map>
class TestIrcMessageHandlerP;
class TestEventSubMessagesP;
namespace chatterino {
@@ -514,6 +515,7 @@ private:
friend class IrcMessageHandler;
friend class Commands_E2E_Test;
friend class ::TestIrcMessageHandlerP;
friend class ::TestEventSubMessagesP;
};
} // namespace chatterino
+3 -14
View File
@@ -27,6 +27,7 @@
#include "singletons/WindowManager.hpp"
#include "util/PostToThread.hpp"
#include "util/RatelimitBucket.hpp"
#include "util/Twitch.hpp"
#include <IrcCommand>
#include <IrcMessage>
@@ -1201,18 +1202,6 @@ std::shared_ptr<Channel> TwitchIrcServer::getChannelOrEmptyByID(
return Channel::getEmpty();
}
QString TwitchIrcServer::cleanChannelName(const QString &dirtyChannelName)
{
if (dirtyChannelName.startsWith('#'))
{
return dirtyChannelName.mid(1).toLower();
}
else
{
return dirtyChannelName.toLower();
}
}
bool TwitchIrcServer::prepareToSend(
const std::shared_ptr<TwitchChannel> &channel)
{
@@ -1544,7 +1533,7 @@ void TwitchIrcServer::sendRawMessage(const QString &rawMessage)
ChannelPtr TwitchIrcServer::getOrAddChannel(const QString &dirtyChannelName)
{
auto channelName = this->cleanChannelName(dirtyChannelName);
auto channelName = cleanChannelName(dirtyChannelName);
// try get channel
ChannelPtr chan = this->getChannelOrEmpty(channelName);
@@ -1594,7 +1583,7 @@ ChannelPtr TwitchIrcServer::getOrAddChannel(const QString &dirtyChannelName)
ChannelPtr TwitchIrcServer::getChannelOrEmpty(const QString &dirtyChannelName)
{
auto channelName = this->cleanChannelName(dirtyChannelName);
auto channelName = cleanChannelName(dirtyChannelName);
std::lock_guard<std::mutex> lock(this->channelMutex);
-2
View File
@@ -169,8 +169,6 @@ protected:
std::shared_ptr<Channel> getCustomChannel(const QString &channelname);
QString cleanChannelName(const QString &dirtyChannelName);
private:
void onMessageSendRequested(const std::shared_ptr<TwitchChannel> &channel,
const QString &message, bool &sent);
+13 -2
View File
@@ -55,7 +55,10 @@ void Connection::onChannelBan(
BanAction action{};
action.timestamp = std::chrono::steady_clock::now();
if (!getApp()->isTest())
{
action.timestamp = std::chrono::steady_clock::now();
}
action.roomID = roomID;
action.source = ActionUser{
.id = QString::fromStdString(payload.event.moderatorUserID),
@@ -85,6 +88,10 @@ void Connection::onChannelBan(
runInGuiThread([action{std::move(action)}, chan{std::move(chan)}] {
auto time = QDateTime::currentDateTime();
if (getApp()->isTest())
{
time = QDateTime::fromSecsSinceEpoch(0).toUTC();
}
MessageBuilder msg(action, time);
msg->flags.set(MessageFlag::PubSub);
chan->addOrReplaceTimeout(msg.release(), QDateTime::currentDateTime());
@@ -162,7 +169,11 @@ void Connection::onChannelModerate(
return;
}
const auto now = QDateTime::currentDateTime();
auto now = QDateTime::currentDateTime();
if (getApp()->isTest())
{
now = QDateTime::fromSecsSinceEpoch(0).toUTC();
}
std::visit(
[&](auto &&action) {
+10
View File
@@ -62,6 +62,16 @@ void stripChannelName(QString &channelName)
}
}
QString cleanChannelName(const QString &dirtyChannelName)
{
if (dirtyChannelName.startsWith('#'))
{
return dirtyChannelName.mid(1).toLower();
}
return dirtyChannelName.toLower();
}
std::pair<ParsedUserName, ParsedUserID> parseUserNameOrID(const QString &input)
{
if (input.startsWith("id:"))
+3
View File
@@ -16,6 +16,9 @@ void stripUserName(QString &userName);
// stripChannelName removes any @ prefix or , suffix to make it more suitable for command use
void stripChannelName(QString &channelName);
/// Strips a leading `#` and lowercases the name
QString cleanChannelName(const QString &dirtyChannelName);
using ParsedUserName = QString;
using ParsedUserID = QString;