File indexing completed on 2025-02-02 04:51:28
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 "removeothertokensjobtest.h" 0008 #include "ruqola_restapi_helper.h" 0009 #include "users/removeothertokensjob.h" 0010 #include <QJsonDocument> 0011 QTEST_GUILESS_MAIN(RemoveOtherTokensJobTest) 0012 using namespace RocketChatRestApi; 0013 RemoveOtherTokensJobTest::RemoveOtherTokensJobTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void RemoveOtherTokensJobTest::shouldHaveDefaultValue() 0019 { 0020 RemoveOtherTokensJob job; 0021 verifyDefaultValue(&job); 0022 QVERIFY(job.requireHttpAuthentication()); 0023 QVERIFY(!job.hasQueryParameterSupport()); 0024 QVERIFY(!job.requireTwoFactorAuthentication()); 0025 } 0026 0027 void RemoveOtherTokensJobTest::shouldGenerateRequest() 0028 { 0029 RemoveOtherTokensJob job; 0030 QNetworkRequest request = QNetworkRequest(QUrl()); 0031 verifyAuthentication(&job, request); 0032 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.removeOtherTokens"))); 0033 QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); 0034 } 0035 0036 void RemoveOtherTokensJobTest::shouldGenerateJson() 0037 { 0038 RemoveOtherTokensJob job; 0039 QVERIFY(job.json().toJson(QJsonDocument::Compact).isNull()); 0040 } 0041 0042 void RemoveOtherTokensJobTest::shouldNotStarting() 0043 { 0044 RemoveOtherTokensJob 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 } 0060 0061 #include "moc_removeothertokensjobtest.cpp"