File indexing completed on 2024-06-02 05:07:02
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 "syncthreadmessagesjobtest.h" 0008 #include "chat/syncthreadmessagesjob.h" 0009 #include "ruqola_restapi_helper.h" 0010 QTEST_GUILESS_MAIN(SyncThreadMessagesJobTest) 0011 using namespace RocketChatRestApi; 0012 SyncThreadMessagesJobTest::SyncThreadMessagesJobTest(QObject *parent) 0013 : QObject(parent) 0014 { 0015 } 0016 0017 void SyncThreadMessagesJobTest::shouldHaveDefaultValue() 0018 { 0019 SyncThreadMessagesJob job; 0020 QVERIFY(!job.restApiMethod()); 0021 QVERIFY(!job.networkAccessManager()); 0022 QVERIFY(!job.start()); 0023 QVERIFY(job.threadMessageId().isEmpty()); 0024 QVERIFY(job.timeStamp().isEmpty()); 0025 QVERIFY(job.requireHttpAuthentication()); 0026 QVERIFY(!job.restApiLogger()); 0027 QVERIFY(!job.hasQueryParameterSupport()); 0028 } 0029 0030 void SyncThreadMessagesJobTest::shouldGenerateRequest() 0031 { 0032 SyncThreadMessagesJob job; 0033 RestApiMethod method; 0034 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0035 job.setRestApiMethod(&method); 0036 const QString threadMessageId = QStringLiteral("bla"); 0037 job.setThreadMessageId(threadMessageId); 0038 0039 const QString timestamp = QStringLiteral("blu"); 0040 job.setTimeStamp(timestamp); 0041 0042 const QNetworkRequest request = job.request(); 0043 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.syncThreadMessages?tmid=%1&updatedSince=%2").arg(threadMessageId, timestamp))); 0044 } 0045 0046 void SyncThreadMessagesJobTest::shouldNotStarting() 0047 { 0048 SyncThreadMessagesJob job; 0049 0050 RestApiMethod method; 0051 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0052 job.setRestApiMethod(&method); 0053 0054 QNetworkAccessManager mNetworkAccessManager; 0055 job.setNetworkAccessManager(&mNetworkAccessManager); 0056 QVERIFY(!job.canStart()); 0057 const QString auth = QStringLiteral("foo"); 0058 const QString userId = QStringLiteral("foo"); 0059 job.setAuthToken(auth); 0060 QVERIFY(!job.canStart()); 0061 job.setUserId(userId); 0062 QVERIFY(!job.canStart()); 0063 const QString threadMessageId = QStringLiteral("foo1"); 0064 job.setThreadMessageId(threadMessageId); 0065 QVERIFY(!job.canStart()); 0066 0067 const QString timestamp = QStringLiteral("blu"); 0068 job.setTimeStamp(timestamp); 0069 QVERIFY(job.canStart()); 0070 } 0071 0072 #include "moc_syncthreadmessagesjobtest.cpp"