Skip to content

Commit

Permalink
fix(proofs): improve new proof date & currency optional mgmt. ref #327
Browse files Browse the repository at this point in the history
…& #337
  • Loading branch information
raphodn committed Jun 22, 2024
1 parent 31cc0b7 commit c8656df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 5 additions & 4 deletions app/routers/proofs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Annotated
from typing import Annotated, Optional

from fastapi import APIRouter, Depends, Form, HTTPException, UploadFile, status
from fastapi_filter import FilterDepends
Expand Down Expand Up @@ -39,10 +39,11 @@ def get_user_proofs(
def upload_proof(
file: UploadFile,
type: Annotated[ProofTypeEnum, Form(description="The type of the proof")],
current_user: schemas.UserCreate = Depends(get_current_user),
date: str | None = None,
currency: CurrencyEnum | None = None,
date: Optional[str] | None = Form(description="Proof date", default=None),
currency: Optional[CurrencyEnum]
| None = Form(description="Proof currency", default=None),
app_name: str | None = None,
current_user: schemas.UserCreate = Depends(get_current_user),
db: Session = Depends(get_db),
) -> Proof:
"""
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,15 +861,19 @@ def test_create_proof(db_session, user_session: SessionModel, clean_proofs):
headers={"Authorization": f"Bearer {user_session.token}"},
)
assert response.status_code == 201
assert response.json()["date"] is None
assert response.json()["currency"] is None
assert len(crud.get_proofs(db_session)) == 1

response = client.post(
"/api/v1/proofs/upload",
files={"file": ("filename", (io.BytesIO(b"test")), "image/webp")},
data={"type": "RECEIPT", "date": "2024-01-01"},
data={"type": "RECEIPT", "date": "2024-01-01", "currency": ""},
headers={"Authorization": f"Bearer {user_session.token}"},
)
assert response.status_code == 201
assert response.json()["date"] == "2024-01-01"
assert response.json()["currency"] is None
assert len(crud.get_proofs(db_session)) == 1 + 1

response = client.post(
Expand All @@ -879,6 +883,8 @@ def test_create_proof(db_session, user_session: SessionModel, clean_proofs):
headers={"Authorization": f"Bearer {user_session.token}"},
)
assert response.status_code == 201
assert response.json()["date"] == "2024-01-01"
assert response.json()["currency"] == "EUR"
assert len(crud.get_proofs(db_session)) == 2 + 1

# with app_name
Expand Down

0 comments on commit c8656df

Please sign in to comment.