Changeset View
Changeset View
Standalone View
Standalone View
src/tests/client/storage-actions-test.cpp
- This file was added.
| /* | |||||
| * This file is part of libkazv. | |||||
| * SPDX-FileCopyrightText: 2025 tusooa <tusooa@kazv.moe> | |||||
| * SPDX-License-Identifier: AGPL-3.0-or-later | |||||
| */ | |||||
| #include <libkazv-config.hpp> | |||||
| #include "actions/storage.hpp" | |||||
| #include <catch2/catch_test_macros.hpp> | |||||
| #include <catch2/matchers/catch_matchers_quantifiers.hpp> | |||||
| #include <catch2/matchers/catch_matchers_predicate.hpp> | |||||
| #include <factory.hpp> | |||||
| using namespace Kazv; | |||||
| using namespace Kazv::Factory; | |||||
| using Catch::Matchers::AllMatch; | |||||
| using Catch::Matchers::Predicate; | |||||
| static const std::string roomId = "!test:example.com"; | |||||
| template<class T> | |||||
| static auto makeEventInRoom(T modifiers) | |||||
| { | |||||
| return makeEvent(withEventKV("/room_id"_json_pointer, roomId) | std::move(modifiers)); | |||||
| }; | |||||
| static auto makeEventInRoom() | |||||
| { | |||||
| return makeEvent(withEventKV("/room_id"_json_pointer, roomId)); | |||||
| }; | |||||
| TEST_CASE("LoadEventsFromStorageAction", "[client][storage-actions]") | |||||
| { | |||||
| auto existingEvents = EventList{ | |||||
| makeEventInRoom(), | |||||
| makeEventInRoom(), | |||||
| }; | |||||
| auto c = makeClient(withRoom(makeRoom(withRoomId(roomId) | withRoomTimeline(existingEvents)))); | |||||
| auto timelineEvents = EventList{ | |||||
| makeEventInRoom(), | |||||
| makeEventInRoom(), | |||||
| }; | |||||
| auto relatedEvents = EventList{ | |||||
| makeEventInRoom(withEventRelationship("moe.kazv.mxc.some-rel", timelineEvents[0].id())), | |||||
| makeEventInRoom(withEventRelationship("moe.kazv.mxc.other-rel", existingEvents[0].id())), | |||||
| }; | |||||
| auto [next, _] = updateClient(c, LoadEventsFromStorageAction{ | |||||
| {{roomId, timelineEvents}}, | |||||
| {{roomId, relatedEvents}}, | |||||
| }); | |||||
| { | |||||
| auto room = next.roomList.rooms[roomId]; | |||||
| REQUIRE(room.timeline == intoImmer(immer::flex_vector<std::string>{}, zug::map(&Event::id), existingEvents + timelineEvents)); | |||||
| REQUIRE_THAT(existingEvents + timelineEvents + relatedEvents, | |||||
| AllMatch(Predicate<Event>([&room](const auto &e) { return !!room.messages.count(e.id()); }, "should be in messages"))); | |||||
| REQUIRE(room.reverseEventRelationships.count(timelineEvents[0].id())); | |||||
| REQUIRE(room.reverseEventRelationships.count(existingEvents[0].id())); | |||||
| } | |||||
| // Verify the load works when loading into timeline an event in | |||||
| // messages but not in timeline | |||||
| auto nextTimelineEvents = relatedEvents + EventList{makeEventInRoom()}; | |||||
| std::tie(next, std::ignore) = updateClient(next, LoadEventsFromStorageAction{ | |||||
| {{roomId, nextTimelineEvents}}, | |||||
| {}, | |||||
| }); | |||||
| { | |||||
| auto room = next.roomList.rooms[roomId]; | |||||
| REQUIRE(room.timeline == intoImmer(immer::flex_vector<std::string>{}, zug::map(&Event::id), existingEvents + timelineEvents + nextTimelineEvents)); | |||||
| } | |||||
| } | |||||