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