diff --git a/autotests/changechanneltopicjobtest.cpp b/autotests/changechanneltopicjobtest.cpp index b731e4b6..3a9609f5 100644 --- a/autotests/changechanneltopicjobtest.cpp +++ b/autotests/changechanneltopicjobtest.cpp @@ -1,29 +1,43 @@ /* Copyright (c) 2018 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "changechanneltopicjobtest.h" +#include "restapi/changechanneltopicjob.h" #include QTEST_GUILESS_MAIN(ChangeChannelTopicJobTest) ChangeChannelTopicJobTest::ChangeChannelTopicJobTest(QObject *parent) : QObject(parent) { } + +void ChangeChannelTopicJobTest::shouldHaveDefaultValue() +{ + ChangeChannelTopicJob job; + QVERIFY(!job.restApiMethod()); + QVERIFY(!job.networkAccessManager()); + QVERIFY(!job.start()); + QVERIFY(job.requireHttpAuthentication()); + QVERIFY(job.authToken().isEmpty()); + QVERIFY(job.userId().isEmpty()); + QVERIFY(!job.ruqolaLogger()); + QVERIFY(job.topic().isEmpty()); +} diff --git a/autotests/changechanneltopicjobtest.h b/autotests/changechanneltopicjobtest.h index 41e77631..2db29174 100644 --- a/autotests/changechanneltopicjobtest.h +++ b/autotests/changechanneltopicjobtest.h @@ -1,34 +1,36 @@ /* Copyright (c) 2018 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef CHANGECHANNELTOPICJOBTEST_H #define CHANGECHANNELTOPICJOBTEST_H #include class ChangeChannelTopicJobTest : public QObject { Q_OBJECT public: explicit ChangeChannelTopicJobTest(QObject *parent = nullptr); ~ChangeChannelTopicJobTest() = default; +private Q_SLOTS: + void shouldHaveDefaultValue(); }; #endif // CHANGECHANNELTOPICJOBTEST_H diff --git a/src/restapi/changechanneltopicjob.cpp b/src/restapi/changechanneltopicjob.cpp index b1d97ac6..6ab604c2 100644 --- a/src/restapi/changechanneltopicjob.cpp +++ b/src/restapi/changechanneltopicjob.cpp @@ -1,49 +1,71 @@ /* Copyright (c) 2018 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "changechanneltopicjob.h" +#include "ruqola_restapi_debug.h" ChangeChannelTopicJob::ChangeChannelTopicJob(QObject *parent) : RestApiAbstractJob(parent) { } ChangeChannelTopicJob::~ChangeChannelTopicJob() { } bool ChangeChannelTopicJob::start() { + if (!canStart()) { + deleteLater(); + return false; + } //TODO return false; } bool ChangeChannelTopicJob::requireHttpAuthentication() const { return true; } bool ChangeChannelTopicJob::canStart() const { - //TODO - return false; + if (mTopic.isEmpty()) { + qCWarning(RUQOLA_RESTAPI_LOG) << "Topic is empty"; + return false; + } + if (!RestApiAbstractJob::canStart()) { + qCWarning(RUQOLA_RESTAPI_LOG) << "Impossible to start ChangeChannelTopicJob job"; + return false; + } + return true; +} + +QString ChangeChannelTopicJob::topic() const +{ + return mTopic; +} + +void ChangeChannelTopicJob::setTopic(const QString &topic) +{ + mTopic = topic; } diff --git a/src/restapi/changechanneltopicjob.h b/src/restapi/changechanneltopicjob.h index 1a3a19e2..61c0716a 100644 --- a/src/restapi/changechanneltopicjob.h +++ b/src/restapi/changechanneltopicjob.h @@ -1,42 +1,46 @@ /* Copyright (c) 2018 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef CHANGECHANNELTOPICJOB_H #define CHANGECHANNELTOPICJOB_H #include "restapiabstractjob.h" #include "libruqola_private_export.h" class LIBRUQOLACORE_TESTS_EXPORT ChangeChannelTopicJob : public RestApiAbstractJob { Q_OBJECT public: explicit ChangeChannelTopicJob(QObject *parent = nullptr); ~ChangeChannelTopicJob() override; bool start() override; bool requireHttpAuthentication() const override; bool canStart() const override; + QString topic() const; + void setTopic(const QString &topic); + private: Q_DISABLE_COPY(ChangeChannelTopicJob) + QString mTopic; }; #endif // CHANGECHANNELTOPICJOB_H diff --git a/src/restapi/getavatarjob.cpp b/src/restapi/getavatarjob.cpp index b7cdbde7..e9191704 100644 --- a/src/restapi/getavatarjob.cpp +++ b/src/restapi/getavatarjob.cpp @@ -1,102 +1,102 @@ /* Copyright (c) 2018 Montel Laurent This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License or ( at your option ) version 3 or, at the discretion of KDE e.V. ( which shall act as a proxy as in section 14 of the GPLv3 ), any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "getavatarjob.h" -#include "ruqola_ddpapi_debug.h" +#include "ruqola_restapi_debug.h" #include "restapimethod.h" #include #include #include GetAvatarJob::GetAvatarJob(QObject *parent) : RestApiAbstractJob(parent) { } GetAvatarJob::~GetAvatarJob() { } bool GetAvatarJob::canStart() const { if (mAvatarUserId.isEmpty()) { - qCWarning(RUQOLA_DDPAPI_LOG) << "Avatar userid is empty"; + qCWarning(RUQOLA_RESTAPI_LOG) << "Avatar userid is empty"; return false; } if (!RestApiAbstractJob::canStart()) { - qCWarning(RUQOLA_DDPAPI_LOG) << "Impossible to start getavatar job"; + qCWarning(RUQOLA_RESTAPI_LOG) << "Impossible to start getavatar job"; return false; } return true; } bool GetAvatarJob::start() { if (!canStart()) { deleteLater(); return false; } QNetworkReply *reply = mNetworkAccessManager->get(request()); connect(reply, &QNetworkReply::finished, this, &GetAvatarJob::slotGetAvatarInfo); addLoggerInfo("GetAvatarJob ask for avatarUserId: " + mAvatarUserId.toLatin1()); reply->setProperty("userId", mAvatarUserId); return true; } void GetAvatarJob::slotGetAvatarInfo() { QNetworkReply *reply = qobject_cast(sender()); if (reply) { const QByteArray data = reply->readAll(); //qCDebug(RUQOLA_RESTAPI_LOG) << "RestApiRequest::parseGetAvatar: " << data << " userId "<property("userId").toString(); Q_EMIT avatar(userId, str); } deleteLater(); } QNetworkRequest GetAvatarJob::request() const { QUrl url = mRestApiMethod->generateUrl(RestApiUtil::RestApiUrlType::UsersGetAvatar); QUrlQuery queryUrl; queryUrl.addQueryItem(QStringLiteral("userId"), mAvatarUserId); url.setQuery(queryUrl); QNetworkRequest request(url); return request; } bool GetAvatarJob::requireHttpAuthentication() const { return false; } QString GetAvatarJob::avatarUserId() const { return mAvatarUserId; } void GetAvatarJob::setAvatarUserId(const QString &avatarUserId) { mAvatarUserId = avatarUserId; }