~aleteoryx/muditaos

b232c9770ca1ce8da9f3df4818a3eef168f610da — Pawel Olejniczak 3 years ago 2a539a4
[CP-1135] Extend messages API by deleteThread method

Allow to delete single message thread specified by id
using messages endpoint API.
M products/PurePhone/services/desktop/endpoints/messages/MessageHelper.cpp => products/PurePhone/services/desktop/endpoints/messages/MessageHelper.cpp +17 -2
@@ 34,6 34,7 @@
#include <utility>
#include <module-db/queries/messages/sms/QuerySMSGetByText.hpp>
#include "queries/messages/threads/QueryThreadGetByID.hpp"
#include "queries/messages/threads/QueryThreadRemove.hpp"

namespace sdesktop::endpoints
{


@@ 418,8 419,22 @@ namespace sdesktop::endpoints

    auto MessageHelper::deleteThread(Context &context) -> sys::ReturnCodes
    {
        context.setResponseStatus(http::Code::NotImplemented);
        putToSendQueue(context.createSimpleResponse());
        auto query = std::make_unique<db::query::ThreadRemove>(context.getBody()[json::messages::threadID].int_value());

        auto listener = std::make_unique<db::EndpointListener>(
            [](db::QueryResult *result, Context &context) {
                if (auto threadRemoveResult = dynamic_cast<db::query::ThreadRemoveResult *>(result)) {
                    context.setResponseStatus(threadRemoveResult->success() ? http::Code::NoContent
                                                                            : http::Code::InternalServerError);
                    putToSendQueue(context.createSimpleResponse());
                    return true;
                }
                return false;
            },
            context);

        query->setQueryListener(std::move(listener));
        DBServiceAPI::GetQuery(ownerServicePtr, db::Interface::Name::SMSThread, std::move(query));
        return sys::ReturnCodes::Success;
    }


M test/harness => test/harness +1 -1
@@ 1,1 1,1 @@
Subproject commit 577c1191121e5c59f6c7adc81417cd2e95e32c27
Subproject commit 3d77819ba8ab0cbac5912b2f3ca9f002e21a436a

M test/pytest/service-desktop/test_message_threads.py => test/pytest/service-desktop/test_message_threads.py +24 -1
@@ 2,7 2,7 @@
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
import pytest
from harness.request import TransactionError
from harness.api.messages import GetThreadsWithOffsetAndLimit, GetThreadById, MarkThreadAsUnread, GetMessageById, AddMessage, DeleteMessageById
from harness.api.messages import GetThreadsWithOffsetAndLimit, GetThreadById, MarkThreadAsUnread, DeleteThreadById, GetMessageById, AddMessage, DeleteMessageById


class ThreadsTester:


@@ 33,6 33,14 @@ class ThreadsTester:
        else:
            return True, result

    def delete_thread_by_id(self, thread_record_id):
        try:
            DeleteThreadById(thread_record_id).run(self.harness)
        except TransactionError:
            return False
        else:
            return True

    def get_message_by_id(self, message_record_id):
        try:
            result = GetMessageById(message_record_id).run(self.harness)


@@ 60,6 68,21 @@ class ThreadsTester:

@pytest.mark.service_desktop_test
@pytest.mark.usefixtures("phone_unlocked")
def test_create_and_delete_thread(harness):
    message_number = "123456789"
    message_body = "Test message"

    threads_tester = ThreadsTester(harness)

    result, message_record = threads_tester.add_message(message_number, message_body)
    assert result, "Failed to add message!"
    result, received_message_record = threads_tester.get_message_by_id(message_record["messageID"])
    assert result, "Failed to get message by id!"

    assert threads_tester.delete_thread_by_id(message_record["threadID"]), "Failed to delete a thread!"

@pytest.mark.service_desktop_test
@pytest.mark.usefixtures("phone_unlocked")
def test_marking_thread_as_read(harness):
    message_number = "123456789"
    message_body = "Test message nr 1"