Commit 6b017655 authored by Volker Krause's avatar Volker Krause
Browse files

Run trips added from journey queries through post-processing

This fills in missing country and timezone information, which we rely on
in a few places. This makes manually and imported trips behave the same
in that regard.
parent dfdc41e2
......@@ -16,6 +16,7 @@
#include <QtTest/qtest.h>
#include <QStandardPaths>
#include <QTimeZone>
using namespace KItinerary;
......@@ -25,7 +26,7 @@ class PublicTransportTest : public QObject
private Q_SLOTS:
void initTestCase()
{
qputenv("TZ", "UTC");
qputenv("TZ", "Europe/Zurich");
QStandardPaths::setTestModeEnabled(true);
}
......@@ -80,6 +81,10 @@ private Q_SLOTS:
QCOMPARE(newTrip.departureTime(), section.scheduledDepartureTime());
QCOMPARE(newTrip.arrivalTime(), section.scheduledArrivalTime());
// times have correct timezones now (while input was in local time)
QCOMPARE(newTrip.departureTime().timeSpec(), Qt::TimeZone);
QCOMPARE(newTrip.departureTime().timeZone().id(), "Europe/Zurich");
// old line name parts need to be cleared
QCOMPARE(newTrip.trainName(), QString());
QCOMPARE(newTrip.trainNumber(), QLatin1String("R 342"));
......@@ -98,6 +103,9 @@ private Q_SLOTS:
QCOMPARE(newArr.name(), section.to().name());
QVERIFY(!newArr.geo().isValid());
// locations got country data assigned
QCOMPARE(newDep.address().addressCountry(), QLatin1String("CH"));
// ticket token is preserved, but seat reservation is cleared
const auto newTicket = newRes.reservedTicket().value<Ticket>();
QCOMPARE(newTicket.ticketToken(), ticket.ticketToken());
......
......@@ -9,6 +9,7 @@
#include "logging.h"
#include <KItinerary/BusTrip>
#include <KItinerary/ExtractorPostprocessor>
#include <KItinerary/Reservation>
#include <KItinerary/TrainTrip>
#include <KItinerary/Ticket>
......@@ -254,14 +255,25 @@ static KItinerary::BusReservation applyJourneySection(KItinerary::BusReservation
return res;
}
static QVariant postProcessOne(const QVariant &res)
{
KItinerary::ExtractorPostprocessor postProc;
postProc.process({res});
const auto result = postProc.result();
if (result.size() == 1) {
return result.at(0);
}
return res;
}
QVariant PublicTransport::reservationFromJourneySection(const KPublicTransport::JourneySection &section)
{
using namespace KItinerary;
if (isTrainMode(section.route().line().mode())) {
return ::applyJourneySection(TrainReservation(), section);
return postProcessOne(::applyJourneySection(TrainReservation(), section));
}
if (isBusMode(section.route().line().mode())) {
return ::applyJourneySection(BusReservation(), section);
return postProcessOne(::applyJourneySection(BusReservation(), section));
}
qCWarning(Log) << "Unsupported section type:" << section.route().line().mode();
......@@ -273,10 +285,10 @@ QVariant PublicTransport::applyJourneySection(const QVariant &res, const KPublic
using namespace KItinerary;
if (JsonLd::isA<TrainReservation>(res)) {
return ::applyJourneySection(res.value<TrainReservation>(), section);
return postProcessOne(::applyJourneySection(res.value<TrainReservation>(), section));
}
if (JsonLd::isA<BusReservation>(res)) {
return ::applyJourneySection(res.value<BusReservation>(), section);
return postProcessOne(::applyJourneySection(res.value<BusReservation>(), section));
}
qCWarning(Log) << res.typeName() << "Unsupported section type!";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment