Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle survey group not being set #680

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading