~aleteoryx/muditaos

9a8f09737795c81f2a46c16c48190eb09476135a — Maciej Gibowicz 3 years ago b99fd74
[MOS-556] Fix call rejection in DND

Calls from a favorite contact for enabled notifications
were rejected.
M module-services/service-cellular/call/CallMachine.hpp => module-services/service-cellular/call/CallMachine.hpp +2 -2
@@ 132,10 132,10 @@ namespace call

    struct ClipDND_NOK
    {
        bool operator()(Dependencies &di, CallData &call)
        bool operator()(const call::event::CLIP &clip, Dependencies &di, CallData &call)
        {
            return call.mode == sys::phone_modes::PhoneMode::DoNotDisturb &&
                   not di.db->isNumberInFavourites(call.record.phoneNumber);
                   not(di.modem->areCallsFromFavouritesEnabled() && di.db->isNumberInFavourites(clip.number));
        }
    } constexpr ClipDND_NOK;


M module-services/service-cellular/call/tests/test-CallMachine.cpp => module-services/service-cellular/call/tests/test-CallMachine.cpp +17 -1
@@ 317,13 317,29 @@ TEST_CASE("call incoming - dnd - not favourite")
    fakeit::Verify(Method(di.api, rejectCall)).Exactly(1);
}

TEST_CASE("call incoming - dnd - in favourite")
TEST_CASE("call incoming - dnd - in favourite - calls from favourites disabled")
{
    auto number  = utils::PhoneNumber("+48700800900");
    auto di      = mocks::DIWrapper(true);
    auto machine = std::make_unique<call::StateMachine>(di.get());

    fakeit::When(Method(di.db, isNumberInFavourites)).AlwaysReturn(true);
    fakeit::When(Method(di.api, areCallsFromFavouritesEnabled)).AlwaysReturn(false);

    REQUIRE(not machine->machine.process_event(call::event::RING{}));
    REQUIRE(machine->machine.process_event(call::event::CLIP{number.getView()}));
    fakeit::Verify(Method(di.audio, play)).Exactly(0);
    fakeit::Verify(Method(di.api, rejectCall)).Exactly(1);
}

TEST_CASE("call incoming - dnd - in favourite - calls from favourites enabled")
{
    auto number  = utils::PhoneNumber("+48700800900");
    auto di      = mocks::DIWrapper(true);
    auto machine = std::make_unique<call::StateMachine>(di.get());

    fakeit::When(Method(di.db, isNumberInFavourites)).AlwaysReturn(true);
    fakeit::When(Method(di.api, areCallsFromFavouritesEnabled)).AlwaysReturn(true);

    REQUIRE(not machine->machine.process_event(call::event::RING{}));
    REQUIRE(machine->machine.process_event(call::event::CLIP{number.getView()}));