Skip to content

Commit

Permalink
Add text only error to FreeText state
Browse files Browse the repository at this point in the history
  • Loading branch information
erikh360 committed Aug 22, 2023
1 parent 3a3ec69 commit 966fae6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vaccine/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def __init__(
override_answer_name: Optional[str] = None,
footer: Optional[str] = None,
header: Optional[str] = None,
text_only_error: Optional[str] = None,
):
self.app = app
self.question = question
Expand All @@ -225,8 +226,12 @@ def __init__(
self.override_answer_name = override_answer_name
self.footer = footer
self.header = header
self.text_only_error = text_only_error

async def process_message(self, message: Message):
if self.text_only_error is not None and message.transport_metadata:
if message.transport_metadata.get("message", {}).get("type") != "text":
return self.app.send_message(self.text_only_error)
if self.check is not None:
if not isinstance(self.check, list):
self.check = [self.check]
Expand Down
1 change: 1 addition & 0 deletions yal/surveys/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ async def state_location_name_city(self):
question=question,
next="state_location_area_type",
check=nonempty_validator(question),
text_only_error=question,
)

async def state_location_area_type(self):
Expand Down
26 changes: 26 additions & 0 deletions yal/tests/surveys/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,32 @@ async def test_state_location_name_city(tester: AppTester):
)


@pytest.mark.asyncio
async def test_state_location_name_city_invalid(tester: AppTester):
tester.setup_state("state_location_name_city")
await tester.user_input(
"",
transport_metadata={
"message": {
"type": "image",
"image": {"id": "img1", "mime_type": "image/jpeg"},
}
},
)

tester.assert_state("state_location_name_city")
tester.assert_message(
"\n".join(
[
"*What is the name of the city or town you live in or live closest "
"to?*",
"",
"Please *TYPE* in the name of the city or town.",
]
)
)


@pytest.mark.asyncio
async def test_state_location_area_type(tester: AppTester):
tester.setup_state("state_location_name_city")
Expand Down

0 comments on commit 966fae6

Please sign in to comment.