summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-03-15 16:51:55 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-03-15 16:51:55 +0100
commitdd240d06dc35c50239dec91dcf043f8d4c990953 (patch)
treeaf968c6c61b30ac6b383ac8e92f5bef81f71933d
parent8318b29b81d9a98fc5ad5fe1550f6d7a46ca7296 (diff)
downloadkube-dd240d06dc35c50239dec91dcf043f8d4c990953.tar.gz
kube-dd240d06dc35c50239dec91dcf043f8d4c990953.zip
Fixed and tested maildirsettings.
-rw-r--r--accounts/maildir/maildirsettings.cpp49
-rw-r--r--accounts/maildir/tests/settingstest.cpp42
2 files changed, 64 insertions, 27 deletions
diff --git a/accounts/maildir/maildirsettings.cpp b/accounts/maildir/maildirsettings.cpp
index c8b892d7..1d48fc24 100644
--- a/accounts/maildir/maildirsettings.cpp
+++ b/accounts/maildir/maildirsettings.cpp
@@ -105,7 +105,10 @@ void MaildirSettings::save()
105 if (!mIdentifier.isEmpty()) { 105 if (!mIdentifier.isEmpty()) {
106 Sink::ApplicationDomain::SinkResource resource(mIdentifier); 106 Sink::ApplicationDomain::SinkResource resource(mIdentifier);
107 resource.setProperty("path", mPath); 107 resource.setProperty("path", mPath);
108 Sink::Store::modify(resource).exec(); 108 Sink::Store::modify(resource).then<void>([](){}, [](int errorCode, const QString &errorMessage) {
109 qWarning() << "Error while modifying resource: " << errorMessage;
110 })
111 .exec();
109 } else { 112 } else {
110 const auto resourceIdentifier = "org.kde.maildir." + QUuid::createUuid().toByteArray(); 113 const auto resourceIdentifier = "org.kde.maildir." + QUuid::createUuid().toByteArray();
111 mIdentifier = resourceIdentifier; 114 mIdentifier = resourceIdentifier;
@@ -114,31 +117,39 @@ void MaildirSettings::save()
114 resource.setProperty("path", property("path")); 117 resource.setProperty("path", property("path"));
115 resource.setProperty("identifier", resourceIdentifier); 118 resource.setProperty("identifier", resourceIdentifier);
116 resource.setProperty("type", "org.kde.maildir"); 119 resource.setProperty("type", "org.kde.maildir");
117 Sink::Store::create(resource).exec(); 120 Sink::Store::create(resource).then<void>([this, resourceIdentifier]() {
118 Q_ASSERT(!mAccountIdentifier.isEmpty()); 121 Q_ASSERT(!mAccountIdentifier.isEmpty());
119 Kube::Account account(mAccountIdentifier); 122 Kube::Account account(mAccountIdentifier);
120 account.setProperty("maildirResource", resourceIdentifier); 123 account.setProperty("maildirResource", resourceIdentifier);
121 account.save(); 124 account.save();
122 //TODO deal with errors while creating 125 },
126 [](int errorCode, const QString &errorMessage) {
127 qWarning() << "Error while creating resource: " << errorMessage;
128 })
129 .exec();
123 } 130 }
124} 131}
125 132
126void MaildirSettings::remove() 133void MaildirSettings::remove()
127{ 134{
128 if (!mIdentifier.isEmpty()) { 135 if (mIdentifier.isEmpty()) {
129 qWarning() << "We're missing an identifier"; 136 qWarning() << "We're missing an identifier";
130 } else { 137 } else {
131 Sink::ApplicationDomain::SinkResource resource(mIdentifier); 138 Sink::ApplicationDomain::SinkResource resource("", mIdentifier, 0, QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create());
132 Sink::Store::remove(resource).exec(); 139 Sink::Store::remove(resource).then<void>([this]() {
133 Kube::Account account(mAccountIdentifier); 140 Kube::Account account(mAccountIdentifier);
134 account.remove(); 141 account.remove();
135 142
136 Kube::Settings settings("accounts"); 143 Kube::Settings settings("accounts");
137 auto accounts = settings.property("accounts").toStringList(); 144 auto accounts = settings.property("accounts").toStringList();
138 accounts.removeAll(mAccountIdentifier); 145 accounts.removeAll(mAccountIdentifier);
139 settings.setProperty("accounts", accounts); 146 settings.setProperty("accounts", accounts);
140 settings.save(); 147 settings.save();
141 //TODO deal with errors while removing 148 },
149 [](int errorCode, const QString &errorMessage) {
150 qWarning() << "Error while removing resource: " << errorMessage;
151 })
152 .exec();
142 } 153 }
143} 154}
144 155
diff --git a/accounts/maildir/tests/settingstest.cpp b/accounts/maildir/tests/settingstest.cpp
index d9983028..af1a35b4 100644
--- a/accounts/maildir/tests/settingstest.cpp
+++ b/accounts/maildir/tests/settingstest.cpp
@@ -1,6 +1,11 @@
1#include <QtTest> 1#include <QTest>
2#include <QDebug> 2#include <QDebug>
3#include <QSignalSpy>
3#include <functional> 4#include <functional>
5#include <QStandardPaths>
6#include <QDir>
7#include <sink/test.h>
8#include <sink/store.h>
4 9
5#include "maildirsettings.h" 10#include "maildirsettings.h"
6 11
@@ -11,9 +16,7 @@ private slots:
11 16
12 void initTestCase() 17 void initTestCase()
13 { 18 {
14 // Sink::FacadeFactory::instance().resetFactory(); 19 Sink::Test::initTest();
15 // ResourceConfig::clear();
16 // Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
17 } 20 }
18 21
19 void testLoad() 22 void testLoad()
@@ -26,10 +29,33 @@ private slots:
26 settings.setPath(maildirPath); 29 settings.setPath(maildirPath);
27 settings.save(); 30 settings.save();
28 31
29 //TODO ensure the maildir resource has been created 32 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query()).then<void, QList<Sink::ApplicationDomain::SinkResource>>([](const QList<Sink::ApplicationDomain::SinkResource> &resources) {
30 //TODO ensure the path has been setup correctly 33 QCOMPARE(resources.size(), 1);
31 //Ensure we can read the configuration correctly 34 })
32 //Ensure we can remove the account again 35 .exec().waitForFinished();
36
37 //Ensure we can read back all the information using the accountid
38 {
39 MaildirSettings readSettings;
40 QSignalSpy spy(&readSettings, &MaildirSettings::pathChanged);
41 readSettings.setAccountIdentifier(accountId);
42 QTRY_VERIFY(spy.count());
43 QVERIFY(!readSettings.identifier().isEmpty());
44 QCOMPARE(readSettings.path().toString(), maildirPath);
45 }
46
47 {
48 MaildirSettings settings;
49 QSignalSpy spy(&settings, &MaildirSettings::pathChanged);
50 settings.setAccountIdentifier(accountId);
51 QTRY_VERIFY(spy.count());
52 settings.remove();
53 }
54
55 Sink::Store::fetchAll<Sink::ApplicationDomain::SinkResource>(Sink::Query()).then<void, QList<Sink::ApplicationDomain::SinkResource>>([](const QList<Sink::ApplicationDomain::SinkResource> &resources) {
56 QCOMPARE(resources.size(), 0);
57 })
58 .exec().waitForFinished();
33 } 59 }
34}; 60};
35 61