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