Skip to content

Commit

Permalink
[#391] Add answers & benchmark into segment put endpoint obj
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Jan 20, 2025
1 parent 8ca1e80 commit 53121d5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
9 changes: 4 additions & 5 deletions backend/routes/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from db.connection import get_session
from models.segment import (
SegmentBase,
SegmentDict,
SegmentUpdateBase,
SegmentWithAnswersDict,
)
Expand All @@ -24,7 +23,7 @@

@segment_route.post(
"/segment",
response_model=List[SegmentDict],
response_model=List[SegmentWithAnswersDict],
summary="create segment",
name="segment:create",
tags=["Segment"],
Expand All @@ -45,12 +44,12 @@ def create_segment(
session=session, case_id=case_id, user_id=user.id
)
segments = crud_segment.add_segment(session=session, payloads=payload)
return [s.serialize for s in segments]
return [s.serialize_with_answers for s in segments]


@segment_route.put(
"/segment",
response_model=List[SegmentDict],
response_model=List[SegmentWithAnswersDict],
summary="update segment",
name="segment:update",
tags=["Segment"],
Expand All @@ -71,7 +70,7 @@ def update_segment(
crud_case.case_updated_by(
session=session, case_id=case_id, user_id=user.id
)
return [s.serialize for s in segments]
return [s.serialize_with_answers for s in segments]


@segment_route.delete(
Expand Down
26 changes: 26 additions & 0 deletions backend/tests/test_040_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ async def test_create_segment(
"adult": 2.0,
"child": 3.0,
"number_of_farmers": None,
"answers": {},
"benchmark": None,
}
]
# with admin user cred
Expand Down Expand Up @@ -104,6 +106,8 @@ async def test_create_segment(
"adult": 3.0,
"child": 2.0,
"number_of_farmers": None,
"answers": {},
"benchmark": None,
},
{
"id": res[1]["id"],
Expand All @@ -114,6 +118,13 @@ async def test_create_segment(
"adult": 4.0,
"child": 2.0,
"number_of_farmers": None,
"answers": {
"current-1-1": 10000.0,
"current-1-2": None,
"feasible-1-1": None,
"feasible-1-2": None,
},
"benchmark": None,
},
]

Expand Down Expand Up @@ -156,6 +167,8 @@ async def test_update_segment(
"adult": 4.0,
"child": 2.0,
"number_of_farmers": None,
"answers": {},
"benchmark": None,
}
]
# with admin user cred
Expand Down Expand Up @@ -227,6 +240,8 @@ async def test_update_segment(
"adult": 5.0,
"child": 0.0,
"number_of_farmers": None,
"answers": {},
"benchmark": None,
},
{
"id": 2,
Expand All @@ -237,6 +252,8 @@ async def test_update_segment(
"adult": 6.0,
"child": 0.0,
"number_of_farmers": None,
"answers": {},
"benchmark": None,
},
{
"id": 3,
Expand All @@ -247,5 +264,14 @@ async def test_update_segment(
"adult": 4.0,
"child": 2.0,
"number_of_farmers": None,
"answers": {
"current-1-1": 10000.0,
"current-1-2": None,
"current-1-3": None,
"feasible-1-1": None,
"feasible-1-2": None,
"feasible-1-3": 500.0,
},
"benchmark": None,
},
]

0 comments on commit 53121d5

Please sign in to comment.