File indexing completed on 2024-05-19 05:03:12
0001 /* 0002 SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "reactonmessagejobtest.h" 0008 #include "chat/reactonmessagejob.h" 0009 #include "ruqola_restapi_helper.h" 0010 #include <QJsonDocument> 0011 QTEST_GUILESS_MAIN(ReactOnMessageJobTest) 0012 using namespace RocketChatRestApi; 0013 ReactOnMessageJobTest::ReactOnMessageJobTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void ReactOnMessageJobTest::shouldHaveDefaultValue() 0019 { 0020 ReactOnMessageJob job; 0021 verifyDefaultValue(&job); 0022 QVERIFY(job.requireHttpAuthentication()); 0023 QVERIFY(job.messageId().isEmpty()); 0024 QVERIFY(job.emoji().isEmpty()); 0025 QVERIFY(!job.hasQueryParameterSupport()); 0026 QVERIFY(!job.requireTwoFactorAuthentication()); 0027 } 0028 0029 void ReactOnMessageJobTest::shouldGenerateRequest() 0030 { 0031 ReactOnMessageJob job; 0032 QNetworkRequest request = QNetworkRequest(QUrl()); 0033 verifyAuthentication(&job, request); 0034 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.react"))); 0035 QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); 0036 } 0037 0038 void ReactOnMessageJobTest::shouldGenerateJson() 0039 { 0040 ReactOnMessageJob job; 0041 const QString messageid = QStringLiteral("foo1"); 0042 const QString emoji = QStringLiteral("topic1"); 0043 job.setMessageId(messageid); 0044 job.setEmoji(emoji); 0045 QCOMPARE(job.json().toJson(QJsonDocument::Compact), 0046 QStringLiteral(R"({"emoji":"%1","messageId":"%2","shouldReact":true})").arg(emoji, messageid).toLatin1()); 0047 0048 job.setShouldReact(false); 0049 QCOMPARE(job.json().toJson(QJsonDocument::Compact), 0050 QStringLiteral(R"({"emoji":"%1","messageId":"%2","shouldReact":false})").arg(emoji, messageid).toLatin1()); 0051 } 0052 0053 void ReactOnMessageJobTest::shouldNotStarting() 0054 { 0055 ReactOnMessageJob job; 0056 0057 RestApiMethod method; 0058 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0059 job.setRestApiMethod(&method); 0060 0061 QNetworkAccessManager mNetworkAccessManager; 0062 job.setNetworkAccessManager(&mNetworkAccessManager); 0063 QVERIFY(!job.canStart()); 0064 const QString auth = QStringLiteral("foo"); 0065 const QString userId = QStringLiteral("foo"); 0066 job.setAuthToken(auth); 0067 QVERIFY(!job.canStart()); 0068 job.setUserId(userId); 0069 QVERIFY(!job.canStart()); 0070 const QString messageId = QStringLiteral("foo1"); 0071 job.setMessageId(messageId); 0072 QVERIFY(!job.canStart()); 0073 const QString emoji = QStringLiteral("topic1"); 0074 job.setEmoji(emoji); 0075 QVERIFY(job.canStart()); 0076 } 0077 0078 #include "moc_reactonmessagejobtest.cpp"