diff --git a/autotests/postmessagejobtest.cpp b/autotests/postmessagejobtest.cpp index 50b132b1..bf65e43d 100644 --- a/autotests/postmessagejobtest.cpp +++ b/autotests/postmessagejobtest.cpp @@ -1,59 +1,87 @@ /* 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 "postmessagejobtest.h" #include "restapi/chat/postmessagejob.h" #include "ruqola_restapi_helper.h" #include #include QTEST_GUILESS_MAIN(PostMessageJobTest) PostMessageJobTest::PostMessageJobTest(QObject *parent) : QObject(parent) { } void PostMessageJobTest::shouldHaveDefaultValue() { PostMessageJob job; verifyDefaultValue(&job); QVERIFY(job.requireHttpAuthentication()); QVERIFY(job.roomId().isEmpty()); QVERIFY(job.text().isEmpty()); } void PostMessageJobTest::shouldGenerateRequest() { PostMessageJob job; QNetworkRequest request = QNetworkRequest(QUrl()); verifyAuthentication(&job, request); QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/chat.postMessage"))); QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); } void PostMessageJobTest::shouldGenerateJson() { PostMessageJob job; const QString roomId = QStringLiteral("foo1"); const QString text = QStringLiteral("topic1"); job.setRoomId(roomId); job.setText(text); QCOMPARE(job.json().toJson(QJsonDocument::Compact), QStringLiteral("{\"roomId\":\"%1\",\"text\":\"%2\"}").arg(roomId).arg(text).toLatin1()); } + +void PostMessageJobTest::shouldNotStarting() +{ + PostMessageJob job; + + RestApiMethod *method = new RestApiMethod; + method->setServerUrl(QStringLiteral("http://www.kde.org")); + job.setRestApiMethod(method); + + QNetworkAccessManager *mNetworkAccessManager = new QNetworkAccessManager; + job.setNetworkAccessManager(mNetworkAccessManager); + QVERIFY(!job.canStart()); + const QString auth = QStringLiteral("foo"); + const QString userId = QStringLiteral("foo"); + job.setAuthToken(auth); + QVERIFY(!job.canStart()); + job.setUserId(userId); + QVERIFY(!job.canStart()); + const QString roomId = QStringLiteral("foo1"); + job.setRoomId(roomId); + QVERIFY(!job.canStart()); + const QString text = QStringLiteral("topic1"); + job.setText(text); + QVERIFY(job.canStart()); + + delete method; + delete mNetworkAccessManager; +} diff --git a/autotests/postmessagejobtest.h b/autotests/postmessagejobtest.h index 10f46a2f..f454ef86 100644 --- a/autotests/postmessagejobtest.h +++ b/autotests/postmessagejobtest.h @@ -1,38 +1,39 @@ /* 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 POSTMESSAGEJOBTEST_H #define POSTMESSAGEJOBTEST_H #include class PostMessageJobTest : public QObject { Q_OBJECT public: explicit PostMessageJobTest(QObject *parent = nullptr); ~PostMessageJobTest() = default; private Q_SLOTS: void shouldHaveDefaultValue(); void shouldGenerateRequest(); void shouldGenerateJson(); + void shouldNotStarting(); }; #endif // POSTMESSAGEJOBTEST_H