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

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "customuserstatuscreatetestjob.h"
0008 #include "custom/customuserstatuscreatejob.h"
0009 #include "ruqola_restapi_helper.h"
0010 #include <QJsonDocument>
0011 QTEST_GUILESS_MAIN(CustomUserStatusCreateTestJob)
0012 using namespace RocketChatRestApi;
0013 CustomUserStatusCreateTestJob::CustomUserStatusCreateTestJob(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void CustomUserStatusCreateTestJob::shouldHaveDefaultValue()
0019 {
0020     CustomUserStatusCreateJob job;
0021     verifyDefaultValue(&job);
0022     QVERIFY(job.requireHttpAuthentication());
0023     QVERIFY(!job.hasQueryParameterSupport());
0024 }
0025 
0026 void CustomUserStatusCreateTestJob::shouldGenerateRequest()
0027 {
0028     CustomUserStatusCreateJob job;
0029     QNetworkRequest request = QNetworkRequest(QUrl());
0030     verifyAuthentication(&job, request);
0031     QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/custom-user-status.create")));
0032     QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json"));
0033 }
0034 
0035 void CustomUserStatusCreateTestJob::shouldGenerateJson()
0036 {
0037     CustomUserStatusCreateJob job;
0038 
0039     const QString name = QStringLiteral("foo1");
0040     const QString statusType = QStringLiteral("topic1");
0041     CustomUserStatusCreateJob::StatusCreateInfo info;
0042     info.name = name;
0043     info.statusType = statusType;
0044     job.setStatusCreateInfo(info);
0045     QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral(R"({"name":"%1","statusType":"%2"})").arg(name, statusType).toLatin1());
0046 }
0047 
0048 void CustomUserStatusCreateTestJob::shouldNotStarting()
0049 {
0050     CustomUserStatusCreateJob 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 
0065     CustomUserStatusCreateJob::StatusCreateInfo info;
0066     info.name = QStringLiteral("foo");
0067     job.setStatusCreateInfo(info);
0068     QVERIFY(!job.canStart());
0069     info.statusType = QStringLiteral("bla");
0070     job.setStatusCreateInfo(info);
0071     QVERIFY(job.canStart());
0072 }
0073 
0074 #include "moc_customuserstatuscreatetestjob.cpp"