summaryrefslogtreecommitdiffstats
path: root/tests/teststore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/teststore.cpp')
-rw-r--r--tests/teststore.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/teststore.cpp b/tests/teststore.cpp
index 6a5304ad..902014cd 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,65 @@ static void createFolder(const QVariantMap &object)
124 }); 129 });
125} 130}
126 131
132static 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 if (object.contains("uid")) {
142 auto uid = object["uid"].toString();
143 sinkEvent.setUid(uid);
144 calcoreEvent->setUid(uid);
145 } else {
146 auto uid = QUuid::createUuid().toString();
147 sinkEvent.setUid(uid);
148 calcoreEvent->setUid(uid);
149 }
150
151 auto summary = object["summary"].toString();
152 sinkEvent.setSummary(summary);
153 calcoreEvent->setSummary(summary);
154
155 if (object.contains("description")) {
156 auto description = object["description"].toString();
157 sinkEvent.setDescription(description);
158 calcoreEvent->setDescription(description);
159 }
160
161 auto startTime = object["starts"].toDateTime();
162 auto endTime = object["ends"].toDateTime();
163 sinkEvent.setStartTime(startTime);
164 sinkEvent.setEndTime(endTime);
165
166 calcoreEvent->setDtStart(startTime);
167 calcoreEvent->setDtEnd(endTime);
168
169 auto ical = KCalCore::ICalFormat().toRawString(static_cast<QSharedPointer<KCalCore::Incidence>>(calcoreEvent));
170 sinkEvent.setIcal(ical);
171
172 sinkEvent.setCalendar(calendarId);
173
174 Sink::Store::create(sinkEvent).exec().waitForFinished();
175}
176
177static void createCalendar(const QVariantMap &object)
178{
179 using Sink::ApplicationDomain::Calendar;
180 using Sink::ApplicationDomain::ApplicationDomainType;
181
182 auto calendar = ApplicationDomainType::createEntity<Calendar>(object["resource"].toByteArray());
183 calendar.setName(object["name"].toString());
184 Sink::Store::create(calendar).exec().waitForFinished();
185
186 auto calendarId = calendar.identifier();
187 iterateOverObjects(object.value("events").toList(),
188 [calendarId](const QVariantMap &object) { createEvent(object, calendarId); });
189}
190
127void TestStore::setup(const QVariantMap &map) 191void TestStore::setup(const QVariantMap &map)
128{ 192{
129 using namespace Sink::ApplicationDomain; 193 using namespace Sink::ApplicationDomain;
@@ -143,6 +207,9 @@ void TestStore::setup(const QVariantMap &map)
143 } else if (object["type"] == "mailtransport") { 207 } else if (object["type"] == "mailtransport") {
144 resource.setResourceType("sink.mailtransport"); 208 resource.setResourceType("sink.mailtransport");
145 resource.setProperty("testmode", true); 209 resource.setProperty("testmode", true);
210 } else if (object["type"] == "caldav") {
211 resource.setResourceType("sink.caldav");
212 resource.setProperty("testmode", true);
146 } else { 213 } else {
147 Q_ASSERT(false); 214 Q_ASSERT(false);
148 } 215 }
@@ -166,6 +233,8 @@ void TestStore::setup(const QVariantMap &map)
166 createMail(map); 233 createMail(map);
167 }); 234 });
168 235
236 iterateOverObjects(map.value("calendars").toList(), createCalendar);
237
169 Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished(); 238 Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished();
170} 239}
171 240