Skip to content

Commit

Permalink
test: test endpoint for checking ServiceAreas containing a GeoPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TAnas0 committed Sep 27, 2024
1 parent 32df877 commit 3f6297c
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/tests/test_check_point.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from fastapi.testclient import TestClient
from src.main import app
import src.tests.utils
import json

setup_db = src.tests.utils.setup_db

client = TestClient(app)


# Test checking if a point is in a service area
def test_check_point_in_service_area(setup_db):
# Create a service area that covers a specific point
service_area_data = {
"name": "Test Service Area",
"price": 100.0,
"geojson": json.dumps(
{
"type": "Polygon",
"coordinates": [
[
[-74.0, 40.0],
[-74.0, 41.0],
[-73.0, 41.0],
[-73.0, 40.0],
[-74.0, 40.0],
]
],
}
),
}
client.post("/api/v1/serviceareas/", json=service_area_data)

lat, lng = 40.5, -73.5 # Point inside the service area
response = client.get(f"/api/v1/serviceareas/check/?lat={lat}&lng={lng}")

assert response.status_code == 200
assert isinstance(response.json(), list)
assert len(response.json()) > 0


# Test checking a point not in a service area
def test_check_point_not_in_service_area(setup_db):
service_area_data = {
"name": "Test Service Area",
"price": 100.0,
"geojson": json.dumps(
{
"type": "Polygon",
"coordinates": [
[
[-74.0, 40.0],
[-74.0, 41.0],
[-73.0, 41.0],
[-73.0, 40.0],
[-74.0, 40.0],
]
],
}
),
}
client.post("/api/v1/serviceareas/", json=service_area_data)

lat, lng = 42.0, -75.0 # Point outside the service area
response = client.get(f"/api/v1/serviceareas/check/?lat={lat}&lng={lng}")

assert response.status_code == 404
assert response.json() == {
"detail": "No service area found for the given coordinates"
}

0 comments on commit 3f6297c

Please sign in to comment.