Page MenuHomePhorge

matrix-room-timeline-test.cpp
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

matrix-room-timeline-test.cpp

/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <libkazv-config.hpp>
#include <immer/config.hpp> // https://github.com/arximboldi/immer/issues/168
#include <memory>
#include <QtTest>
#include <factory.hpp>
#include <matrix-room-timeline.hpp>
#include <matrix-sdk.hpp>
#include <matrix-room-list.hpp>
#include <matrix-room.hpp>
#include <matrix-event.hpp>
#include <matrix-event-reader-list-model.hpp>
#include <matrix-event-reader.hpp>
#include "test-model.hpp"
#include "test-utils.hpp"
using namespace Kazv;
using namespace Kazv::Factory;
class MatrixRoomTimelineTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testLocalEcho();
void testReadReceipts();
};
void MatrixRoomTimelineTest::testLocalEcho()
{
auto model = makeTestModel();
std::unique_ptr<MatrixSdk> sdk{makeTestSdk(model)};
auto roomList = toUniquePtr(sdk->roomList());
auto room = toUniquePtr(roomList->room("!foo:tusooa.xyz"));
auto timeline = toUniquePtr(room->timeline());
QCOMPARE(timeline->count(), 2);
auto first = toUniquePtr(timeline->at(1)); // reverse order
QCOMPARE(first->isSending(), true);
QCOMPARE(first->isLocalEcho(), true);
QCOMPARE(first->isFailed(), false);
QCOMPARE(first->txnId(), "some-txn-id");
auto second = toUniquePtr(timeline->at(0));
QCOMPARE(second->isSending(), false);
QCOMPARE(second->isLocalEcho(), true);
QCOMPARE(second->isFailed(), true);
QCOMPARE(second->txnId(), "some-other-txn-id");
}
void MatrixRoomTimelineTest::testReadReceipts()
{
auto r = makeRoom(withRoomTimeline({
makeEvent(withEventId("$1")),
makeEvent(withEventId("$2")),
}));
r.eventReadUsers = {{"$1", {"@a:example.com", "@b:example.com"}}};
r.readReceipts = {{"@a:example.com", {"$1", 1234}}, {"@b:example.com", {"$2", 5678}}};
auto model = SdkModel{makeClient(withRoom(r))};
std::unique_ptr<MatrixSdk> sdk{makeTestSdk(model)};
auto roomList = toUniquePtr(sdk->roomList());
auto room = toUniquePtr(roomList->room(QString::fromStdString(r.roomId)));
auto timeline = toUniquePtr(room->timeline());
{
auto event = toUniquePtr(timeline->at(1));
QCOMPARE(event->eventId(), "$1");
auto readers = toUniquePtr(event->readers());
QCOMPARE(readers->count(), 2);
auto reader1 = toUniquePtr(readers->at(0));
QCOMPARE(reader1->userId(), "@a:example.com");
QCOMPARE(reader1->timestamp(), 1234);
auto reader2 = toUniquePtr(readers->at(1));
QCOMPARE(reader2->userId(), "@b:example.com");
QCOMPARE(reader2->timestamp(), 5678);
}
{
auto event = toUniquePtr(timeline->at(0));
QCOMPARE(event->eventId(), "$2");
auto readers = toUniquePtr(event->readers());
QCOMPARE(readers->count(), 0);
}
}
QTEST_MAIN(MatrixRoomTimelineTest)
#include "matrix-room-timeline-test.moc"

File Metadata

Mime Type
text/x-c
Expires
Fri, Jul 18, 8:06 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
261465
Default Alt Text
matrix-room-timeline-test.cpp (2 KB)

Event Timeline