Skip to content

Commit

Permalink
Handle survey group not being set
Browse files Browse the repository at this point in the history
  • Loading branch information
erikh360 committed Aug 28, 2023
1 parent fc94976 commit bae94ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions yal/surveys/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ async def state_location_introduction(self):
"ejaf_location_survey_status", "not_invited"
)
survey_group = self.user.metadata.get("ejaf_location_survey_group")

if not survey_group:
return await self.go_to_state("state_location_not_invited")

self.save_answer("ejaf_location_survey_group", survey_group)

error, group_count = await rapidpro.get_group_membership_count(
Expand Down
17 changes: 17 additions & 0 deletions yal/tests/surveys/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ def get_rapidpro_contact(urn):
status = "completed"
if "27820001003" in urn:
status = None
survey_group = None
if "27820001004" in urn:
survey_group = "2"
if "27820001005" in urn:
status = "invalid_province"
if "27820001006" in urn:
status = None
return {
"fields": {
"ejaf_location_survey_status": status,
Expand Down Expand Up @@ -137,6 +140,20 @@ async def test_state_location_introduction_not_invited(tester: AppTester):
)


@pytest.mark.asyncio
async def test_state_location_introduction_not_invited_with_group(tester: AppTester):
tester.setup_user_address("27820001006")
tester.setup_state("state_location_introduction")
await tester.user_input(session=Message.SESSION_EVENT.NEW)

tester.assert_state("state_location_not_invited")

tester.assert_message(
"Unfortunately it looks like we already have enough people answering this "
"survey, but thank you for your interest."
)


@pytest.mark.asyncio
async def test_state_location_introduction_group_max(tester: AppTester):
tester.setup_user_address("27820001004")
Expand Down

0 comments on commit bae94ef

Please sign in to comment.