Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | """Tests for webhook event types.""" |
| 2 | |
| 3 | import pytest |
| 4 | |
| 5 | from composio.core.models.webhook_events import ( |
| 6 | ConnectionExpiredEvent, |
| 7 | WebhookEventType, |
| 8 | is_connection_expired_event, |
| 9 | ) |
| 10 | |
| 11 | |
| 12 | class TestWebhookEventType: |
| 13 | """Tests for WebhookEventType enum.""" |
| 14 | |
| 15 | def test_connection_expired_value(self) -> None: |
| 16 | """Should have correct value for CONNECTION_EXPIRED.""" |
| 17 | assert ( |
| 18 | WebhookEventType.CONNECTION_EXPIRED.value |
| 19 | == "composio.connected_account.expired" |
| 20 | ) |
| 21 | |
| 22 | def test_trigger_message_value(self) -> None: |
| 23 | """Should have correct value for TRIGGER_MESSAGE.""" |
| 24 | assert WebhookEventType.TRIGGER_MESSAGE.value == "composio.trigger.message" |
| 25 | |
| 26 | |
| 27 | class TestIsConnectionExpiredEvent: |
| 28 | """Tests for is_connection_expired_event helper function.""" |
| 29 | |
| 30 | @pytest.fixture |
| 31 | def valid_payload(self) -> dict: |
| 32 | """Return a valid connection expired event payload.""" |
| 33 | return { |
| 34 | "id": "msg_847cdfcd-d219-4f18-a6dd-91acd42ca94a", |
| 35 | "timestamp": "2026-02-02T10:14:20.955Z", |
| 36 | "type": "composio.connected_account.expired", |
| 37 | "data": { |
| 38 | "toolkit": {"slug": "gmail"}, |
| 39 | "auth_config": { |
| 40 | "id": "ac_izZGRCZ9qyxk", |
| 41 | "auth_scheme": "OAUTH2", |
| 42 | "is_composio_managed": True, |
| 43 | "is_disabled": False, |
| 44 | }, |
| 45 | "id": "ca__IvSeEzEBjVt", |
| 46 | "user_id": "test-user", |
| 47 | "status": "EXPIRED", |
| 48 | "created_at": "2026-02-02T08:35:44.272Z", |
| 49 | "updated_at": "2026-02-02T10:14:20.949Z", |
| 50 | "state": { |
| 51 | "authScheme": "OAUTH2", |
| 52 | "val": {"status": "EXPIRED"}, |
| 53 | }, |
| 54 | "data": {}, |
| 55 | "params": {}, |
| 56 | "status_reason": None, |
| 57 | "is_disabled": False, |
| 58 | }, |
| 59 | "metadata": { |
| 60 | "project_id": "pr_koucdrMIwRsf", |
| 61 | "org_id": "4a4ded8f-d3ae-4dea-a229-c30234298b05", |
| 62 | }, |
| 63 | } |
| 64 | |
| 65 | def test_returns_true_for_valid_payload(self, valid_payload: dict) -> None: |
| 66 | """Should return True for a valid connection expired event.""" |
| 67 | assert is_connection_expired_event(valid_payload) is True |
| 68 | |
| 69 | def test_returns_false_for_trigger_message(self) -> None: |
| 70 | """Should return False for a trigger message event.""" |
| 71 | payload = { |
| 72 | "id": "msg_123", |
| 73 | "timestamp": "2026-02-02T10:14:20.955Z", |
| 74 | "type": "composio.trigger.message", |
| 75 | "data": {}, |
| 76 | "metadata": {}, |
| 77 | } |
| 78 | assert is_connection_expired_event(payload) is False |
| 79 | |
| 80 | def test_returns_false_for_none(self) -> None: |
| 81 | """Should return False for None input.""" |
| 82 | assert is_connection_expired_event(None) is False # type: ignore |
| 83 | |
| 84 | def test_returns_false_for_string(self) -> None: |
| 85 | """Should return False for string input.""" |
| 86 | assert is_connection_expired_event("string") is False # type: ignore |
| 87 | |
| 88 | def test_returns_false_for_empty_dict(self) -> None: |
| 89 | """Should return False for empty dict.""" |
| 90 | assert is_connection_expired_event({}) is False |
| 91 | |
| 92 | def test_returns_false_for_missing_type(self, valid_payload: dict) -> None: |
| 93 | """Should return False when type field is missing.""" |
| 94 | del valid_payload["type"] |
| 95 | assert is_connection_expired_event(valid_payload) is False |
| 96 | |
| 97 | |
| 98 | class TestConnectionExpiredEventType: |
| 99 | """Tests for ConnectionExpiredEvent TypedDict structure.""" |
| 100 | |
| 101 | def test_type_annotation(self) -> None: |
| 102 | """Should have correct type annotations.""" |
| 103 | # This test verifies the TypedDict can be used for type hints |
| 104 | event: ConnectionExpiredEvent = { |
| 105 | "id": "msg_123", |
| 106 | "timestamp": "2026-02-02T10:14:20.955Z", |
| 107 | "type": "composio.connected_account.expired", |
| 108 | "data": { |
| 109 | "toolkit": {"slug": "gmail"}, |
| 110 | "auth_config": { |
| 111 | "id": "ac_123", |
| 112 | "auth_scheme": "OAUTH2", |
| 113 | "is_composio_managed": True, |
| 114 | "is_disabled": False, |
| 115 | }, |
| 116 | "id": "ca_123", |
| 117 | "user_id": "user_123", |
| 118 | "status": "EXPIRED", |
| 119 | "created_at": "2026-02-02T08:35:44.272Z", |
| 120 | "updated_at": "2026-02-02T10:14:20.949Z", |
| 121 | "state": {"authScheme": "OAUTH2", "val": {}}, |
| 122 | "data": {}, |
| 123 | "params": {}, |
| 124 | "status_reason": None, |
| 125 | "is_disabled": False, |
| 126 | }, |
| 127 | "metadata": {"project_id": "pr_123", "org_id": "org_123"}, |
| 128 | } |
| 129 | |
| 130 | # Verify type narrowing works |
| 131 | assert event["type"] == "composio.connected_account.expired" |
| 132 | assert event["data"]["toolkit"]["slug"] == "gmail" |
| 133 | assert event["metadata"]["project_id"] == "pr_123" |