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 "getsnippetedmessagesjobtest.h" 0008 #include "chat/getsnippetedmessagesjob.h" 0009 #include "ruqola_restapi_helper.h" 0010 QTEST_GUILESS_MAIN(GetSnippetedMessagesJobTest) 0011 using namespace RocketChatRestApi; 0012 GetSnippetedMessagesJobTest::GetSnippetedMessagesJobTest(QObject *parent) 0013 : QObject(parent) 0014 { 0015 } 0016 0017 void GetSnippetedMessagesJobTest::shouldHaveDefaultValue() 0018 { 0019 GetSnippetedMessagesJob job; 0020 QVERIFY(!job.restApiMethod()); 0021 QVERIFY(!job.networkAccessManager()); 0022 QVERIFY(!job.start()); 0023 QVERIFY(job.roomId().isEmpty()); 0024 QVERIFY(job.requireHttpAuthentication()); 0025 QVERIFY(!job.restApiLogger()); 0026 QVERIFY(job.hasQueryParameterSupport()); 0027 QVERIFY(!job.requireTwoFactorAuthentication()); 0028 } 0029 0030 void GetSnippetedMessagesJobTest::shouldGenerateRequest() 0031 { 0032 GetSnippetedMessagesJob job; 0033 RestApiMethod method; 0034 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0035 job.setRestApiMethod(&method); 0036 const QString roomId = QStringLiteral("bla"); 0037 job.setRoomId(roomId); 0038 const QNetworkRequest request = job.request(); 0039 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.getSnippetedMessages?roomId=%1").arg(roomId))); 0040 } 0041 0042 void GetSnippetedMessagesJobTest::shouldNotStarting() 0043 { 0044 GetSnippetedMessagesJob job; 0045 0046 RestApiMethod method; 0047 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0048 job.setRestApiMethod(&method); 0049 0050 QNetworkAccessManager mNetworkAccessManager; 0051 job.setNetworkAccessManager(&mNetworkAccessManager); 0052 QVERIFY(!job.canStart()); 0053 const QString auth = QStringLiteral("foo"); 0054 const QString userId = QStringLiteral("foo"); 0055 job.setAuthToken(auth); 0056 QVERIFY(!job.canStart()); 0057 job.setUserId(userId); 0058 QVERIFY(!job.canStart()); 0059 const QString roomId = QStringLiteral("foo1"); 0060 job.setRoomId(roomId); 0061 QVERIFY(job.canStart()); 0062 } 0063 0064 #include "moc_getsnippetedmessagesjobtest.cpp"