File indexing completed on 2025-02-02 04:51:26
0001 /* 0002 SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "leavegroupsjobtest.h" 0008 #include "groups/leavegroupsjob.h" 0009 #include "ruqola_restapi_helper.h" 0010 #include <QJsonDocument> 0011 QTEST_GUILESS_MAIN(LeaveGroupsJobTest) 0012 using namespace RocketChatRestApi; 0013 LeaveGroupsJobTest::LeaveGroupsJobTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void LeaveGroupsJobTest::shouldHaveDefaultValue() 0019 { 0020 LeaveGroupsJob job; 0021 verifyDefaultValue(&job); 0022 QVERIFY(job.requireHttpAuthentication()); 0023 QVERIFY(!job.hasIdentifier()); 0024 QVERIFY(!job.hasQueryParameterSupport()); 0025 } 0026 0027 void LeaveGroupsJobTest::shouldGenerateRequest() 0028 { 0029 LeaveGroupsJob job; 0030 QNetworkRequest request = QNetworkRequest(QUrl()); 0031 verifyAuthentication(&job, request); 0032 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.leave"))); 0033 QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); 0034 } 0035 0036 void LeaveGroupsJobTest::shouldGenerateJson() 0037 { 0038 LeaveGroupsJob job; 0039 const QString roomId = QStringLiteral("foo1"); 0040 ChannelGroupBaseJob::ChannelGroupInfo info; 0041 info.identifier = roomId; 0042 info.channelGroupInfoType = ChannelGroupBaseJob::ChannelGroupInfoType::Identifier; 0043 job.setChannelGroupInfo(info); 0044 QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral(R"({"roomId":"%1"})").arg(roomId).toLatin1()); 0045 } 0046 0047 void LeaveGroupsJobTest::shouldNotStarting() 0048 { 0049 LeaveGroupsJob job; 0050 0051 RestApiMethod method; 0052 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0053 job.setRestApiMethod(&method); 0054 0055 QNetworkAccessManager mNetworkAccessManager; 0056 job.setNetworkAccessManager(&mNetworkAccessManager); 0057 QVERIFY(!job.canStart()); 0058 const QString auth = QStringLiteral("foo"); 0059 const QString userId = QStringLiteral("foo"); 0060 job.setAuthToken(auth); 0061 QVERIFY(!job.canStart()); 0062 job.setUserId(userId); 0063 QVERIFY(!job.canStart()); 0064 const QString roomId = QStringLiteral("foo1"); 0065 ChannelGroupBaseJob::ChannelGroupInfo info; 0066 info.identifier = roomId; 0067 info.channelGroupInfoType = ChannelGroupBaseJob::ChannelGroupInfoType::Identifier; 0068 job.setChannelGroupInfo(info); 0069 0070 QVERIFY(job.canStart()); 0071 } 0072 0073 #include "moc_leavegroupsjobtest.cpp"