File indexing completed on 2025-02-02 04:51:25
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 "getthreadsjobtest.h" 0008 #include "chat/getthreadsjob.h" 0009 #include "restapimethod.h" 0010 #include <QTest> 0011 QTEST_GUILESS_MAIN(GetThreadsJobTest) 0012 using namespace RocketChatRestApi; 0013 GetThreadsJobTest::GetThreadsJobTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void GetThreadsJobTest::shouldHaveDefaultValue() 0019 { 0020 GetThreadsJob job; 0021 QVERIFY(!job.restApiMethod()); 0022 QVERIFY(!job.networkAccessManager()); 0023 QVERIFY(!job.start()); 0024 QVERIFY(job.roomId().isEmpty()); 0025 QVERIFY(job.requireHttpAuthentication()); 0026 QVERIFY(!job.restApiLogger()); 0027 QVERIFY(job.hasQueryParameterSupport()); 0028 QVERIFY(!job.requireTwoFactorAuthentication()); 0029 QCOMPARE(job.searchType(), GetThreadsJob::TheadSearchType::All); 0030 } 0031 0032 void GetThreadsJobTest::shouldGenerateRequest() 0033 { 0034 GetThreadsJob job; 0035 RestApiMethod method; 0036 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0037 job.setRestApiMethod(&method); 0038 const QString roomId = QStringLiteral("bla"); 0039 job.setRoomId(roomId); 0040 QNetworkRequest request = job.request(); 0041 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.getThreadsList?rid=%1&type=all").arg(roomId))); 0042 0043 job.setSearchType(GetThreadsJob::TheadSearchType::Following); 0044 request = job.request(); 0045 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.getThreadsList?rid=%1&type=following").arg(roomId))); 0046 0047 job.setSearchType(GetThreadsJob::TheadSearchType::Unread); 0048 request = job.request(); 0049 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.getThreadsList?rid=%1&type=unread").arg(roomId))); 0050 0051 job.setSearchType(GetThreadsJob::TheadSearchType::All); 0052 request = job.request(); 0053 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.getThreadsList?rid=%1&type=all").arg(roomId))); 0054 } 0055 0056 void GetThreadsJobTest::shouldNotStarting() 0057 { 0058 GetThreadsJob job; 0059 0060 RestApiMethod method; 0061 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0062 job.setRestApiMethod(&method); 0063 0064 QNetworkAccessManager mNetworkAccessManager; 0065 job.setNetworkAccessManager(&mNetworkAccessManager); 0066 QVERIFY(!job.canStart()); 0067 const QString auth = QStringLiteral("foo"); 0068 const QString userId = QStringLiteral("foo"); 0069 job.setAuthToken(auth); 0070 QVERIFY(!job.canStart()); 0071 job.setUserId(userId); 0072 QVERIFY(!job.canStart()); 0073 const QString roomId = QStringLiteral("foo1"); 0074 job.setRoomId(roomId); 0075 QVERIFY(job.canStart()); 0076 } 0077 0078 #include "moc_getthreadsjobtest.cpp"