summaryrefslogtreecommitdiffstats
path: root/tests/accountstest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/accountstest.cpp')
-rw-r--r--tests/accountstest.cpp45
1 files changed, 37 insertions, 8 deletions
diff --git a/tests/accountstest.cpp b/tests/accountstest.cpp
index be5e1a0..4be8bd6 100644
--- a/tests/accountstest.cpp
+++ b/tests/accountstest.cpp
@@ -8,6 +8,7 @@
8#include <store.h> 8#include <store.h>
9#include <log.h> 9#include <log.h>
10#include <configstore.h> 10#include <configstore.h>
11#include "testutils.h"
11 12
12class AccountsTest : public QObject 13class AccountsTest : public QObject
13{ 14{
@@ -17,7 +18,6 @@ private slots:
17 void initTestCase() 18 void initTestCase()
18 { 19 {
19 Sink::Test::initTest(); 20 Sink::Test::initTest();
20 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
21 } 21 }
22 22
23 void init() 23 void init()
@@ -52,7 +52,7 @@ private slots:
52 QString smtpUsername("smtpUsername"); 52 QString smtpUsername("smtpUsername");
53 QString smtpPassword("smtpPassword"); 53 QString smtpPassword("smtpPassword");
54 auto resource = ApplicationDomainType::createEntity<SinkResource>(); 54 auto resource = ApplicationDomainType::createEntity<SinkResource>();
55 resource.setProperty("type", "org.kde.mailtransport"); 55 resource.setProperty("type", "sink.mailtransport");
56 resource.setProperty("account", account.identifier()); 56 resource.setProperty("account", account.identifier());
57 resource.setProperty("server", smtpServer); 57 resource.setProperty("server", smtpServer);
58 resource.setProperty("username", smtpUsername); 58 resource.setProperty("username", smtpUsername);
@@ -63,7 +63,7 @@ private slots:
63 Store::fetchAll<SinkResource>(Query()).then<void, QList<SinkResource::Ptr>>([&](const QList<SinkResource::Ptr> &resources) { 63 Store::fetchAll<SinkResource>(Query()).then<void, QList<SinkResource::Ptr>>([&](const QList<SinkResource::Ptr> &resources) {
64 QCOMPARE(resources.size(), 1); 64 QCOMPARE(resources.size(), 1);
65 auto resource = resources.first(); 65 auto resource = resources.first();
66 QCOMPARE(resource->getProperty("type").toString(), QString("org.kde.mailtransport")); 66 QCOMPARE(resource->getProperty("type").toString(), QString("sink.mailtransport"));
67 QCOMPARE(resource->getProperty("server").toString(), smtpServer); 67 QCOMPARE(resource->getProperty("server").toString(), smtpServer);
68 }) 68 })
69 .exec().waitForFinished(); 69 .exec().waitForFinished();
@@ -94,8 +94,8 @@ private slots:
94 using namespace Sink::ApplicationDomain; 94 using namespace Sink::ApplicationDomain;
95 95
96 auto account = ApplicationDomainType::createEntity<SinkAccount>(); 96 auto account = ApplicationDomainType::createEntity<SinkAccount>();
97 account.setProperty("type", "maildir"); 97 account.setAccountType("maildir");
98 account.setProperty("name", "name"); 98 account.setName("name");
99 Store::create(account).exec().waitForFinished(); 99 Store::create(account).exec().waitForFinished();
100 100
101 Query query; 101 Query query;
@@ -104,18 +104,47 @@ private slots:
104 QTRY_COMPARE(model->rowCount(QModelIndex()), 1); 104 QTRY_COMPARE(model->rowCount(QModelIndex()), 1);
105 105
106 auto account2 = ApplicationDomainType::createEntity<SinkAccount>(); 106 auto account2 = ApplicationDomainType::createEntity<SinkAccount>();
107 account2.setProperty("type", "maildir"); 107 account2.setAccountType("maildir");
108 account2.setProperty("name", "name"); 108 account2.setName("name");
109 Store::create(account2).exec().waitForFinished(); 109 Store::create(account2).exec().waitForFinished();
110 QTRY_COMPARE(model->rowCount(QModelIndex()), 2); 110 QTRY_COMPARE(model->rowCount(QModelIndex()), 2);
111 111
112 //Ensure the notifier only affects one type 112 //Ensure the notifier only affects one type
113 auto resource = ApplicationDomainType::createEntity<SinkResource>(); 113 auto resource = ApplicationDomainType::createEntity<SinkResource>();
114 resource.setProperty("type", "org.kde.mailtransport"); 114 resource.setResourceType("sink.mailtransport");
115 Store::create(resource).exec().waitForFinished(); 115 Store::create(resource).exec().waitForFinished();
116 QTRY_COMPARE(model->rowCount(QModelIndex()), 2); 116 QTRY_COMPARE(model->rowCount(QModelIndex()), 2);
117 } 117 }
118 118
119 void testLoadAccountStatus()
120 {
121 using namespace Sink;
122 using namespace Sink::ApplicationDomain;
123
124 auto account = ApplicationDomainType::createEntity<SinkAccount>();
125 account.setAccountType("dummy");
126 account.setName("name");
127 VERIFYEXEC(Store::create(account));
128
129 auto res = Sink::ApplicationDomain::DummyResource::create(account.identifier());
130 VERIFYEXEC(Sink::Store::create(res));
131 {
132 Sink::Query query;
133 query.liveQuery = true;
134 query.request<Sink::ApplicationDomain::SinkAccount::Status>();
135
136 auto model = Sink::Store::loadModel<Sink::ApplicationDomain::SinkAccount>(query);
137 QTRY_COMPARE(model->rowCount(QModelIndex()), 1);
138 auto account = model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::SinkAccount::Ptr>();
139 QCOMPARE(account->getStatus(), static_cast<int>(Sink::ApplicationDomain::OfflineStatus));
140
141 //Synchronize to connect
142 VERIFYEXEC(Sink::Store::synchronize(Query::ResourceFilter(res)));
143
144 QTRY_COMPARE_WITH_TIMEOUT(model->data(model->index(0, 0, QModelIndex()), Sink::Store::DomainObjectRole).value<Sink::ApplicationDomain::SinkAccount::Ptr>()->getStatus(), static_cast<int>(Sink::ApplicationDomain::ConnectedStatus), 1000);
145 }
146 }
147
119}; 148};
120 149
121QTEST_GUILESS_MAIN(AccountsTest) 150QTEST_GUILESS_MAIN(AccountsTest)