Skip to content

Commit 25d08f5

Browse files
authored
Merge pull request #6 from telexintegrations:feat/tests
feat(test): add integration tests for GitHub webhook endpoint
2 parents bc4d548 + 597a75c commit 25d08f5

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

.env.example

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Sample setup for environmental variables
22

3-
ALLOWED_ORIGINS=https://github.com,http://127.0.0.1:8000,http://0.0.0.0:8000,http://localhost:8000,https://ping.telex.im
4-
ALLOWED_HOSTS=github.com,127.0.0.1,0.0.0.0,localhost,ping.telex.im
3+
ALLOWED_ORIGINS=https://github.com,http://127.0.0.1:8000,http://0.0.0.0:8000,http://localhost:8000,https://ping.telex.im,http://test
4+
ALLOWED_HOSTS=github.com,127.0.0.1,0.0.0.0,localhost,ping.telex.im,test
55
HOST=0.0.0.0
66
PORT=8000
77
RELOAD_VALUE=True

tests/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from fastapi.testclient import TestClient
2+
3+
from main import app
4+
5+
client = TestClient(app, base_url="http://test/api/v1")

tests/test_github.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from tests import client
2+
import json
3+
4+
5+
def test_send_to_telex_success():
6+
response = client.post(
7+
"/webhook/github/{telex_channel_id}", # Replace with an existing channel ID to receive messages
8+
json={
9+
"pusher": {"name": "test"},
10+
"commits": [
11+
{"key": "value"},
12+
],
13+
},
14+
)
15+
assert response.status_code == 200
16+
response_data = json.loads(response.content.decode())
17+
assert response_data["data"]["status"] == "success"
18+
assert response_data["data"]["status_code"] == 202
19+
20+
21+
def test_send_to_telex_failure():
22+
response = client.post(
23+
"/webhook/github/{telex_channel_id}", json={"pusher": {"name": "test"}}
24+
)
25+
assert response.status_code == 422
26+
response_data = json.loads(response.content.decode())
27+
assert "commits" in response_data["detail"][0]["loc"]

0 commit comments

Comments
 (0)