File indexing completed on 2025-02-02 04:51:27

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 "oauthappsjobtest.h"
0008 #include "misc/oauthappsjob.h"
0009 #include "restapimethod.h"
0010 #include "ruqola_restapi_helper.h"
0011 QTEST_GUILESS_MAIN(OauthAppsJobTest)
0012 using namespace RocketChatRestApi;
0013 OauthAppsJobTest::OauthAppsJobTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void OauthAppsJobTest::shouldHaveDefaultValue()
0019 {
0020     OauthAppsJob job;
0021     verifyDefaultValue(&job);
0022     QVERIFY(job.requireHttpAuthentication());
0023     QVERIFY(!job.hasQueryParameterSupport());
0024 }
0025 
0026 void OauthAppsJobTest::shouldGenerateRequest()
0027 {
0028     OauthAppsJob job;
0029     const QString clientId = QStringLiteral("cli");
0030     job.setClientId(clientId);
0031 
0032     const QString appId = QStringLiteral("appId");
0033     job.setAppId(appId);
0034     QNetworkRequest request = QNetworkRequest(QUrl());
0035     verifyAuthentication(&job, request);
0036     QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/oauth-apps.get?clientId=%1&appId=%2").arg(clientId, appId)));
0037 }
0038 
0039 void OauthAppsJobTest::shouldNotStarting()
0040 {
0041     OauthAppsJob job;
0042 
0043     RestApiMethod method;
0044     method.setServerUrl(QStringLiteral("http://www.kde.org"));
0045     job.setRestApiMethod(&method);
0046 
0047     QNetworkAccessManager mNetworkAccessManager;
0048     job.setNetworkAccessManager(&mNetworkAccessManager);
0049     QVERIFY(!job.canStart());
0050     const QString auth = QStringLiteral("foo");
0051     const QString userId = QStringLiteral("foo");
0052     job.setAuthToken(auth);
0053     QVERIFY(!job.canStart());
0054     job.setUserId(userId);
0055     QVERIFY(!job.canStart());
0056 
0057     const QString clientId = QStringLiteral("cli");
0058     job.setClientId(clientId);
0059     QVERIFY(!job.canStart());
0060 
0061     const QString appId = QStringLiteral("appId");
0062     job.setAppId(appId);
0063     QVERIFY(job.canStart());
0064 }
0065 
0066 #include "moc_oauthappsjobtest.cpp"