From 97fa1912a004c144ffb1392a6bfd0469e6047e3f Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 15 Jan 2016 11:45:34 +0100 Subject: Test markMailAsRead with all the new KAsync::Job stuff --- tests/maildirresourcetest.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp index 3e07d93..c649536 100644 --- a/tests/maildirresourcetest.cpp +++ b/tests/maildirresourcetest.cpp @@ -327,6 +327,49 @@ private Q_SLOTS: QTRY_COMPARE(QDir(tempDir.path() + "/maildir1/cur", QString(), QDir::NoSort, QDir::Files).count(), static_cast(0)); } + void testMarkMailAsRead() + { + using namespace Akonadi2; + using namespace Akonadi2::ApplicationDomain; + + auto query = Query::ResourceFilter("org.kde.maildir.instance1"); + Akonadi2::Store::synchronize(query).exec().waitForFinished(); + Akonadi2::Store::flushMessageQueue(query.resources).exec().waitForFinished(); + + auto result = Store::fetchOne( + Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name") + ) + .then, Folder>([query](const Folder &folder) { + return Store::fetchAll( + Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject") + ) + .then, QList >([](const QList &mails) -> KAsync::Job { + //Can't use QCOMPARE because it tries to return + if (mails.size() != 1) { + return KAsync::error(1, "Wrong number of mails."); + } + auto mail = mails.first(); + mail->setProperty("unread", true); + return Akonadi2::Store::modify(*mail); + }) + .then(Akonadi2::Store::flushMessageQueue(query.resources)) + .then >([folder]() -> KAsync::Job { + return Store::fetchAll( + Query::PropertyFilter("folder", folder) + Query::RequestedProperties(QByteArrayList() << "folder" << "subject" << "unread") + ) + .then >([](const QList &mails) { + QCOMPARE(mails.size(), 1); + auto mail = mails.first(); + QCOMPARE(mail->getProperty("unread").toBool(), true); + }) + .then([](){}); + }); + }) + .exec(); + result.waitForFinished(); + QVERIFY(!result.errorCode()); + } + }; QTEST_MAIN(MaildirResourceTest) -- cgit v1.2.3