From 004a1a2e91c72f9b1b7ca964fe20cd6a1a6e68a6 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Tue, 10 Apr 2018 15:47:45 +0200 Subject: Add support for calendar in the teststore --- tests/teststore.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'tests/teststore.cpp') 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 @@ #include #include #include + #include +#include +#include + #include +#include #include #include "framework/src/domain/mime/mailtemplates.h" @@ -124,6 +129,65 @@ static void createFolder(const QVariantMap &object) }); } +static void createEvent(const QVariantMap &object, const QByteArray &calendarId = {}) +{ + using Sink::ApplicationDomain::ApplicationDomainType; + using Sink::ApplicationDomain::Event; + + auto sinkEvent = ApplicationDomainType::createEntity(object["resource"].toByteArray()); + + auto calcoreEvent = QSharedPointer::create(); + + if (object.contains("uid")) { + auto uid = object["uid"].toString(); + sinkEvent.setUid(uid); + calcoreEvent->setUid(uid); + } else { + auto uid = QUuid::createUuid().toString(); + sinkEvent.setUid(uid); + calcoreEvent->setUid(uid); + } + + auto summary = object["summary"].toString(); + sinkEvent.setSummary(summary); + calcoreEvent->setSummary(summary); + + if (object.contains("description")) { + auto description = object["description"].toString(); + sinkEvent.setDescription(description); + calcoreEvent->setDescription(description); + } + + auto startTime = object["starts"].toDateTime(); + auto endTime = object["ends"].toDateTime(); + sinkEvent.setStartTime(startTime); + sinkEvent.setEndTime(endTime); + + calcoreEvent->setDtStart(startTime); + calcoreEvent->setDtEnd(endTime); + + auto ical = KCalCore::ICalFormat().toRawString(static_cast>(calcoreEvent)); + sinkEvent.setIcal(ical); + + sinkEvent.setCalendar(calendarId); + + Sink::Store::create(sinkEvent).exec().waitForFinished(); +} + +static void createCalendar(const QVariantMap &object) +{ + using Sink::ApplicationDomain::Calendar; + using Sink::ApplicationDomain::ApplicationDomainType; + + auto calendar = ApplicationDomainType::createEntity(object["resource"].toByteArray()); + calendar.setName(object["name"].toString()); + Sink::Store::create(calendar).exec().waitForFinished(); + + auto calendarId = calendar.identifier(); + iterateOverObjects(object.value("events").toList(), + [calendarId](const QVariantMap &object) { createEvent(object, calendarId); }); +} + void TestStore::setup(const QVariantMap &map) { using namespace Sink::ApplicationDomain; @@ -143,6 +207,9 @@ void TestStore::setup(const QVariantMap &map) } else if (object["type"] == "mailtransport") { resource.setResourceType("sink.mailtransport"); resource.setProperty("testmode", true); + } else if (object["type"] == "caldav") { + resource.setResourceType("sink.caldav"); + resource.setProperty("testmode", true); } else { Q_ASSERT(false); } @@ -166,6 +233,8 @@ void TestStore::setup(const QVariantMap &map) createMail(map); }); + iterateOverObjects(map.value("calendars").toList(), createCalendar); + Sink::ResourceControl::flushMessageQueue(resources).exec().waitForFinished(); } -- cgit v1.2.3