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

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 "teamconverttochanneljobtest.h"
0008 #include "ruqola_restapi_helper.h"
0009 #include "teams/teamconverttochanneljob.h"
0010 #include <QJsonDocument>
0011 QTEST_GUILESS_MAIN(TeamConvertToChannelJobTest)
0012 using namespace RocketChatRestApi;
0013 TeamConvertToChannelJobTest::TeamConvertToChannelJobTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void TeamConvertToChannelJobTest::shouldHaveDefaultValue()
0019 {
0020     TeamConvertToChannelJob job;
0021     verifyDefaultValue(&job);
0022     QVERIFY(job.requireHttpAuthentication());
0023     QVERIFY(job.teamId().isEmpty());
0024     QVERIFY(job.roomsToRemove().isEmpty());
0025     QVERIFY(!job.hasQueryParameterSupport());
0026 }
0027 
0028 void TeamConvertToChannelJobTest::shouldGenerateRequest()
0029 {
0030     TeamConvertToChannelJob job;
0031     QNetworkRequest request = QNetworkRequest(QUrl());
0032     verifyAuthentication(&job, request);
0033     QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/teams.convertToChannel")));
0034     QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json"));
0035 }
0036 
0037 void TeamConvertToChannelJobTest::shouldGenerateJson()
0038 {
0039     TeamConvertToChannelJob job;
0040     const QString teamId = QStringLiteral("foo2");
0041     job.setTeamId(teamId);
0042 
0043     QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral(R"({"teamId":"%1"})").arg(teamId).toLatin1());
0044     const QStringList roomsToRemove{QStringLiteral("bla"), QStringLiteral("bla1"), QStringLiteral("bla2")};
0045     job.setRoomsToRemove(roomsToRemove);
0046     QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral(R"({"roomsToRemove":["bla","bla1","bla2"],"teamId":"%1"})").arg(teamId).toLatin1());
0047 }
0048 
0049 void TeamConvertToChannelJobTest::shouldNotStarting()
0050 {
0051     TeamConvertToChannelJob job;
0052 
0053     RestApiMethod method;
0054     method.setServerUrl(QStringLiteral("http://www.kde.org"));
0055     job.setRestApiMethod(&method);
0056 
0057     QNetworkAccessManager mNetworkAccessManager;
0058     job.setNetworkAccessManager(&mNetworkAccessManager);
0059     QVERIFY(!job.canStart());
0060     const QString auth = QStringLiteral("foo");
0061     const QString userId = QStringLiteral("foo");
0062     job.setAuthToken(auth);
0063     QVERIFY(!job.canStart());
0064     job.setUserId(userId);
0065     QVERIFY(!job.canStart());
0066     const QString teamId = QStringLiteral("foo2");
0067     job.setTeamId(teamId);
0068     QVERIFY(job.canStart());
0069 }
0070 
0071 #include "moc_teamconverttochanneljobtest.cpp"