Changeset View
Changeset View
Standalone View
Standalone View
src/tests/client/account-data-test.cpp
| Show All 25 Lines | |||||
| Event accountDataEvent = R"({ | Event accountDataEvent = R"({ | ||||
| "type": "moe.kazv.mxc.kazv.some-event", | "type": "moe.kazv.mxc.kazv.some-event", | ||||
| "content": { | "content": { | ||||
| "test": 1 | "test": 1 | ||||
| } | } | ||||
| })"_json; | })"_json; | ||||
| Event mDirectEvent = R"({ | |||||
| "type": "m.direct", | |||||
| "content": { | |||||
| "@mew:example.org": ["!somewhere:example.org"] | |||||
| } | |||||
| })"_json; | |||||
| TEST_CASE("Send set account data by room job", "[client][account-data]") | TEST_CASE("Send set account data by room job", "[client][account-data]") | ||||
| { | { | ||||
| ClientModel loggedInModel = makeClient({}); | ClientModel loggedInModel = makeClient({}); | ||||
| auto [resModel, dontCareEffect] = ClientModel::update( | auto [resModel, dontCareEffect] = ClientModel::update( | ||||
| loggedInModel, SetAccountDataPerRoomAction{"!room:example.com", accountDataEvent}); | loggedInModel, SetAccountDataPerRoomAction{"!room:example.com", accountDataEvent}); | ||||
| assert1Job(resModel); | assert1Job(resModel); | ||||
| ▲ Show 20 Lines • Show All 346 Lines • ▼ Show 20 Lines | client.setAccountData(accountDataEvent) | ||||
| io.stop(); | io.stop(); | ||||
| }); | }); | ||||
| io.run(); | io.run(); | ||||
| REQUIRE(dispatcher.template calledTimes<SetAccountDataAction>() == 1); | REQUIRE(dispatcher.template calledTimes<SetAccountDataAction>() == 1); | ||||
| auto a = dispatcher.template of<SetAccountDataAction>()[0]; | auto a = dispatcher.template of<SetAccountDataAction>()[0]; | ||||
| REQUIRE(a.accountDataEvent == accountDataEvent); | REQUIRE(a.accountDataEvent == accountDataEvent); | ||||
| } | |||||
| TEST_CASE("Client::addDirectRoom()", "[client][account-data]") | |||||
| { | |||||
| boost::asio::io_context io; | |||||
| SingleTypePromiseInterface<EffectStatus> ph{AsioPromiseHandler{io.get_executor()}}; | |||||
| ClientModel m = makeClient({}); | |||||
| auto jh = Kazv::CprJobHandler{io.get_executor()}; | |||||
| auto ee = Kazv::LagerStoreEventEmitter(lager::with_boost_asio_event_loop{io.get_executor()}); | |||||
| auto sdk = Kazv::makeSdk( | |||||
| SdkModel{m}, | |||||
| jh, | |||||
| ee, | |||||
| Kazv::AsioPromiseHandler{io.get_executor()}, | |||||
| zug::identity | |||||
| ); | |||||
| auto ctx = sdk.context(); | |||||
| auto dispatcher = getMockDispatcher( | |||||
| ph, | |||||
| ctx, | |||||
| returnEmpty<SetAccountDataAction>() | |||||
| ); | |||||
| auto mockContext = getMockContext(ph, dispatcher); | |||||
| auto client = Client(Client::InEventLoopTag{}, mockContext, sdk.context()); | |||||
| client.addDirectRoom("@mew:example.org", "!somewhere:example.org") | |||||
| .then([&io](auto) { | |||||
| io.stop(); | |||||
| }); | |||||
| io.run(); | |||||
| REQUIRE(dispatcher.template calledTimes<SetAccountDataAction>() == 1); | |||||
| auto a = dispatcher.template of<SetAccountDataAction>()[0]; | |||||
| REQUIRE(a.accountDataEvent == mDirectEvent); | |||||
| } | |||||
| TEST_CASE("Client::addDirectRoom(), when roomId is already in m.direct", "[client][account-data]") | |||||
| { | |||||
| boost::asio::io_context io; | |||||
| SingleTypePromiseInterface<EffectStatus> ph{AsioPromiseHandler{io.get_executor()}}; | |||||
| ClientModel m = makeClient({}); | |||||
| m.accountData = m.accountData.set("m.direct", mDirectEvent); | |||||
| auto jh = Kazv::CprJobHandler{io.get_executor()}; | |||||
| auto ee = Kazv::LagerStoreEventEmitter(lager::with_boost_asio_event_loop{io.get_executor()}); | |||||
| auto sdk = Kazv::makeSdk( | |||||
| SdkModel{m}, | |||||
| jh, | |||||
| ee, | |||||
| Kazv::AsioPromiseHandler{io.get_executor()}, | |||||
| zug::identity | |||||
| ); | |||||
| auto ctx = sdk.context(); | |||||
| auto dispatcher = getMockDispatcher( | |||||
| ph, | |||||
| ctx, | |||||
| returnEmpty<SetAccountDataAction>() | |||||
| ); | |||||
| auto mockContext = getMockContext(ph, dispatcher); | |||||
| auto client = Client(Client::InEventLoopTag{}, mockContext, sdk.context()); | |||||
| client.addDirectRoom("@mew:example.org", "!somewhere:example.org") | |||||
| .then([&io](auto) { | |||||
| io.stop(); | |||||
| }); | |||||
| io.run(); | |||||
| REQUIRE(dispatcher.template calledTimes<SetAccountDataAction>() == 0); | |||||
| } | } | ||||
tusooa: Add test cases where:
- the m.direct content contains other users' rooms, then these rooms… | |||||
Add test cases where: