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