-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into TW-2809-TW-2866-add-fields
- Loading branch information
Showing
7 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,3 +190,32 @@ def http_client_list_scheduled_messages(): | |
], | ||
} | ||
return mock_http_client | ||
|
||
|
||
@pytest.fixture | ||
def http_client_clean_messages(): | ||
mock_http_client = Mock() | ||
mock_http_client._execute.return_value = { | ||
"request_id": "dd3ec9a2-8f15-403d-b269-32b1f1beb9f5", | ||
"data": [ | ||
{ | ||
"body": "Hello, I just sent a message using Nylas!", | ||
"from": [ | ||
{"name": "Daenerys Targaryen", "email": "[email protected]"} | ||
], | ||
"grant_id": "41009df5-bf11-4c97-aa18-b285b5f2e386", | ||
"id": "message-1", | ||
"object": "message", | ||
"conversation": "cleaned example", | ||
}, | ||
{ | ||
"body": "Hello, this is a test message!", | ||
"from": [{"name": "Michael Scott", "email": "[email protected]"}], | ||
"grant_id": "41009df5-bf11-4c97-aa18-b285b5f2e386", | ||
"id": "message-2", | ||
"object": "message", | ||
"conversation": "another example", | ||
}, | ||
], | ||
} | ||
return mock_http_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,3 +272,37 @@ def test_stop_scheduled_message(self, http_client_response): | |
method="DELETE", | ||
path="/v3/grants/abc-123/messages/schedules/schedule-123", | ||
) | ||
|
||
def test_clean_messages(self, http_client_clean_messages): | ||
messages = Messages(http_client_clean_messages) | ||
request_body = { | ||
"message_id": ["message-1", "message-2"], | ||
"ignore_images": True, | ||
"ignore_links": True, | ||
"ignore_tables": True, | ||
"images_as_markdown": True, | ||
"remove_conclusion_phrases": True, | ||
} | ||
|
||
response = messages.clean_messages( | ||
identifier="abc-123", | ||
request_body=request_body, | ||
) | ||
|
||
http_client_clean_messages._execute.assert_called_once_with( | ||
method="PUT", | ||
path="/v3/grants/abc-123/messages/clean", | ||
request_body=request_body, | ||
) | ||
|
||
# Assert the conversation field, and the typical message fields serialize properly | ||
assert len(response.data) == 2 | ||
assert response.data[0].body == "Hello, I just sent a message using Nylas!" | ||
assert response.data[0].from_ == [ | ||
{"name": "Daenerys Targaryen", "email": "[email protected]"} | ||
] | ||
assert response.data[0].object == "message" | ||
assert response.data[0].id == "message-1" | ||
assert response.data[0].grant_id == "41009df5-bf11-4c97-aa18-b285b5f2e386" | ||
assert response.data[0].conversation == "cleaned example" | ||
assert response.data[1].conversation == "another example" |