File indexing completed on 2024-12-01 04:35:27

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 "roleinfotest.h"
0008 #include "roles/roleinfo.h"
0009 #include "ruqola_autotest_helper.h"
0010 
0011 QTEST_GUILESS_MAIN(RoleInfoTest)
0012 RoleInfoTest::RoleInfoTest(QObject *parent)
0013     : QObject(parent)
0014 {
0015 }
0016 
0017 void RoleInfoTest::shouldHaveDefaultValues()
0018 {
0019     RoleInfo w;
0020     QVERIFY(w.name().isEmpty());
0021     QVERIFY(w.identifier().isEmpty());
0022     QVERIFY(w.scope().isEmpty());
0023     QVERIFY(w.description().isEmpty());
0024     QVERIFY(!w.roleProtected());
0025 }
0026 
0027 void RoleInfoTest::shouldLoadRoles_data()
0028 {
0029     QTest::addColumn<QString>("name");
0030     QTest::addColumn<RoleInfo>("role");
0031     {
0032         RoleInfo r;
0033         r.setMandatory2fa(false);
0034         r.setRoleProtected(true);
0035         r.setName(QStringLiteral("app"));
0036         r.setScope(QStringLiteral("Users"));
0037         r.setIdentifier(QStringLiteral("app"));
0038 
0039         QTest::addRow("roleinfo1") << QStringLiteral("roleinfo1") << r;
0040     }
0041     {
0042         RoleInfo r;
0043         r.setMandatory2fa(false);
0044         r.setRoleProtected(true);
0045         r.setDescription(QStringLiteral("Livechat Manager"));
0046         r.setName(QStringLiteral("livechat-manager"));
0047         r.setScope(QStringLiteral("Users"));
0048         r.setIdentifier(QStringLiteral("livechat-manager"));
0049 
0050         QTest::addRow("roleinfo2") << QStringLiteral("roleinfo2") << r;
0051     }
0052 }
0053 
0054 void RoleInfoTest::shouldLoadRoles()
0055 {
0056     QFETCH(QString, name);
0057     QFETCH(RoleInfo, role);
0058     const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/rolesinfo/") + name + QLatin1String(".json");
0059     const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile);
0060 
0061     RoleInfo r;
0062     r.parseRoleInfo(obj);
0063     QCOMPARE(r, role);
0064 }
0065 
0066 #include "moc_roleinfotest.cpp"