|
| 1 | +from android_sms_gateway.enums import WebhookEvent |
1 | 2 | import pytest
|
2 | 3 |
|
3 |
| -from android_sms_gateway.domain import MessageState, RecipientState |
| 4 | +from android_sms_gateway.domain import MessageState, RecipientState, Webhook |
4 | 5 |
|
5 | 6 |
|
6 | 7 | # Test for successful instantiation from a dictionary
|
@@ -79,3 +80,58 @@ def test_message_state_from_dict_incorrect_types():
|
79 | 80 | Exception
|
80 | 81 | ): # Replace Exception with the specific exception you expect
|
81 | 82 | MessageState.from_dict(incorrect_payload)
|
| 83 | + |
| 84 | + |
| 85 | +def test_webhook_from_dict(): |
| 86 | + """ |
| 87 | + Tests that a Webhook instance can be successfully instantiated from a dictionary |
| 88 | + representation of a webhook. |
| 89 | + """ |
| 90 | + payload = { |
| 91 | + "id": "webhook_123", |
| 92 | + "url": "https://example.com/webhook", |
| 93 | + "event": "sms:received", |
| 94 | + } |
| 95 | + |
| 96 | + webhook = Webhook.from_dict(payload) |
| 97 | + |
| 98 | + assert webhook.id == payload["id"] |
| 99 | + assert webhook.url == payload["url"] |
| 100 | + assert webhook.event == WebhookEvent(payload["event"]) |
| 101 | + |
| 102 | + |
| 103 | +def test_webhook_asdict(): |
| 104 | + """ |
| 105 | + Tests that a Webhook instance can be successfully converted to a dictionary |
| 106 | + representation and that the fields match the expected values. |
| 107 | +
|
| 108 | + This test ensures that the asdict method of the Webhook class returns a dictionary |
| 109 | + with the correct keys and values. |
| 110 | + """ |
| 111 | + webhook = Webhook( |
| 112 | + id="webhook_123", |
| 113 | + url="https://example.com/webhook", |
| 114 | + event=WebhookEvent.SMS_RECEIVED, |
| 115 | + ) |
| 116 | + |
| 117 | + expected_dict = { |
| 118 | + "id": "webhook_123", |
| 119 | + "url": "https://example.com/webhook", |
| 120 | + "event": "sms:received", |
| 121 | + } |
| 122 | + |
| 123 | + assert webhook.asdict() == expected_dict |
| 124 | + |
| 125 | + webhook = Webhook( |
| 126 | + id=None, |
| 127 | + url="https://example.com/webhook", |
| 128 | + event=WebhookEvent.SMS_RECEIVED, |
| 129 | + ) |
| 130 | + |
| 131 | + expected_dict = { |
| 132 | + "id": None, |
| 133 | + "url": "https://example.com/webhook", |
| 134 | + "event": "sms:received", |
| 135 | + } |
| 136 | + |
| 137 | + assert webhook.asdict() == expected_dict |
0 commit comments