diff --git a/.env.example b/.env.example index cd2ba9a..4032fe7 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,7 @@ # Sample setup for environmental variables -ALLOWED_ORIGINS=https://github.com,http://127.0.0.1:8000,http://0.0.0.0:8000,http://localhost:8000,https://ping.telex.im -ALLOWED_HOSTS=github.com,127.0.0.1,0.0.0.0,localhost,ping.telex.im +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 +ALLOWED_HOSTS=github.com,127.0.0.1,0.0.0.0,localhost,ping.telex.im,test HOST=0.0.0.0 PORT=8000 RELOAD_VALUE=True diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..bd7f851 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,5 @@ +from fastapi.testclient import TestClient + +from main import app + +client = TestClient(app, base_url="http://test/api/v1") \ No newline at end of file diff --git a/tests/test_github.py b/tests/test_github.py new file mode 100644 index 0000000..da1cceb --- /dev/null +++ b/tests/test_github.py @@ -0,0 +1,27 @@ +from tests import client +import json + + +def test_send_to_telex_success(): + response = client.post( + "/webhook/github/{telex_channel_id}", # Replace with an existing channel ID to receive messages + json={ + "pusher": {"name": "test"}, + "commits": [ + {"key": "value"}, + ], + }, + ) + assert response.status_code == 200 + response_data = json.loads(response.content.decode()) + assert response_data["data"]["status"] == "success" + assert response_data["data"]["status_code"] == 202 + + +def test_send_to_telex_failure(): + response = client.post( + "/webhook/github/{telex_channel_id}", json={"pusher": {"name": "test"}} + ) + assert response.status_code == 422 + response_data = json.loads(response.content.decode()) + assert "commits" in response_data["detail"][0]["loc"]