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 "permissiontest.h" 0008 #include "permissions/permission.h" 0009 #include "ruqola_autotest_helper.h" 0010 0011 QTEST_GUILESS_MAIN(PermissionTest) 0012 PermissionTest::PermissionTest(QObject *parent) 0013 : QObject(parent) 0014 { 0015 } 0016 0017 void PermissionTest::shouldHaveDefaultValues() 0018 { 0019 Permission p; 0020 QVERIFY(p.roles().isEmpty()); 0021 QVERIFY(p.rolesStr().isEmpty()); 0022 QCOMPARE(p.updatedAt(), -1); 0023 QVERIFY(p.identifier().isEmpty()); 0024 } 0025 0026 void PermissionTest::shouldLoadPermission_data() 0027 { 0028 QTest::addColumn<QString>("name"); 0029 QTest::addColumn<Permission>("permission"); 0030 0031 { 0032 Permission p; 0033 p.setIdentifier(QStringLiteral("pin-message")); 0034 p.setRoles({QStringLiteral("owner"), QStringLiteral("moderator"), QStringLiteral("admin"), QStringLiteral("global-moderator")}); 0035 p.setUpdatedAt(1634615770401); 0036 QTest::addRow("permission1") << QStringLiteral("permission1") << p; 0037 } 0038 { 0039 Permission p; 0040 p.setIdentifier(QStringLiteral("create-c")); 0041 p.setRoles({QStringLiteral("admin"), QStringLiteral("user"), QStringLiteral("bot"), QStringLiteral("app")}); 0042 p.setUpdatedAt(1634615770401); 0043 QTest::addRow("permission2") << QStringLiteral("permission2") << p; 0044 } 0045 } 0046 0047 void PermissionTest::shouldLoadPermission() 0048 { 0049 QFETCH(QString, name); 0050 QFETCH(Permission, permission); 0051 const QString originalJsonFile = QLatin1String(RUQOLA_DATA_DIR) + QLatin1String("/permission/") + name + QLatin1String(".json"); 0052 const QJsonObject obj = AutoTestHelper::loadJsonObject(originalJsonFile); 0053 0054 Permission r; 0055 r.parsePermission(obj); 0056 // qDebug() << " r " << r << " permission " << permission; 0057 QCOMPARE(r, permission); 0058 } 0059 0060 #include "moc_permissiontest.cpp"