File indexing completed on 2024-06-02 05:06:53

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 "deleteownaccountjobtest.h"
0008 #include "ruqola_restapi_helper.h"
0009 #include "users/deleteownaccountjob.h"
0010 #include <QJsonDocument>
0011 QTEST_GUILESS_MAIN(DeleteOwnAccountJobTest)
0012 using namespace RocketChatRestApi;
0013 DeleteOwnAccountJobTest::DeleteOwnAccountJobTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void DeleteOwnAccountJobTest::shouldHaveDefaultValue()
0019 {
0020     DeleteOwnAccountJob job;
0021     verifyDefaultValue(&job);
0022     QVERIFY(job.requireHttpAuthentication());
0023     QVERIFY(job.password().isEmpty());
0024     QVERIFY(!job.hasQueryParameterSupport());
0025 }
0026 
0027 void DeleteOwnAccountJobTest::shouldGenerateRequest()
0028 {
0029     DeleteOwnAccountJob job;
0030     QNetworkRequest request = QNetworkRequest(QUrl());
0031     verifyAuthentication(&job, request);
0032     QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.deleteOwnAccount")));
0033     QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json"));
0034 }
0035 
0036 void DeleteOwnAccountJobTest::shouldGenerateJson()
0037 {
0038     DeleteOwnAccountJob job;
0039     const QString password = QStringLiteral("foo1");
0040     job.setPassword(password);
0041     QCOMPARE(job.json().toJson(QJsonDocument::Compact),
0042              QStringLiteral(R"({"password":"bb4eca334f61af3b67b5d528907d30285151610200539302f4c8cabe66225b53"})").toLatin1());
0043 }
0044 
0045 void DeleteOwnAccountJobTest::shouldNotStarting()
0046 {
0047     DeleteOwnAccountJob job;
0048 
0049     RestApiMethod method;
0050     method.setServerUrl(QStringLiteral("http://www.kde.org"));
0051     job.setRestApiMethod(&method);
0052 
0053     QNetworkAccessManager mNetworkAccessManager;
0054     job.setNetworkAccessManager(&mNetworkAccessManager);
0055     QVERIFY(!job.canStart());
0056     const QString auth = QStringLiteral("foo");
0057     const QString userId = QStringLiteral("foo");
0058     job.setAuthToken(auth);
0059     QVERIFY(!job.canStart());
0060     job.setUserId(userId);
0061     QVERIFY(!job.canStart());
0062     const QString password = QStringLiteral("foo1");
0063     job.setPassword(password);
0064     QVERIFY(job.canStart());
0065 }
0066 
0067 #include "moc_deleteownaccountjobtest.cpp"