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/attachmentclient.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 Q_UNUSED(path) 0028 Q_UNUSED(query) 0029 Q_ASSERT_X(false, "get", qUtf8Printable(QStringLiteral("unmapped: %1; %2").arg(path, query.toString()))); 0030 return nullptr; 0031 } 0032 0033 [[nodiscard]] APIJob *post(const QString &path, const QByteArray &data, const Query &query = Query()) const override 0034 { 0035 Q_UNUSED(query); 0036 if (path == "/bug/1/attachment") { 0037 QJsonParseError error; 0038 QJsonDocument::fromJson(data, &error); 0039 Q_ASSERT(error.error == QJsonParseError::NoError); 0040 return new JobDouble{QFINDTESTDATA("data/attachment.new.json")}; 0041 } 0042 Q_ASSERT_X(false, "post", qUtf8Printable(QStringLiteral("unmapped: %1; %2").arg(path, query.toString()))); 0043 return nullptr; 0044 } 0045 0046 [[nodiscard]] APIJob *put(const QString &path, const QByteArray &, const Query &query = Query()) const override 0047 { 0048 Q_UNUSED(path) 0049 Q_UNUSED(query) 0050 Q_ASSERT_X(false, "put", qUtf8Printable(QStringLiteral("unmapped: %1; %2").arg(path, query.toString()))); 0051 return nullptr; 0052 } 0053 }; 0054 0055 class AttachmentTest : public QObject 0056 { 0057 Q_OBJECT 0058 private Q_SLOTS: 0059 0060 void initTestCase() 0061 { 0062 Bugzilla::setConnection(m_doubleConnection); 0063 } 0064 0065 void testCreate() 0066 { 0067 Bugzilla::AttachmentClient c; 0068 NewAttachment attachment; 0069 attachment.ids = {1}; 0070 attachment.data = "123"; 0071 attachment.file_name = "filename123"; 0072 attachment.summary = "summary123"; 0073 // attachment.content_type = "123"; 0074 attachment.comment = "comment123"; 0075 attachment.is_patch = true; 0076 attachment.is_private = false; 0077 auto job = c.createAttachment(1, attachment); 0078 job->start(); 0079 QList<int> ids = c.createAttachment(job); 0080 QCOMPARE(ids, QList<int>({1234})); 0081 } 0082 0083 private: 0084 Bugzilla::ConnectionDouble *m_doubleConnection = new Bugzilla::ConnectionDouble; 0085 }; 0086 0087 } // namespace Bugzilla 0088 0089 QTEST_MAIN(Bugzilla::AttachmentTest) 0090 0091 #include "attachmenttest.moc"