Commit 6270236c authored by Volker Krause's avatar Volker Krause
Browse files

Add unit test for pass updates

parent a2276d31
......@@ -45,15 +45,24 @@ private slots:
QSignalSpy addSpy(&mgr, &PkPassManager::passAdded);
QVERIFY(addSpy.isValid());
QSignalSpy updateSpy(&mgr, &PkPassManager::passUpdated);
QVERIFY(updateSpy.isValid());
QVERIFY(mgr.passes().isEmpty());
mgr.importPass(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/boardingpass.pkpass")));
mgr.importPass(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/boardingpass-v1.pkpass")));
QCOMPARE(addSpy.size(), 1);
QCOMPARE(addSpy.at(0).at(0).toString(), QLatin1String("pass.booking.kde.org/MTIzNA=="));
QVERIFY(updateSpy.isEmpty());
auto passes = mgr.passes();
QCOMPARE(passes.size(), 1);
QCOMPARE(passes.at(0), QLatin1String("pass.booking.kde.org/MTIzNA=="));
mgr.importPass(QUrl::fromLocalFile(QLatin1String(SOURCE_DIR "/data/boardingpass-v2.pkpass")));
QCOMPARE(addSpy.size(), 1);
QCOMPARE(updateSpy.size(), 1);
QCOMPARE(mgr.passes().size(), 1);
QCOMPARE(updateSpy.at(0).at(0).toString(), QLatin1String("pass.booking.kde.org/MTIzNA=="));
}
};
......
......@@ -32,7 +32,7 @@ private slots:
void testBoardingPass()
{
std::unique_ptr<KPkPass::Pass> pass(KPkPass::Pass::fromFile(QLatin1String(SOURCE_DIR "/data/boardingpass.pkpass")));
std::unique_ptr<KPkPass::Pass> pass(KPkPass::Pass::fromFile(QLatin1String(SOURCE_DIR "/data/boardingpass-v1.pkpass")));
QVERIFY(pass);
QCOMPARE(pass->type(), KPkPass::Pass::BoardingPass);
......
......@@ -58,11 +58,16 @@ QVector<QString> PkPassManager::passes() const
KPkPass::Pass* PkPassManager::pass(const QString& passId)
{
const auto it = m_passes.constFind(passId);
if (it != m_passes.constEnd())
if (it != m_passes.constEnd() && it.value()) {
return it.value();
}
const auto basePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/passes/");
auto file = KPkPass::Pass::fromFile(basePath + passId + QLatin1String(".pkpass"), this);
const QString passPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/passes/") + passId + QLatin1String(".pkpass");
if (!QFile::exists(passPath)) {
return nullptr;
}
auto file = KPkPass::Pass::fromFile(passPath, this);
// TODO error handling
m_passes.insert(passId, file);
return file;
......
Markdown is supported
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