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

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 "changechannelreadonlyjobtest.h"
0008 #include "channels/changechannelreadonlyjob.h"
0009 #include "ruqola_restapi_helper.h"
0010 #include <QJsonDocument>
0011 QTEST_GUILESS_MAIN(ChangeChannelReadonlyJobTest)
0012 using namespace RocketChatRestApi;
0013 ChangeChannelReadonlyJobTest::ChangeChannelReadonlyJobTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void ChangeChannelReadonlyJobTest::shouldHaveDefaultValue()
0019 {
0020     ChangeChannelReadonlyJob job;
0021     verifyDefaultValue(&job);
0022     QVERIFY(!job.readOnly());
0023     QVERIFY(job.roomId().isEmpty());
0024     QVERIFY(!job.hasQueryParameterSupport());
0025 }
0026 
0027 void ChangeChannelReadonlyJobTest::shouldGenerateRequest()
0028 {
0029     ChangeChannelReadonlyJob job;
0030     QNetworkRequest request = QNetworkRequest(QUrl());
0031     verifyAuthentication(&job, request);
0032     QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.setReadOnly")));
0033     QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json"));
0034 }
0035 
0036 void ChangeChannelReadonlyJobTest::shouldGenerateJson()
0037 {
0038     ChangeChannelReadonlyJob job;
0039     const QString roomId = QStringLiteral("foo1");
0040     bool readOnly = true;
0041     job.setRoomId(roomId);
0042     job.setReadOnly(readOnly);
0043     QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral(R"({"readOnly":true,"roomId":"%1"})").arg(roomId).toLatin1());
0044 
0045     readOnly = false;
0046     job.setReadOnly(readOnly);
0047     QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral(R"({"readOnly":false,"roomId":"%1"})").arg(roomId).toLatin1());
0048 }
0049 
0050 #include "moc_changechannelreadonlyjobtest.cpp"