diff --git a/backend/.gitignore b/backend/.gitignore index 0c06538..49ddab5 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -1,3 +1,4 @@ __pycache__ venv -.env \ No newline at end of file +.env +test.db \ No newline at end of file diff --git a/backend/app/routers/url_routes.py b/backend/app/routers/url_routes.py index bb21f76..256eb71 100644 --- a/backend/app/routers/url_routes.py +++ b/backend/app/routers/url_routes.py @@ -13,7 +13,7 @@ ) -@router.post("", response_model=Url) +@router.post("", response_model=Url, status_code=201) def create_url(original_url: OriginalUrl, db: Session = Depends(get_db)): new_url = url_service.create_url(db=db, url_create=original_url) diff --git a/backend/app/tests/routers/__init__.py b/backend/app/tests/routers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/app/tests/routers/test_url_routes.py b/backend/app/tests/routers/test_url_routes.py new file mode 100644 index 0000000..c3f192c --- /dev/null +++ b/backend/app/tests/routers/test_url_routes.py @@ -0,0 +1,14 @@ +from ..test_setup import test_db, client + +prefix = "/url" + + +def test_create_url(test_db): + original_url = "http://test.com" + response = client.post(prefix, json={"originalUrl": original_url}) + result = response.json() + + assert response.status_code == 201 + assert result['id'] >= 0 + assert result['originalUrl'] == original_url + assert len(result['shortenedUrl']) >= 4 diff --git a/backend/app/tests/routers/test_url_shortener.py b/backend/app/tests/routers/test_url_shortener.py new file mode 100644 index 0000000..de83549 --- /dev/null +++ b/backend/app/tests/routers/test_url_shortener.py @@ -0,0 +1,8 @@ +from ..test_setup import test_db, client + + +def test_read_root(test_db): + response = client.get("/") + + assert response.status_code == 200 + assert response.json() == {"message": "Welcome to MinionUrl."}