diff options
author | Rémi Nicole <nicole@kolabsystems.com> | 2018-04-17 10:33:10 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-04-17 10:33:23 +0200 |
commit | be495877931f1f811f46a442e175e2ee53949a29 (patch) | |
tree | 9354741b032e29f8a68fc99f3841b73228edf660 /tests/teststore.cpp | |
parent | 8e2f9664da95dee0ca55a9129e02d298a826f18e (diff) | |
download | kube-be495877931f1f811f46a442e175e2ee53949a29.tar.gz kube-be495877931f1f811f46a442e175e2ee53949a29.zip |
Add calendar support in the Test Store
Summary: Fixes T8483
Reviewers: cmollekopf
Reviewed By: cmollekopf
Tags: #kube
Maniphest Tasks: T8483
Differential Revision: https://phabricator.kde.org/D12087
Diffstat (limited to 'tests/teststore.cpp')
-rw-r--r-- | tests/teststore.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/teststore.cpp b/tests/teststore.cpp index 6a5304ad..3a60676d 100644 --- a/tests/teststore.cpp +++ b/tests/teststore.cpp | |||
@@ -21,9 +21,14 @@ | |||
21 | #include <sink/store.h> | 21 | #include <sink/store.h> |
22 | #include <sink/resourcecontrol.h> | 22 | #include <sink/resourcecontrol.h> |
23 | #include <sink/secretstore.h> | 23 | #include <sink/secretstore.h> |
24 | |||
24 | #include <kmime/kmime_message.h> | 25 | #include <kmime/kmime_message.h> |
25 | 26 | ||
27 | #include <KCalCore/Event> | ||
28 | #include <KCalCore/ICalFormat> | ||
29 | |||
26 | #include <QDebug> | 30 | #include <QDebug> |
31 | #include <QUuid> | ||
27 | #include <QVariant> | 32 | #include <QVariant> |
28 | 33 | ||
29 | #include "framework/src/domain/mime/mailtemplates.h" | 34 | #include "framework/src/domain/mime/mailtemplates.h" |
@@ -124,6 +129,59 @@ static void createFolder(const QVariantMap &object) | |||
124 | }); | 129 | }); |
125 | } | 130 | } |
126 | 131 | ||
132 | static void createEvent(const QVariantMap &object, const QByteArray &calendarId = {}) | ||
133 | { | ||
134 | using Sink::ApplicationDomain::ApplicationDomainType; | ||
135 | using Sink::ApplicationDomain::Event; | ||
136 | |||
137 | auto sinkEvent = ApplicationDomainType::createEntity<Event>(object["resource"].toByteArray()); | ||
138 | |||
139 | auto calcoreEvent = QSharedPointer<KCalCore::Event>::create(); | ||
140 | |||
141 | QString uid; | ||
142 | if (object.contains("uid")) { | ||
143 | uid = object["uid"].toString(); | ||
144 | } else { | ||
145 | uid = QUuid::createUuid().toString(); | ||
146 | } | ||
147 | calcoreEvent->setUid(uid); | ||
148 | |||
149 | auto summary = object["summary"].toString(); | ||
150 | calcoreEvent->setSummary(summary); | ||
151 | |||
152 | if (object.contains("description")) { | ||
153 | auto description = object["description"].toString(); | ||
154 | calcoreEvent->setDescription(description); | ||
155 | } | ||
156 | |||
157 | auto startTime = object["starts"].toDateTime(); | ||
158 | auto endTime = object["ends"].toDateTime(); | ||
159 | |||
160 | calcoreEvent->setDtStart(startTime); | ||
161 | calcoreEvent->setDtEnd(endTime); | ||
162 | |||
163 | auto ical = KCalCore::ICalFormat().toICalString(calcoreEvent); | ||
164 | sinkEvent.setIcal(ical.toUtf8()); | ||
165 | |||
166 | sinkEvent.setCalendar(calendarId); | ||
167 | |||
168 | Sink::Store::create(sinkEvent).exec().waitForFinished(); | ||
169 | } | ||
170 | |||
171 | static void createCalendar(const QVariantMap &object) | ||
172 | { | ||
173 | using Sink::ApplicationDomain::Calendar; | ||
174 | using Sink::ApplicationDomain::ApplicationDomainType; | ||
175 | |||
176 | auto calendar = ApplicationDomainType::createEntity<Calendar>(object["resource"].toByteArray()); | ||
177 | calendar.setName(object["name"].toString()); | ||
178 | Sink::Store::create(calendar).exec().waitForFinished(); | ||
179 | |||
180 | auto calendarId = calendar.identifier(); | ||
181 | iterateOverObjects(object.value("events").toList(), | ||
182 | [calendarId](const QVariantMap &object) { createEvent(object, calendarId); }); | ||
183 | } | ||
184 | |||
127 | void TestStore::setup(const QVariantMap &map) | 185 | void TestStore::setup(const QVariantMap &map) |
128 | { | 186 | { |
129 | using namespace Sink::ApplicationDomain; | 187 | using namespace Sink::ApplicationDomain; |
@@ -143,6 +201,9 @@ void TestStore::setup(const QVariantMap &map) | |||
143 | } else if (object["type"] == "mailtransport") { | 201 | } else if (object["type"] == "mailtransport") { |
144 | resource.setResourceType("sink.mailtransport"); | 202 | resource.setResourceType("sink.mailtransport"); |
145 | resource.setProperty("testmode", true); | 203 | resource.setProperty("testmode", true); |
204 | } else if (object["type"] == "caldav") { | ||
205 | resource.setResourceType("sink.caldav"); | ||
206 | resource.setProperty("testmode", true); | ||
146 | } else { | 207 | } else { |
147 | Q_ASSERT(false); | 208 | Q_ASSERT(false); |
148 | } | 209 | } |
@@ -166,6 +227,8 @@ void TestStore::setup(const QVariantMap &map) | |||
166 | createMail(map); | 227 | createMail(map); |
167 | }); | 228 | }); |
168 | 229 | ||
230 | iterateOverObjects(map.value("calendars").toList(), createCalendar); | ||
231 | |||
169 | Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished(); | 232 | Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished(); |
170 | } | 233 | } |
171 | 234 | ||