diff options
Diffstat (limited to 'tests/maildirresourcetest.cpp')
-rw-r--r-- | tests/maildirresourcetest.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/maildirresourcetest.cpp b/tests/maildirresourcetest.cpp index 6d78242..968abde 100644 --- a/tests/maildirresourcetest.cpp +++ b/tests/maildirresourcetest.cpp | |||
@@ -466,6 +466,64 @@ private slots: | |||
466 | QVERIFY(!result2.errorCode()); | 466 | QVERIFY(!result2.errorCode()); |
467 | } | 467 | } |
468 | 468 | ||
469 | void testEditMail() | ||
470 | { | ||
471 | using namespace Sink; | ||
472 | using namespace Sink::ApplicationDomain; | ||
473 | |||
474 | auto query = Query::ResourceFilter("org.kde.maildir.instance1"); | ||
475 | Store::synchronize(query).exec().waitForFinished(); | ||
476 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
477 | |||
478 | Folder f; | ||
479 | |||
480 | auto result = Store::fetchOne<Folder>( | ||
481 | Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("name", "maildir1") + Query::RequestedProperties(QByteArrayList() << "name")) | ||
482 | .then<void, KAsync::Job<void>, Folder>([query, &f](const Folder &folder) { | ||
483 | f = folder; | ||
484 | return Store::fetchAll<Mail>(Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", folder) + | ||
485 | Query::RequestedProperties(QByteArrayList() << "folder" | ||
486 | << "subject" << "mimeMessage")) | ||
487 | .then<void, KAsync::Job<void>, QList<Mail::Ptr>>([query](const QList<Mail::Ptr> &mails) { | ||
488 | ASYNCCOMPARE(mails.size(), 1); | ||
489 | auto mail = mails.first(); | ||
490 | auto message = KMime::Message::Ptr::create(); | ||
491 | message->subject(true)->fromUnicodeString("Test1", "utf8"); | ||
492 | message->assemble(); | ||
493 | mail->setMimeMessage(message->encodedContent()); | ||
494 | return Store::modify(*mail); | ||
495 | }); | ||
496 | }) | ||
497 | .exec(); | ||
498 | result.waitForFinished(); | ||
499 | QVERIFY(!result.errorCode()); | ||
500 | |||
501 | ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); | ||
502 | |||
503 | // Verify that we can still query for all relevant information | ||
504 | auto result2 = Store::fetchAll<Mail>( | ||
505 | Query::ResourceFilter("org.kde.maildir.instance1") + Query::PropertyFilter("folder", f) + Query::RequestedProperties(QByteArrayList() << "folder" | ||
506 | << "subject" | ||
507 | << "mimeMessage" | ||
508 | << "unread")) | ||
509 | .then<void, KAsync::Job<void>, QList<Mail::Ptr>>([](const QList<Mail::Ptr> &mails) { | ||
510 | ASYNCCOMPARE(mails.size(), 1); | ||
511 | auto mail = mails.first(); | ||
512 | ASYNCCOMPARE(mail->getProperty("subject").toString(), QString("Test1")); | ||
513 | ASYNCVERIFY(QFileInfo(mail->getMimeMessagePath()).exists()); | ||
514 | return KAsync::null<void>(); | ||
515 | }) | ||
516 | .exec(); | ||
517 | result2.waitForFinished(); | ||
518 | QVERIFY(!result2.errorCode()); | ||
519 | |||
520 | //Ensure we didn't leave a stale message behind | ||
521 | auto targetPath = tempDir.path() + "/maildir1/cur"; | ||
522 | QDir dir(targetPath); | ||
523 | dir.setFilter(QDir::Files); | ||
524 | QTRY_COMPARE(dir.count(), static_cast<unsigned int>(1)); | ||
525 | } | ||
526 | |||
469 | void testCreateDraft() | 527 | void testCreateDraft() |
470 | { | 528 | { |
471 | Sink::Query query; | 529 | Sink::Query query; |