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

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 "privateinfojobtest.h"
0008 #include "restapimethod.h"
0009 #include "settings/privateinfojob.h"
0010 #include <QTest>
0011 QTEST_GUILESS_MAIN(PrivateInfoJobTest)
0012 using namespace RocketChatRestApi;
0013 PrivateInfoJobTest::PrivateInfoJobTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void PrivateInfoJobTest::shouldHaveDefaultValue()
0019 {
0020     PrivateInfoJob job;
0021     QVERIFY(!job.restApiMethod());
0022     QVERIFY(!job.networkAccessManager());
0023     QVERIFY(!job.start());
0024     QVERIFY(job.requireHttpAuthentication());
0025     QVERIFY(job.authToken().isEmpty());
0026     QVERIFY(job.authCode().isEmpty());
0027     QVERIFY(job.authMethod().isEmpty());
0028     QVERIFY(job.userId().isEmpty());
0029     QVERIFY(!job.restApiLogger());
0030     QVERIFY(!job.hasQueryParameterSupport());
0031     QVERIFY(!job.requireTwoFactorAuthentication());
0032 }
0033 
0034 void PrivateInfoJobTest::shouldGenerateRequest()
0035 {
0036     PrivateInfoJob job;
0037     const QString authToken = QStringLiteral("foo");
0038     const QString userId = QStringLiteral("user");
0039     job.setUserId(userId);
0040     job.setAuthToken(authToken);
0041     RestApiMethod method;
0042     method.setServerUrl(QStringLiteral("http://www.kde.org"));
0043     job.setRestApiMethod(&method);
0044     const QNetworkRequest request = job.request();
0045     QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/settings")));
0046     QCOMPARE(request.rawHeader(QByteArrayLiteral("X-Auth-Token")), authToken.toLocal8Bit());
0047     QCOMPARE(request.rawHeader(QByteArrayLiteral("X-User-Id")), userId.toLocal8Bit());
0048 }
0049 
0050 #include "moc_privateinfojobtest.cpp"