From f74170387b39b55bafa913e283fccc3e066aa05c Mon Sep 17 00:00:00 2001 From: Pawel Olejniczak Date: Mon, 24 May 2021 16:10:31 +0200 Subject: [PATCH] [CP-79] Update messages API tests Check if all required fields in resposne json are present. Also check if they have a proper type. --- test/pytest/service-desktop/test_messages.py | 14 +++++++++++--- test/pytest/service-desktop/test_templates.py | 4 ++++ test/pytest/service-desktop/test_threads.py | 13 +++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/test/pytest/service-desktop/test_messages.py b/test/pytest/service-desktop/test_messages.py index 3f68bce71bffc716450ee7780710070e39bddbbd..faa7f7c39a95bc0eb8f28968272dac82502c2555 100644 --- a/test/pytest/service-desktop/test_messages.py +++ b/test/pytest/service-desktop/test_messages.py @@ -4,7 +4,6 @@ import pytest from harness.interface.defs import status - MESSAGES_PAGE_SIZE = 4 @@ -19,6 +18,15 @@ def test_get_messages_without_pagination(harness): messages = ret["body"]["entries"] messages_count = len(messages) assert messages_count == limit + message_types = [1, 2, 4, 8, 16, 18, 255] + for message in messages: + assert type(message["contactID"]) == int + assert type(message["messageBody"]) == str + assert type(message["messageID"]) == int + assert type(message["messageType"]) == int + assert type(message["createdAt"]) == int + assert type(message["threadID"]) == int + assert message["messageType"] in message_types @pytest.mark.service_desktop_test @@ -61,7 +69,7 @@ def test_get_all_messages(harness): if "nextPage" in ret["body"]: offset = ret["body"]["nextPage"]["offset"] - messages_left_count = count - len(all_messages) + messages_left_count = count - len(all_messages) body = {"category": "message", "limit": messages_left_count, "offset": offset} ret = harness.endpoint_request("messages", "get", body) @@ -136,7 +144,7 @@ def test_get_all_messages_by_thread_id(harness): if "nextPage" in ret["body"]: offset = ret["body"]["nextPage"]["offset"] - messages_left_count = messages_by_thread_id_count - len(all_messages) + messages_left_count = messages_by_thread_id_count - len(all_messages) body = {"category": "message", "threadID": thread_id, "limit": messages_left_count, "offset": offset} ret = harness.endpoint_request("messages", "get", body) diff --git a/test/pytest/service-desktop/test_templates.py b/test/pytest/service-desktop/test_templates.py index 32e1fcae97e8ec59cf23574b87ec9be236c1dac0..fd2dd5e3cb90ed7805cdee83d080ef08c0618b17 100644 --- a/test/pytest/service-desktop/test_templates.py +++ b/test/pytest/service-desktop/test_templates.py @@ -83,6 +83,10 @@ class TemplatesTester: assert ret["status"] == status["OK"] assert ret["body"]["totalCount"] == count assert len(ret["body"]["entries"]) == number_of_requested_templates + for template in ret["body"]["entries"]: + assert type(template["lastUsedAt"]) == int + assert type(template["templateBody"]) == str + assert type(template["templateID"]) == int def test_changing_template_body(self): test_passed = False diff --git a/test/pytest/service-desktop/test_threads.py b/test/pytest/service-desktop/test_threads.py index 142ca78948b737662e8cc90d83de142e14e0e128..126589c079117e5a9097d6d5ae4a3a258c4b008e 100644 --- a/test/pytest/service-desktop/test_threads.py +++ b/test/pytest/service-desktop/test_threads.py @@ -12,6 +12,19 @@ def test_threads(harness): ret = harness.endpoint_request("messages", "get", body) assert ret["status"] == status["OK"] + # Check if all fields are present and have proper type + message_types = [1, 2, 4, 8, 16, 18, 255] + for thread in ret["body"]["entries"]: + assert type(thread["contactID"]) == int + assert type(thread["isUnread"]) == bool + assert type(thread["lastUpdatedAt"]) == int + assert type(thread["messageCount"]) == int + assert type(thread["messageSnippet"]) == str + assert type(thread["messageType"]) == int + assert type(thread["numberID"]) == int + assert type(thread["threadID"]) == int + assert thread["messageType"] in message_types + # getting a number of threads number_of_requested_threads = 3 if ret["body"]["totalCount"] < number_of_requested_threads: