File indexing completed on 2024-12-01 04:35:26
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 "ownusertest.h" 0008 #include "ownuser/ownuser.h" 0009 #include "ruqola_autotest_helper.h" 0010 #include <QJsonObject> 0011 0012 QTEST_GUILESS_MAIN(OwnUserTest) 0013 0014 OwnUserTest::OwnUserTest(QObject *parent) 0015 : QObject(parent) 0016 { 0017 } 0018 0019 void OwnUserTest::shouldHaveDefaultValues() 0020 { 0021 OwnUser user; 0022 QVERIFY(user.userId().isEmpty()); 0023 QVERIFY(user.userName().isEmpty()); 0024 QVERIFY(user.status().isEmpty()); 0025 QVERIFY(user.email().isEmpty()); 0026 QVERIFY(user.statusText().isEmpty()); 0027 QVERIFY(user.name().isEmpty()); 0028 QVERIFY(user.avatarUrl().isEmpty()); 0029 QVERIFY(user.nickName().isEmpty()); 0030 QCOMPARE(user.utcOffset(), 0.0); 0031 QVERIFY(user.statusDefault().isEmpty()); 0032 QVERIFY(user.roles().isEmpty()); 0033 0034 QVERIFY(!user.servicePassword().totp()); 0035 QVERIFY(!user.servicePassword().email2faEnabled()); 0036 QVERIFY(user.servicePassword().password().isEmpty()); 0037 } 0038 0039 void OwnUserTest::shouldLoadOwnUser_data() 0040 { 0041 QTest::addColumn<QString>("name"); 0042 QTest::addColumn<OwnUser>("ownuser"); 0043 OwnUser result; 0044 result.setUserId(QStringLiteral("YbwG4T2uB3wZSZSKB")); 0045 result.setStatus(QStringLiteral("online")); 0046 result.setUserName(QStringLiteral("foo-bla")); 0047 result.setEmail(QStringLiteral("bla@kde.org")); 0048 result.setName(QStringLiteral("foo-name")); 0049 result.setAvatarUrl(QStringLiteral("https://open.rocket.chat/avatar/fooblabla")); 0050 result.setStatusDefault(QStringLiteral("online")); 0051 result.setNickName(QStringLiteral("tests")); 0052 result.setRoles({QStringLiteral("user")}); 0053 result.setUtcOffset(2); 0054 ServicePassword pwd; 0055 pwd.setEmail2faEnabled(true); 0056 pwd.setTotp(false); 0057 pwd.setPassword(QStringLiteral("$2BNmO77i")); 0058 result.setServicePassword(pwd); 0059 0060 OwnUserPreferences ownUser; 0061 ownUser.setDesktopNotifications(QStringLiteral("all")); 0062 ownUser.setEmailNotificationMode(QStringLiteral("mentions")); 0063 ownUser.setIdleTimeLimit(300); 0064 ownUser.setEnableAutoAway(true); 0065 ownUser.setDisplayAvatars(false); 0066 ownUser.setShowFavorite(true); 0067 ownUser.setRoomListSortOrder(OwnUserPreferences::RoomListSortOrder::ByLastMessage); 0068 ownUser.setReceiveLoginDetectionEmail(true); 0069 result.setOwnUserPreferences(ownUser); 0070 0071 QTest::addRow("example1") << QStringLiteral("example1") << result; 0072 } 0073 0074 void OwnUserTest::shouldLoadOwnUser() 0075 { 0076 QFETCH(QString, name); 0077 QFETCH(OwnUser, ownuser); 0078 const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/ownuser/") + name + QLatin1String(".json"); 0079 const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile); 0080 0081 OwnUser r; 0082 r.parseOwnUserInfo(obj); 0083 const bool equalOwner = (r == ownuser); 0084 if (!equalOwner) { 0085 qDebug() << "ACTUAL " << r; 0086 qDebug() << "EXPECTED " << ownuser; 0087 } 0088 QVERIFY(equalOwner); 0089 } 0090 0091 #include "moc_ownusertest.cpp"