File indexing completed on 2025-02-02 04:51:30
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 "roomleavejobtest.h" 0008 #include "rooms/roomleavejob.h" 0009 #include "ruqola_restapi_helper.h" 0010 #include <QJsonDocument> 0011 QTEST_GUILESS_MAIN(RoomLeaveJobTest) 0012 using namespace RocketChatRestApi; 0013 RoomLeaveJobTest::RoomLeaveJobTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void RoomLeaveJobTest::shouldHaveDefaultValue() 0019 { 0020 RoomLeaveJob job; 0021 verifyDefaultValue(&job); 0022 QVERIFY(job.requireHttpAuthentication()); 0023 QVERIFY(job.roomId().isEmpty()); 0024 QVERIFY(!job.hasQueryParameterSupport()); 0025 QVERIFY(!job.requireTwoFactorAuthentication()); 0026 } 0027 0028 void RoomLeaveJobTest::shouldGenerateRequest() 0029 { 0030 RoomLeaveJob job; 0031 QNetworkRequest request = QNetworkRequest(QUrl()); 0032 verifyAuthentication(&job, request); 0033 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/rooms.leave"))); 0034 QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); 0035 } 0036 0037 void RoomLeaveJobTest::shouldGenerateJson() 0038 { 0039 RoomLeaveJob job; 0040 const QString roomId = QStringLiteral("foo1"); 0041 job.setRoomId(roomId); 0042 QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral(R"({"roomId":"%1"})").arg(roomId).toLatin1()); 0043 } 0044 0045 void RoomLeaveJobTest::shouldNotStarting() 0046 { 0047 RoomLeaveJob 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 const QString roomId = QStringLiteral("foo1"); 0063 job.setRoomId(roomId); 0064 QVERIFY(job.canStart()); 0065 } 0066 0067 #include "moc_roomleavejobtest.cpp"