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

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 "channelfilesjobtest.h"
0008 #include "channels/channelfilesjob.h"
0009 #include "ruqola_restapi_helper.h"
0010 QTEST_GUILESS_MAIN(ChannelFilesJobTest)
0011 using namespace RocketChatRestApi;
0012 ChannelFilesJobTest::ChannelFilesJobTest(QObject *parent)
0013     : QObject(parent)
0014 {
0015 }
0016 
0017 void ChannelFilesJobTest::shouldHaveDefaultValue()
0018 {
0019     ChannelFilesJob job;
0020     verifyDefaultValue(&job);
0021     QVERIFY(job.requireHttpAuthentication());
0022     QVERIFY(!job.hasIdentifier());
0023     QCOMPARE(job.channelType(), ChannelFilesJob::ChannelType::Unknown);
0024     QVERIFY(job.hasQueryParameterSupport());
0025     QVERIFY(!job.requireTwoFactorAuthentication());
0026 }
0027 
0028 void ChannelFilesJobTest::shouldGenerateRequest()
0029 {
0030     ChannelFilesJob job;
0031     job.setChannelType(ChannelFilesJob::Channel);
0032     ChannelGroupBaseJob::ChannelGroupInfo info;
0033     info.channelGroupInfoType = ChannelGroupBaseJob::ChannelGroupInfoType::Identifier;
0034     info.identifier = QStringLiteral("foo");
0035     job.setChannelGroupInfo(info);
0036 
0037     QNetworkRequest request = QNetworkRequest(QUrl());
0038     verifyAuthentication(&job, request);
0039     QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.files?roomId=foo")));
0040 
0041     job.setChannelType(ChannelFilesJob::Direct);
0042     verifyAuthentication(&job, request);
0043     QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/im.files?roomId=foo")));
0044 
0045     job.setChannelType(ChannelFilesJob::Groups);
0046     verifyAuthentication(&job, request);
0047     QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.files?roomId=foo")));
0048 }
0049 
0050 void ChannelFilesJobTest::shouldNotStarting()
0051 {
0052     ChannelFilesJob job;
0053 
0054     RestApiMethod method;
0055     method.setServerUrl(QStringLiteral("http://www.kde.org"));
0056     job.setRestApiMethod(&method);
0057 
0058     QNetworkAccessManager mNetworkAccessManager;
0059     job.setNetworkAccessManager(&mNetworkAccessManager);
0060     QVERIFY(!job.canStart());
0061     const QString auth = QStringLiteral("foo");
0062     const QString userId = QStringLiteral("foo");
0063     job.setAuthToken(auth);
0064     QVERIFY(!job.canStart());
0065     job.setUserId(userId);
0066     QVERIFY(!job.canStart());
0067     const QString roomId = QStringLiteral("foo1");
0068     ChannelGroupBaseJob::ChannelGroupInfo info;
0069     info.channelGroupInfoType = ChannelGroupBaseJob::ChannelGroupInfoType::Identifier;
0070     info.identifier = roomId;
0071     job.setChannelGroupInfo(info);
0072     QVERIFY(!job.canStart());
0073     job.setChannelType(ChannelFilesJob::ChannelType::Channel);
0074     QVERIFY(job.canStart());
0075 }
0076 
0077 #include "moc_channelfilesjobtest.cpp"