File indexing completed on 2024-06-02 05:06:52
0001 /* 0002 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "channelgetallusermentionsjobtest.h" 0008 #include "channels/channelgetallusermentionsjob.h" 0009 #include "restapimethod.h" 0010 #include "ruqola_restapi_helper.h" 0011 QTEST_GUILESS_MAIN(ChannelGetAllUserMentionsJobTest) 0012 using namespace RocketChatRestApi; 0013 ChannelGetAllUserMentionsJobTest::ChannelGetAllUserMentionsJobTest(QObject *parent) 0014 : QObject(parent) 0015 { 0016 } 0017 0018 void ChannelGetAllUserMentionsJobTest::shouldHaveDefaultValue() 0019 { 0020 ChannelGetAllUserMentionsJob job; 0021 QVERIFY(!job.restApiMethod()); 0022 QVERIFY(!job.networkAccessManager()); 0023 QVERIFY(!job.start()); 0024 QVERIFY(job.requireHttpAuthentication()); 0025 QVERIFY(job.roomId().isEmpty()); 0026 QVERIFY(!job.restApiLogger()); 0027 QVERIFY(job.hasQueryParameterSupport()); 0028 QVERIFY(!job.requireTwoFactorAuthentication()); 0029 } 0030 0031 void ChannelGetAllUserMentionsJobTest::shouldHaveParameterSupport() 0032 { 0033 ChannelGetAllUserMentionsJob job; 0034 RestApiMethod method; 0035 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0036 job.setRestApiMethod(&method); 0037 const QString roomId = QStringLiteral("avat"); 0038 job.setRoomId(roomId); 0039 QueryParameters parameters; 0040 parameters.setCount(5); 0041 parameters.setOffset(12); 0042 job.setQueryParameters(parameters); 0043 QNetworkRequest request = job.request(); 0044 verifyAuthentication(&job, request); 0045 QCOMPARE(request.url().toString(), QStringLiteral("http://www.kde.org/api/v1/channels.getAllUserMentionsByChannel?roomId=avat&count=5&offset=12")); 0046 } 0047 0048 void ChannelGetAllUserMentionsJobTest::shouldHaveParameterSupportSorting() 0049 { 0050 ChannelGetAllUserMentionsJob job; 0051 RestApiMethod method; 0052 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0053 job.setRestApiMethod(&method); 0054 const QString roomId = QStringLiteral("avat"); 0055 job.setRoomId(roomId); 0056 QueryParameters parameters; 0057 parameters.setCount(5); 0058 parameters.setOffset(12); 0059 0060 QMap<QString, QueryParameters::SortOrder> map; 0061 map.insert(QStringLiteral("foo"), QueryParameters::SortOrder::Descendant); 0062 parameters.setSorting(map); 0063 0064 job.setQueryParameters(parameters); 0065 QNetworkRequest request = job.request(); 0066 verifyAuthentication(&job, request); 0067 QCOMPARE(request.url().toString(), 0068 QStringLiteral("http://www.kde.org/api/v1/channels.getAllUserMentionsByChannel?roomId=avat&count=5&offset=12&sort=%7B%22foo%22:-1%7D")); 0069 } 0070 0071 void ChannelGetAllUserMentionsJobTest::shouldHaveParameterSupportSortingTwoParameters() 0072 { 0073 ChannelGetAllUserMentionsJob job; 0074 RestApiMethod method; 0075 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0076 job.setRestApiMethod(&method); 0077 const QString roomId = QStringLiteral("avat"); 0078 job.setRoomId(roomId); 0079 QueryParameters parameters; 0080 parameters.setCount(5); 0081 parameters.setOffset(12); 0082 0083 QMap<QString, QueryParameters::SortOrder> map; 0084 map.insert(QStringLiteral("foo"), QueryParameters::SortOrder::Descendant); 0085 map.insert(QStringLiteral("bla"), QueryParameters::SortOrder::Ascendant); 0086 parameters.setSorting(map); 0087 0088 job.setQueryParameters(parameters); 0089 QNetworkRequest request = job.request(); 0090 verifyAuthentication(&job, request); 0091 QCOMPARE( 0092 request.url().toString(), 0093 QStringLiteral("http://www.kde.org/api/v1/channels.getAllUserMentionsByChannel?roomId=avat&count=5&offset=12&sort=%7B%22bla%22:1,%22foo%22:-1%7D")); 0094 } 0095 0096 void ChannelGetAllUserMentionsJobTest::shouldGenerateRequest() 0097 { 0098 ChannelGetAllUserMentionsJob job; 0099 RestApiMethod method; 0100 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0101 job.setRestApiMethod(&method); 0102 const QString roomId = QStringLiteral("avat"); 0103 job.setRoomId(roomId); 0104 QNetworkRequest request = job.request(); 0105 verifyAuthentication(&job, request); 0106 QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/channels.getAllUserMentionsByChannel?roomId=avat"))); 0107 } 0108 0109 void ChannelGetAllUserMentionsJobTest::shouldNotStarting() 0110 { 0111 ChannelGetAllUserMentionsJob job; 0112 0113 RestApiMethod method; 0114 method.setServerUrl(QStringLiteral("http://www.kde.org")); 0115 job.setRestApiMethod(&method); 0116 0117 QNetworkAccessManager mNetworkAccessManager; 0118 job.setNetworkAccessManager(&mNetworkAccessManager); 0119 QVERIFY(!job.canStart()); 0120 const QString auth = QStringLiteral("foo"); 0121 const QString userId = QStringLiteral("foo"); 0122 job.setAuthToken(auth); 0123 QVERIFY(!job.canStart()); 0124 job.setUserId(userId); 0125 QVERIFY(!job.canStart()); 0126 const QString roomId = QStringLiteral("foo1"); 0127 job.setRoomId(roomId); 0128 QVERIFY(job.canStart()); 0129 } 0130 0131 #include "moc_channelgetallusermentionsjobtest.cpp"