File indexing completed on 2025-02-02 04:51:25
0001 /* 0002 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "getpersonalaccesstokensjobtest.h" 0008 #include "personalaccesstoken/getpersonalaccesstokensjob.h" 0009 #include "restapimethod.h" 0010 #include <QTest> 0011 QTEST_GUILESS_MAIN(GetPersonalAccessTokensJobTest) 0012 using namespace RocketChatRestApi; 0013 GetPersonalAccessTokensJobTest::GetPersonalAccessTokensJobTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void GetPersonalAccessTokensJobTest::shouldHaveDefaultValue() 0019 { 0020 GetPersonalAccessTokensJob 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 GetPersonalAccessTokensJobTest::shouldGenerateRequest() 0035 { 0036 { 0037 GetPersonalAccessTokensJob job; 0038 const QString authToken = QStringLiteral("foo"); 0039 const QString userId = QStringLiteral("user"); 0040 job.setUserId(userId); 0041 job.setAuthToken(authToken); 0042 RestApiMethod method; 0043 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0044 job.setRestApiMethod(&method); 0045 const QNetworkRequest request = job.request(); 0046 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.getPersonalAccessTokens"))); 0047 QCOMPARE(request.rawHeader(QByteArrayLiteral("X-Auth-Token")), authToken.toLocal8Bit()); 0048 QCOMPARE(request.rawHeader(QByteArrayLiteral("X-User-Id")), userId.toLocal8Bit()); 0049 } 0050 } 0051 0052 #include "moc_getpersonalaccesstokensjobtest.cpp"