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

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "getusersinrolejobtest.h"
0008 #include "restapimethod.h"
0009 #include "role/getusersinrolejob.h"
0010 #include <QTest>
0011 QTEST_GUILESS_MAIN(GetUsersInRoleJobTest)
0012 using namespace RocketChatRestApi;
0013 GetUsersInRoleJobTest::GetUsersInRoleJobTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void GetUsersInRoleJobTest::shouldHaveDefaultValue()
0019 {
0020     GetUsersInRoleJob job;
0021     QVERIFY(!job.restApiMethod());
0022     QVERIFY(!job.networkAccessManager());
0023     QVERIFY(!job.start());
0024     QVERIFY(job.requireHttpAuthentication());
0025     QVERIFY(!job.restApiLogger());
0026     QVERIFY(job.hasQueryParameterSupport());
0027     QVERIFY(!job.requireTwoFactorAuthentication());
0028     QVERIFY(job.roleId().isEmpty());
0029 }
0030 
0031 void GetUsersInRoleJobTest::shouldGenerateRequest()
0032 {
0033     GetUsersInRoleJob job;
0034     RestApiMethod method;
0035     method.setServerUrl(QStringLiteral("http://www.kde.org"));
0036     job.setRestApiMethod(&method);
0037     const QString roleId{QStringLiteral("bla")};
0038     job.setRoleId(roleId);
0039     QNetworkRequest request = job.request();
0040     QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/roles.getUsersInRole?role=%1").arg(roleId)));
0041 }
0042 
0043 void GetUsersInRoleJobTest::shouldNotStarting()
0044 {
0045     GetUsersInRoleJob job;
0046 
0047     RestApiMethod method;
0048     method.setServerUrl(QStringLiteral("http://www.kde.org"));
0049     job.setRestApiMethod(&method);
0050 
0051     QNetworkAccessManager mNetworkAccessManager;
0052     job.setNetworkAccessManager(&mNetworkAccessManager);
0053     QVERIFY(!job.canStart());
0054     const QString auth = QStringLiteral("foo");
0055     const QString userId = QStringLiteral("foo");
0056     job.setAuthToken(auth);
0057     QVERIFY(!job.canStart());
0058     job.setUserId(userId);
0059 
0060     QVERIFY(!job.canStart());
0061     job.setRoleId(QStringLiteral("ss"));
0062     QVERIFY(job.canStart());
0063 }
0064 
0065 #include "moc_getusersinrolejobtest.cpp"