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 <QTest> 0008 0009 #include "../clients/commentclient.h" 0010 0011 #include "jobdouble.h" 0012 0013 namespace Bugzilla 0014 { 0015 class ConnectionDouble : public Connection 0016 { 0017 public: 0018 using Connection::Connection; 0019 0020 void setToken(const QString &) override 0021 { 0022 Q_UNREACHABLE(); 0023 } 0024 0025 [[nodiscard]] APIJob *get(const QString &path, const Query &query = Query()) const override 0026 { 0027 if (path == "/bug/407363/comment" && query.toString().isEmpty()) { 0028 return new JobDouble{QFINDTESTDATA("data/comments.json")}; 0029 } 0030 if (path == "/bug/1/comment" && query.toString().isEmpty()) { 0031 return new JobDouble{QFINDTESTDATA("data/error.nobug.invalid.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 Q_UNUSED(path); 0040 Q_UNUSED(query); 0041 Q_ASSERT_X(false, "post", qUtf8Printable(QStringLiteral("unmapped: %1; %2").arg(path, query.toString()))); 0042 return nullptr; 0043 } 0044 0045 [[nodiscard]] APIJob *put(const QString &path, const QByteArray &, const Query &query = Query()) const override 0046 { 0047 Q_UNUSED(path); 0048 Q_UNUSED(query); 0049 Q_ASSERT_X(false, "put", qUtf8Printable(QStringLiteral("unmapped: %1; %2").arg(path, query.toString()))); 0050 return nullptr; 0051 } 0052 }; 0053 0054 class CommentTest : public QObject 0055 { 0056 Q_OBJECT 0057 private Q_SLOTS: 0058 0059 void initTestCase() 0060 { 0061 Bugzilla::setConnection(m_doubleConnection); 0062 } 0063 0064 void testSearch() 0065 { 0066 Bugzilla::CommentClient c; 0067 auto job = c.getFromBug(407363); 0068 job->start(); 0069 auto comments = c.getFromBug(job); 0070 QCOMPARE(comments.size(), 3); 0071 0072 Comment::Ptr uno = comments[0]; 0073 QCOMPARE(uno->bug_id(), 407363); 0074 QCOMPARE(uno->text(), "uno"); 0075 0076 Comment::Ptr tre = comments[2]; 0077 QCOMPARE(tre->bug_id(), 407363); 0078 QCOMPARE(tre->text(), "tre"); 0079 } 0080 0081 void testSearchNoBugInvalid() 0082 { 0083 // Our bugzilla has a bug where errors do not have error:true! 0084 // Make sure we correctly handle objects that are errors but do not 0085 // necessarily have error:true. 0086 // This is particularly relevant for comments because we make 0087 // expectations about bugs being valid/invalid/throwing. 0088 Bugzilla::CommentClient c; 0089 auto job = c.getFromBug(1); 0090 job->start(); 0091 QVERIFY_EXCEPTION_THROWN(c.getFromBug(job), Bugzilla::APIException); 0092 } 0093 0094 private: 0095 Bugzilla::ConnectionDouble *m_doubleConnection = new Bugzilla::ConnectionDouble; 0096 }; 0097 0098 } // namespace Bugzilla 0099 0100 QTEST_MAIN(Bugzilla::CommentTest) 0101 0102 #include "commenttest.moc"