File indexing completed on 2025-02-02 04:51:34
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 "userssetpreferencesjobtest.h" 0008 #include "ruqola_restapi_helper.h" 0009 #include "users/userssetpreferencesjob.h" 0010 #include <QJsonDocument> 0011 QTEST_GUILESS_MAIN(UsersSetPreferencesJobTest) 0012 using namespace RocketChatRestApi; 0013 UsersSetPreferencesJobTest::UsersSetPreferencesJobTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void UsersSetPreferencesJobTest::shouldHaveDefaultValue() 0019 { 0020 UsersSetPreferencesJob job; 0021 QVERIFY(!job.usersSetPreferencesInfo().isValid()); 0022 verifyDefaultValue(&job); 0023 QVERIFY(job.requireHttpAuthentication()); 0024 QVERIFY(!job.hasQueryParameterSupport()); 0025 } 0026 0027 void UsersSetPreferencesJobTest::shouldGenerateRequest() 0028 { 0029 UsersSetPreferencesJob job; 0030 QNetworkRequest request = QNetworkRequest(QUrl()); 0031 verifyAuthentication(&job, request); 0032 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/users.setPreferences"))); 0033 QCOMPARE(request.header(QNetworkRequest::ContentTypeHeader).toString(), QStringLiteral("application/json")); 0034 } 0035 0036 void UsersSetPreferencesJobTest::shouldGenerateJson() 0037 { 0038 { 0039 UsersSetPreferencesJob job; 0040 UsersSetPreferencesJob::UsersSetPreferencesInfo info; 0041 const QString desktopNotifications = QStringLiteral("Bla"); 0042 info.desktopNotifications = desktopNotifications; 0043 job.setUsersSetPreferencesInfo(info); 0044 QVERIFY(!job.canStart()); 0045 0046 const QString userId = QStringLiteral("foo"); 0047 info.userId = userId; 0048 job.setUsersSetPreferencesInfo(info); 0049 QCOMPARE(job.json().toJson(QJsonDocument::Compact), 0050 QStringLiteral(R"({"data":{"desktopNotifications":"%2"},"userId":"%1"})").arg(userId, desktopNotifications).toLatin1()); 0051 } 0052 } 0053 0054 void UsersSetPreferencesJobTest::shouldNotStarting() 0055 { 0056 UsersSetPreferencesJob job; 0057 0058 RestApiMethod method; 0059 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0060 job.setRestApiMethod(&method); 0061 0062 QNetworkAccessManager mNetworkAccessManager; 0063 job.setNetworkAccessManager(&mNetworkAccessManager); 0064 QVERIFY(!job.canStart()); 0065 const QString auth = QStringLiteral("foo"); 0066 const QString userId = QStringLiteral("foo"); 0067 job.setAuthToken(auth); 0068 QVERIFY(!job.canStart()); 0069 job.setUserId(userId); 0070 QVERIFY(!job.canStart()); 0071 UsersSetPreferencesJob::UsersSetPreferencesInfo info; 0072 info.desktopNotifications = QStringLiteral("Bla"); 0073 job.setUsersSetPreferencesInfo(info); 0074 QVERIFY(!job.canStart()); 0075 0076 info.userId = QStringLiteral("foo"); 0077 job.setUsersSetPreferencesInfo(info); 0078 QVERIFY(job.canStart()); 0079 } 0080 0081 #include "moc_userssetpreferencesjobtest.cpp"