File indexing completed on 2024-06-02 05:06:52
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "channelgetcountersjobtest.h" 0008 #include "channels/channelgetcountersjob.h" 0009 #include "restapimethod.h" 0010 #include "ruqola_restapi_helper.h" 0011 QTEST_GUILESS_MAIN(ChannelGetCountersJobTest) 0012 using namespace RocketChatRestApi; 0013 ChannelGetCountersJobTest::ChannelGetCountersJobTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void ChannelGetCountersJobTest::shouldHaveDefaultValue() 0019 { 0020 ChannelGetCountersJob job; 0021 QVERIFY(!job.restApiMethod()); 0022 QVERIFY(!job.networkAccessManager()); 0023 QVERIFY(!job.start()); 0024 QVERIFY(job.requireHttpAuthentication()); 0025 QVERIFY(!job.hasIdentifier()); 0026 QVERIFY(!job.restApiLogger()); 0027 QVERIFY(!job.hasQueryParameterSupport()); 0028 } 0029 0030 void ChannelGetCountersJobTest::shouldGenerateRequest() 0031 { 0032 ChannelGetCountersJob job; 0033 RestApiMethod method; 0034 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0035 job.setRestApiMethod(&method); 0036 ChannelGroupBaseJob::ChannelGroupInfo info; 0037 info.channelGroupInfoType = ChannelGroupBaseJob::ChannelGroupInfoType::Identifier; 0038 info.identifier = QStringLiteral("avat"); 0039 job.setChannelGroupInfo(info); 0040 QNetworkRequest request = job.request(); 0041 verifyAuthentication(&job, request); 0042 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.counters?roomId=avat"))); 0043 } 0044 0045 void ChannelGetCountersJobTest::shouldNotStarting() 0046 { 0047 ChannelGetCountersJob 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 ChannelGroupBaseJob::ChannelGroupInfo info; 0063 info.channelGroupInfoType = ChannelGroupBaseJob::ChannelGroupInfoType::Identifier; 0064 info.identifier = QStringLiteral("avat"); 0065 job.setChannelGroupInfo(info); 0066 QVERIFY(job.canStart()); 0067 } 0068 0069 #include "moc_channelgetcountersjobtest.cpp"