File indexing completed on 2024-05-12 16:59:02
0001 /* 0002 SPDX-FileCopyrightText: 2019 Harald Sitter <sitter@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include <QDebug> 0008 #include <QTest> 0009 0010 #include <clients/productclient.h> 0011 0012 #include "jobdouble.h" 0013 0014 namespace Bugzilla 0015 { 0016 class ConnectionDouble : public Connection 0017 { 0018 public: 0019 using Connection::Connection; 0020 0021 void setToken(const QString &) override 0022 { 0023 Q_UNREACHABLE(); 0024 } 0025 0026 [[nodiscard]] APIJob *get(const QString &path, const Query &query = Query()) const override 0027 { 0028 Q_UNUSED(path); 0029 Q_UNUSED(query); 0030 if (path == "/product/dragonplayer") { 0031 return new JobDouble{QFINDTESTDATA("data/product.dragonplayer.json")}; 0032 } 0033 Q_ASSERT_X(false, "get", qUtf8Printable(QStringLiteral("unmapped: %1; %2").arg(path, query.toString()))); 0034 return nullptr; 0035 } 0036 0037 [[nodiscard]] APIJob *post(const QString &path, const QByteArray &, const Query &query = Query()) const override 0038 { 0039 qDebug() << path << query.toString(); 0040 Q_UNREACHABLE(); 0041 return nullptr; 0042 } 0043 0044 [[nodiscard]] APIJob *put(const QString &, const QByteArray &, const Query & = Query()) const override 0045 { 0046 Q_UNREACHABLE(); 0047 } 0048 }; 0049 0050 class ProductTest : public QObject 0051 { 0052 Q_OBJECT 0053 private Q_SLOTS: 0054 void initTestCase() 0055 { 0056 Bugzilla::setConnection(m_doubleConnection); 0057 } 0058 0059 void testProduct() 0060 { 0061 KJob *job = Bugzilla::ProductClient().get("dragonplayer"); 0062 Q_ASSERT(job); 0063 job->start(); 0064 Product::Ptr product = Bugzilla::ProductClient().get(job); 0065 0066 QCOMPARE(product->isActive(), true); 0067 QCOMPARE(product->componentNames(), QStringList({"general"})); 0068 QCOMPARE(product->allVersions(), 0069 QStringList({"2.0", "2.0-beta1", "2.0-git", "2.0.x", "17.04", "17.08", "17.12", "18.04", "18.08", "18.12", "SVN", "unspecified"})); 0070 QCOMPARE(product->inactiveVersions(), QStringList({"2.0", "2.0-beta1", "2.0-git", "2.0.x", "SVN"})); 0071 0072 QCOMPARE(product->versions().size(), 12); 0073 { // inactive version 0074 auto version = product->versions()[0]; 0075 QCOMPARE(version->id(), 4408); 0076 QCOMPARE(version->name(), "2.0"); 0077 QCOMPARE(version->isActive(), false); 0078 } 0079 { // active version 0080 auto version = product->versions()[11]; 0081 QCOMPARE(version->id(), 3239); 0082 QCOMPARE(version->name(), "unspecified"); 0083 QCOMPARE(version->isActive(), true); 0084 } 0085 0086 QCOMPARE(product->components().size(), 1); 0087 auto component = product->components()[0]; 0088 QCOMPARE(component->id(), 1200); 0089 QCOMPARE(component->name(), "general"); 0090 } 0091 0092 private: 0093 Bugzilla::ConnectionDouble *m_doubleConnection = new Bugzilla::ConnectionDouble; 0094 }; 0095 0096 } // namespace Bugzilla 0097 0098 QTEST_MAIN(Bugzilla::ProductTest) 0099 0100 #include "producttest.moc"