File indexing completed on 2025-02-02 04:51:24

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "emojicustomalljobtest.h"
0008 #include "emoji/emojicustomalljob.h"
0009 #include "restapimethod.h"
0010 #include <QTest>
0011 QTEST_GUILESS_MAIN(EmojiCustomAllJobTest)
0012 using namespace RocketChatRestApi;
0013 EmojiCustomAllJobTest::EmojiCustomAllJobTest(QObject *parent)
0014     : QObject(parent)
0015 {
0016 }
0017 
0018 void EmojiCustomAllJobTest::shouldHaveDefaultValue()
0019 {
0020     EmojiCustomAllJob job;
0021     QVERIFY(!job.restApiMethod());
0022     QVERIFY(!job.networkAccessManager());
0023     QVERIFY(!job.start());
0024     QVERIFY(job.requireHttpAuthentication());
0025     QVERIFY(job.authToken().isEmpty());
0026     QVERIFY(job.authCode().isEmpty());
0027     QVERIFY(job.authMethod().isEmpty());
0028     QVERIFY(job.userId().isEmpty());
0029     QVERIFY(!job.restApiLogger());
0030     QVERIFY(job.hasQueryParameterSupport());
0031     QVERIFY(!job.requireTwoFactorAuthentication());
0032 }
0033 
0034 void EmojiCustomAllJobTest::shouldGenerateRequest()
0035 {
0036     {
0037         EmojiCustomAllJob job;
0038         const QString authToken = QStringLiteral("foo");
0039         const QString userId = QStringLiteral("user");
0040         job.setUserId(userId);
0041         job.setAuthToken(authToken);
0042         RestApiMethod method;
0043         method.setServerUrl(QStringLiteral("http://www.kde.org"));
0044         job.setRestApiMethod(&method);
0045         const QNetworkRequest request = job.request();
0046         QCOMPARE(request.url(), QUrl(QStringLiteral("http://www.kde.org/api/v1/emoji-custom.all")));
0047         QCOMPARE(request.rawHeader(QByteArrayLiteral("X-Auth-Token")), authToken.toLocal8Bit());
0048         QCOMPARE(request.rawHeader(QByteArrayLiteral("X-User-Id")), userId.toLocal8Bit());
0049     }
0050     {
0051         EmojiCustomAllJob job;
0052         const QString authToken = QStringLiteral("foo");
0053         const QString userId = QStringLiteral("user");
0054         job.setUserId(userId);
0055         job.setAuthToken(authToken);
0056         RestApiMethod method;
0057         method.setServerUrl(QStringLiteral("http://www.kde.org"));
0058         job.setRestApiMethod(&method);
0059 
0060         QMap<QString, RocketChatRestApi::QueryParameters::SortOrder> map;
0061         map.insert(QStringLiteral("name"), RocketChatRestApi::QueryParameters::SortOrder::Ascendant);
0062         RocketChatRestApi::QueryParameters parameters;
0063         parameters.setSorting(map);
0064         parameters.setOffset(1);
0065         parameters.setCount(3);
0066         parameters.setSearchString(QStringLiteral("bla"));
0067 
0068         job.setQueryParameters(parameters);
0069         const QNetworkRequest request = job.request();
0070         QCOMPARE(request.url().query(),
0071                  QStringLiteral("count=3&offset=1&query=%7B%22name%22:%7B%22$regex%22:%22bla%22,%22$options%22:%22i%22%7D%7D&sort=%7B%22name%22:1%7D"));
0072         QCOMPARE(request.rawHeader(QByteArrayLiteral("X-Auth-Token")), authToken.toLocal8Bit());
0073         QCOMPARE(request.rawHeader(QByteArrayLiteral("X-User-Id")), userId.toLocal8Bit());
0074     }
0075 }
0076 
0077 #include "moc_emojicustomalljobtest.cpp"