51 lines
1.4 KiB
C++
51 lines
1.4 KiB
C++
#include "Types.h"
|
|
|
|
#include <QTest>
|
|
|
|
using namespace Qt::StringLiterals;
|
|
|
|
class TypesTest final : public QObject {
|
|
Q_OBJECT
|
|
|
|
private slots:
|
|
void parsesShareUrl();
|
|
void rejectsNonShareUrl();
|
|
void plansByChecksum();
|
|
};
|
|
|
|
void TypesTest::parsesShareUrl()
|
|
{
|
|
QString error;
|
|
const auto endpoint = ShareEndpoint::fromUserInput(
|
|
u"https://photos.example.test/immich/share/summer-2026?ignored=yes"_s, u"secret"_s, &error);
|
|
QCOMPARE(error, QString{});
|
|
QCOMPARE(endpoint.apiRoot, QUrl{u"https://photos.example.test/immich/api"_s});
|
|
QCOMPARE(endpoint.credential, u"summer-2026"_s);
|
|
QCOMPARE(endpoint.password, u"secret"_s);
|
|
}
|
|
|
|
void TypesTest::rejectsNonShareUrl()
|
|
{
|
|
QString error;
|
|
const auto endpoint = ShareEndpoint::fromUserInput(u"file:///tmp/share/key"_s, {}, &error);
|
|
QVERIFY(!error.isEmpty());
|
|
QVERIFY(endpoint.apiRoot.isEmpty());
|
|
}
|
|
|
|
void TypesTest::plansByChecksum()
|
|
{
|
|
ShareInfo left;
|
|
left.assets = {{u"1"_s, u"same"_s}, {u"2"_s, u"left-only"_s}, {u"3"_s, {}}};
|
|
ShareInfo right;
|
|
right.assets = {{u"4"_s, u"same"_s}, {u"5"_s, u"right-only"_s}};
|
|
|
|
const auto plan = buildSyncPlan(left, right);
|
|
QCOMPARE(plan.leftToRight.size(), 1);
|
|
QCOMPARE(plan.leftToRight.front().id, u"2"_s);
|
|
QCOMPARE(plan.rightToLeft.size(), 1);
|
|
QCOMPARE(plan.rightToLeft.front().id, u"5"_s);
|
|
}
|
|
|
|
QTEST_MAIN(TypesTest)
|
|
#include "TypesTest.moc"
|