File indexing completed on 2024-05-19 05:03:07

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 "channelopenjobtest.h"
0008 #include "channels/channelopenjob.h"
0009 #include "ruqola_restapi_helper.h"
0010 #include <QJsonDocument>
0011 QTEST_GUILESS_MAIN(ChannelOpenJobTest)
0012 using namespace RocketChatRestApi;
0013 ChannelOpenJobTest::ChannelOpenJobTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void ChannelOpenJobTest::shouldHaveDefaultValue()
0019 {
0020     ChannelOpenJob job;
0021     verifyDefaultValue(&job);
0022     QVERIFY(job.requireHttpAuthentication());
0023     QVERIFY(!job.hasIdentifier());
0024     QVERIFY(!job.hasQueryParameterSupport());
0025 }
0026 
0027 void ChannelOpenJobTest::shouldGenerateRequest()
0028 {
0029     ChannelOpenJob job;
0030     QNetworkRequest request = QNetworkRequest(QUrl());
0031     verifyAuthentication(&job, request);
0032     QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.open")));
0033     QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json"));
0034 }
0035 
0036 void ChannelOpenJobTest::shouldGenerateJson()
0037 {
0038     ChannelOpenJob job;
0039     const QString roomId = QStringLiteral("foo1");
0040     ChannelGroupBaseJob::ChannelGroupInfo info;
0041     info.channelGroupInfoType = ChannelGroupBaseJob::ChannelGroupInfoType::Identifier;
0042     info.identifier = roomId;
0043     job.setChannelGroupInfo(info);
0044     QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral(R"({"roomId":"%1"})").arg(roomId).toLatin1());
0045 }
0046 
0047 void ChannelOpenJobTest::shouldNotStarting()
0048 {
0049     ChannelOpenJob job;
0050 
0051     RestApiMethod method;
0052     method.setServerUrl(QStringLiteral("http://www.kde.org"));
0053     job.setRestApiMethod(&method);
0054 
0055     QNetworkAccessManager mNetworkAccessManager;
0056     job.setNetworkAccessManager(&mNetworkAccessManager);
0057     QVERIFY(!job.canStart());
0058     const QString auth = QStringLiteral("foo");
0059     const QString userId = QStringLiteral("foo");
0060     job.setAuthToken(auth);
0061     QVERIFY(!job.canStart());
0062     job.setUserId(userId);
0063     QVERIFY(!job.canStart());
0064     const QString roomId = QStringLiteral("foo1");
0065     ChannelGroupBaseJob::ChannelGroupInfo info;
0066     info.channelGroupInfoType = ChannelGroupBaseJob::ChannelGroupInfoType::Identifier;
0067     info.identifier = roomId;
0068     job.setChannelGroupInfo(info);
0069     QVERIFY(job.canStart());
0070 }
0071 
0072 #include "moc_channelopenjobtest.cpp"