File indexing completed on 2025-02-02 04:51:33

0001 /*
0002    SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "unfollowmessagejobtest.h"
0008 #include "chat/unfollowmessagejob.h"
0009 #include "ruqola_restapi_helper.h"
0010 #include <QJsonDocument>
0011 QTEST_GUILESS_MAIN(UnFollowMessageJobTest)
0012 using namespace RocketChatRestApi;
0013 UnFollowMessageJobTest::UnFollowMessageJobTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void UnFollowMessageJobTest::shouldHaveDefaultValue()
0019 {
0020     UnFollowMessageJob job;
0021     verifyDefaultValue(&job);
0022     QVERIFY(job.requireHttpAuthentication());
0023     QVERIFY(job.messageId().isEmpty());
0024     QVERIFY(!job.hasQueryParameterSupport());
0025     QVERIFY(!job.requireTwoFactorAuthentication());
0026 }
0027 
0028 void UnFollowMessageJobTest::shouldGenerateRequest()
0029 {
0030     UnFollowMessageJob job;
0031     QNetworkRequest request = QNetworkRequest(QUrl());
0032     verifyAuthentication(&job, request);
0033     QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.unfollowMessage")));
0034     QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json"));
0035 }
0036 
0037 void UnFollowMessageJobTest::shouldGenerateJson()
0038 {
0039     UnFollowMessageJob job;
0040     const QString messageid = QStringLiteral("foo1");
0041     job.setMessageId(messageid);
0042     QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral(R"({"mid":"%1"})").arg(messageid).toLatin1());
0043 }
0044 
0045 void UnFollowMessageJobTest::shouldNotStarting()
0046 {
0047     UnFollowMessageJob job;
0048 
0049     RestApiMethod method;
0050     method.setServerUrl(QStringLiteral("http://www.kde.org"));
0051     job.setRestApiMethod(&method);
0052 
0053     QNetworkAccessManager mNetworkAccessManager;
0054     job.setNetworkAccessManager(&mNetworkAccessManager);
0055     QVERIFY(!job.canStart());
0056     const QString auth = QStringLiteral("foo");
0057     const QString userId = QStringLiteral("foo");
0058     job.setAuthToken(auth);
0059     QVERIFY(!job.canStart());
0060     job.setUserId(userId);
0061     QVERIFY(!job.canStart());
0062     const QString messageId = QStringLiteral("foo1");
0063     job.setMessageId(messageId);
0064     QVERIFY(job.canStart());
0065 }
0066 
0067 #include "moc_unfollowmessagejobtest.cpp"