diff --git a/framework/src/domain/invitationcontroller.cpp b/framework/src/domain/invitationcontroller.cpp index 46cf89f0..45a02ecf 100644 --- a/framework/src/domain/invitationcontroller.cpp +++ b/framework/src/domain/invitationcontroller.cpp @@ -1,98 +1,100 @@ /* * Copyright (C) 2017 Michael Bohlender, * Copyright (C) 2018 Christian Mollekopf, * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "invitationcontroller.h" #include #include #include #include #include #include using namespace Sink::ApplicationDomain; InvitationController::InvitationController() : EventController(), action_accept{new Kube::ControllerAction{this, &InvitationController::accept}}, action_decline{new Kube::ControllerAction{this, &InvitationController::decline}} { } void InvitationController::loadICal(const QString &ical) { auto icalEvent = KCalCore::ICalFormat().readIncidence(ical.toUtf8()).dynamicCast(); if(!icalEvent) { SinkWarning() << "Invalid ICal to process, ignoring..."; return; } - setUid(icalEvent->uid()); + setState(InvitationState::Unknown); + + setUid(icalEvent->uid().toUtf8()); setSummary(icalEvent->summary()); setDescription(icalEvent->description()); setLocation(icalEvent->location()); setStart(icalEvent->dtStart()); setEnd(icalEvent->dtEnd()); setAllDay(icalEvent->allDay()); } void InvitationController::accept() { using namespace Sink; using namespace Sink::ApplicationDomain; const auto calendar = getCalendar(); if (!calendar) { qWarning() << "No calendar selected"; return; } auto calcoreEvent = QSharedPointer::create(); calcoreEvent->setUid(getUid()); calcoreEvent->setSummary(getSummary()); calcoreEvent->setDescription(getDescription()); calcoreEvent->setLocation(getLocation()); calcoreEvent->setDtStart(getStart()); calcoreEvent->setDtEnd(getEnd()); calcoreEvent->setAllDay(getAllDay()); Event event(calendar->resourceInstanceIdentifier()); event.setIcal(KCalCore::ICalFormat().toICalString(calcoreEvent).toUtf8()); event.setCalendar(*calendar); auto job = Store::create(event) .then([&] (const KAsync::Error &error) { if (error) { SinkWarning() << "Failed to save the event: " << error; } emit done(); }); run(job); //TODO sendIMipMessage(calcoreEvent); } void InvitationController::decline() { } diff --git a/framework/src/domain/invitationcontroller.h b/framework/src/domain/invitationcontroller.h index 2c98144b..3fd583e1 100644 --- a/framework/src/domain/invitationcontroller.h +++ b/framework/src/domain/invitationcontroller.h @@ -1,44 +1,53 @@ /* * Copyright (C) 2017 Michael Bohlender, * Copyright (C) 2018 Christian Mollekopf, * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #pragma once #include "kube_export.h" #include #include #include #include "eventcontroller.h" class KUBE_EXPORT InvitationController : public EventController { Q_OBJECT +public: + enum InvitationState { + Unknown, + Accepted, + Declined, + }; + Q_ENUM(InvitationState); + KUBE_CONTROLLER_PROPERTY(QByteArray, Uid, uid) + KUBE_CONTROLLER_PROPERTY(InvitationState, State, state) KUBE_CONTROLLER_ACTION(accept) KUBE_CONTROLLER_ACTION(decline) public: explicit InvitationController(); Q_INVOKABLE void loadICal(const QString &message); }; diff --git a/framework/src/tests/CMakeLists.txt b/framework/src/tests/CMakeLists.txt index f13103bf..f95effdf 100644 --- a/framework/src/tests/CMakeLists.txt +++ b/framework/src/tests/CMakeLists.txt @@ -1,42 +1,27 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ) find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Core Test Gui) -add_executable(folderlistmodeltest folderlistmodeltest.cpp) -add_test(folderlistmodeltest folderlistmodeltest) -target_link_libraries(folderlistmodeltest - Qt5::Core - Qt5::Test - Qt5::Gui - kubeframework -) - -add_executable(maillistmodeltest maillistmodeltest.cpp) -add_test(maillistmodeltest maillistmodeltest) -target_link_libraries(maillistmodeltest - Qt5::Core - Qt5::Test - Qt5::Gui - kubeframework -) - -add_executable(eventoccurrencemodeltest eventoccurrencemodeltest.cpp) -add_test(eventoccurrencemodeltest eventoccurrencemodeltest) -target_link_libraries(eventoccurrencemodeltest - Qt5::Core - Qt5::Test - Qt5::Gui - kubeframework -) +macro(auto_tests) + foreach(_testname ${ARGN}) + add_executable(${_testname} ${_testname}.cpp) + add_test(${_testname} ${_testname}) + target_link_libraries(${_testname} + Qt5::Core + Qt5::Test + Qt5::Gui + kubeframework + ) + endforeach(_testname) +endmacro(auto_tests) -add_executable(entitymodeltest entitymodeltest.cpp) -add_test(entitymodeltest entitymodeltest) -target_link_libraries(entitymodeltest - Qt5::Core - Qt5::Test - Qt5::Gui - kubeframework +auto_tests( + folderlistmodeltest + maillistmodeltest + eventoccurrencemodeltest + entitymodeltest + invitationcontrollertest ) diff --git a/framework/src/tests/invitationcontrollertest.cpp b/framework/src/tests/invitationcontrollertest.cpp new file mode 100644 index 00000000..4dac9f86 --- /dev/null +++ b/framework/src/tests/invitationcontrollertest.cpp @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include "invitationcontroller.h" + +using namespace Sink::ApplicationDomain; + + +class InvitationControllerTest : public QObject +{ + Q_OBJECT + + QByteArray resourceId; + + QString createInvitation(const QByteArray &uid) + { + auto calcoreEvent = QSharedPointer::create(); + calcoreEvent->setUid(uid); + calcoreEvent->setSummary("summary"); + calcoreEvent->setDescription("description"); + calcoreEvent->setLocation("location"); + calcoreEvent->setDtStart(QDateTime::currentDateTime()); + + return KCalCore::ICalFormat{}.createScheduleMessage(calcoreEvent, KCalCore::iTIPRequest); + } + + +private slots: + void initTestCase() + { + Sink::Test::initTest(); + + auto account = ApplicationDomainType::createEntity(); + Sink::Store::create(account).exec().waitForFinished(); + + auto resource = DummyResource::create(account.identifier()); + Sink::Store::create(resource).exec().waitForFinished(); + resourceId = resource.identifier(); + } + + void testAccept() + { + + + auto calendar = ApplicationDomainType::createEntity(resourceId); + Sink::Store::create(calendar).exec().waitForFinished(); + + QByteArray uid{"uid1"}; + const QString ical = createInvitation(uid); + + { + InvitationController controller; + controller.loadICal(ical); + + controller.setCalendar(ApplicationDomainType::Ptr::create(calendar)); + + QTRY_COMPARE(controller.getState(), InvitationController::Unknown); + + controller.acceptAction()->execute(); + + QTRY_COMPARE(Sink::Store::read(Sink::Query{}.filter(calendar)).size(), 1); + + auto list = Sink::Store::read(Sink::Query{}.filter(calendar)); + QCOMPARE(list.size(), 1); + } + + // { + // InvitationController controller; + // controller.loadICal(ical); + // QTRY_COMPARE(controller.state(), InvitationController::Accepted); + // QTRY_COMPARE(controller.uid(), eventUid); + // } + } +}; + +QTEST_MAIN(InvitationControllerTest) +#include "invitationcontrollertest.moc"