File indexing completed on 2025-02-02 04:51:23
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 "creategroupsjobtest.h" 0008 #include "groups/creategroupsjob.h" 0009 #include "ruqola_restapi_helper.h" 0010 #include <QJsonDocument> 0011 QTEST_GUILESS_MAIN(CreateGroupsJobTest) 0012 using namespace RocketChatRestApi; 0013 CreateGroupsJobTest::CreateGroupsJobTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void CreateGroupsJobTest::shouldHaveDefaultValue() 0019 { 0020 CreateGroupsJob job; 0021 verifyDefaultValue(&job); 0022 QVERIFY(job.requireHttpAuthentication()); 0023 CreateChannelTeamInfo info = job.createGroupsInfo(); 0024 QVERIFY(!info.readOnly); 0025 QVERIFY(info.name.isEmpty()); 0026 QVERIFY(info.members.isEmpty()); 0027 QVERIFY(!job.hasQueryParameterSupport()); 0028 } 0029 0030 void CreateGroupsJobTest::shouldGenerateRequest() 0031 { 0032 CreateGroupsJob job; 0033 QNetworkRequest request = QNetworkRequest(QUrl()); 0034 verifyAuthentication(&job, request); 0035 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/groups.create"))); 0036 QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); 0037 } 0038 0039 void CreateGroupsJobTest::shouldGenerateJson() 0040 { 0041 CreateGroupsJob job; 0042 const QString channelname = QStringLiteral("foo1"); 0043 CreateChannelTeamInfo info; 0044 info.name = channelname; 0045 job.setCreateGroupsInfo(info); 0046 QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral(R"({"extraData":{},"name":"%1"})").arg(channelname).toLatin1()); 0047 0048 bool readOnly = false; 0049 info.readOnly = readOnly; 0050 job.setCreateGroupsInfo(info); 0051 QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral(R"({"extraData":{},"name":"%1"})").arg(channelname).toLatin1()); 0052 0053 readOnly = true; 0054 info.readOnly = readOnly; 0055 job.setCreateGroupsInfo(info); 0056 QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral(R"({"extraData":{},"name":"%1","readOnly":true})").arg(channelname).toLatin1()); 0057 0058 const QStringList members = {QStringLiteral("foo"), QStringLiteral("bla")}; 0059 info.members = members; 0060 job.setCreateGroupsInfo(info); 0061 QCOMPARE(job.json().toJson(QJsonDocument::Compact), 0062 QStringLiteral(R"({"extraData":{},"members":["foo","bla"],"name":"%1","readOnly":true})").arg(channelname).toLatin1()); 0063 0064 const QString teamId = {QStringLiteral("foo")}; 0065 info.teamId = teamId; 0066 info.broadcast = true; 0067 job.setCreateGroupsInfo(info); 0068 QCOMPARE( 0069 job.json().toJson(QJsonDocument::Compact), 0070 QStringLiteral(R"({"extraData":{"broadcast":true,"teamId":"foo"},"members":["foo","bla"],"name":"%1","readOnly":true})").arg(channelname).toLatin1()); 0071 } 0072 0073 void CreateGroupsJobTest::shouldNotStarting() 0074 { 0075 CreateGroupsJob job; 0076 0077 RestApiMethod method; 0078 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0079 job.setRestApiMethod(&method); 0080 0081 QNetworkAccessManager mNetworkAccessManager; 0082 job.setNetworkAccessManager(&mNetworkAccessManager); 0083 QVERIFY(!job.canStart()); 0084 const QString auth = QStringLiteral("foo"); 0085 const QString userId = QStringLiteral("foo"); 0086 job.setAuthToken(auth); 0087 QVERIFY(!job.canStart()); 0088 job.setUserId(userId); 0089 QVERIFY(!job.canStart()); 0090 const QString roomId = QStringLiteral("foo1"); 0091 CreateChannelTeamInfo info; 0092 info.name = roomId; 0093 job.setCreateGroupsInfo(info); 0094 QVERIFY(job.canStart()); 0095 } 0096 0097 #include "moc_creategroupsjobtest.cpp"