Skip to content

Commit

Permalink
Merge pull request #670 from praekeltfoundation/location-survey
Browse files Browse the repository at this point in the history
Add missing loccation survey states
  • Loading branch information
erikh360 authored Aug 17, 2023
2 parents 8a35b8e + 598c7ac commit 1a205d2
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 3 deletions.
58 changes: 56 additions & 2 deletions yal/surveys/location.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import asyncio

from vaccine.base_application import BaseApplication
from vaccine.states import (
Choice,
Expand All @@ -7,7 +9,7 @@
WhatsAppListState,
)
from vaccine.validators import nonempty_validator
from yal import rapidpro
from yal import contentrepo, rapidpro
from yal.askaquestion import Application as AAQApplication
from yal.change_preferences import Application as ChangePreferencesApplication
from yal.utils import get_generic_error, normalise_phonenumber
Expand Down Expand Up @@ -75,7 +77,11 @@ async def state_location_introduction(self):
question=question,
choices=choices,
error=self._(get_generic_error()),
next={"yes": "state_location_province", "no": "TODO", "question": "TODO"},
next={
"yes": "state_location_province",
"no": "state_location_decline",
"question": "state_send_consent_pdf",
},
)

async def state_location_not_invited(self):
Expand All @@ -95,6 +101,53 @@ async def state_location_already_completed(self):
next=self.START_STATE,
)

async def state_location_decline(self):
return EndState(
self,
self._(
"That's completely okay, there are no consequences to not taking part "
"in this study. Please enjoy the BWise tool and stay safe."
),
next=self.START_STATE,
)

async def state_send_consent_pdf(self):
await self.worker.publish_message(
self.inbound.reply(
None,
helper_metadata={"document": contentrepo.get_privacy_policy_url()},
)
)
await asyncio.sleep(1.5)
return await self.go_to_state("state_location_question")

async def state_location_question(self):
async def _next(choice: Choice):
if choice.value == "decline":
return "state_location_decline"
return "state_location_province"

return WhatsAppButtonState(
self,
question=self._(
"\n".join(
[
"You should be able to find the answer to any questions you "
"have in the consent doc we sent you. If you still have "
"questions, please email [email protected]",
"",
"Would you like to continue?",
]
)
),
choices=[
Choice("continue", "Continue"),
Choice("decline", "No, thank you"),
],
next=_next,
error=self._(get_generic_error()),
)

async def state_location_province(self):
async def _next(choice: Choice):
if choice.value == "other":
Expand Down Expand Up @@ -219,6 +272,7 @@ async def state_location_update_status(self):
return await self.go_to_state("state_location_end")

async def state_location_end(self):
# TODO: handle the don't understand branch
question = self._(
"\n".join(
[
Expand Down
3 changes: 3 additions & 0 deletions yal/tests/states_dictionary.md
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,6 @@
| state_location_group_invite | TRUE | Text | Invite user to group discussions
| state_location_update_status | FALSE | Text | Updates ejaf_location_survey_status contact field on rapidpro
| state_location_end | TRUE | Text | Tells user the survey is over with some prompts to go to different places
| state_location_question | TRUE | text | Asks user if they'd like to continue after seeing consent pdf
| state_send_consent_pdf | FALSE | text | Send the consent pdf to the user
| state_location_decline | FALSE | text | Tells users there are no consequences for not joining study
57 changes: 56 additions & 1 deletion yal/tests/surveys/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,65 @@ async def test_state_location_introduction_pending(tester: AppTester):
)


@pytest.mark.asyncio
async def test_state_location_decline(tester: AppTester):
tester.setup_state("state_location_introduction")
await tester.user_input("2")

tester.assert_state("state_start")
tester.assert_message(
"That's completely okay, there are no consequences to not taking part in this "
"study. Please enjoy the BWise tool and stay safe."
)


@pytest.mark.asyncio
async def test_state_location_question(tester: AppTester):
tester.setup_state("state_location_introduction")
await tester.user_input("3")

tester.assert_state("state_location_question")
tester.assert_message(
"\n".join(
[
"You should be able to find the answer to any questions you have in "
"the consent doc we sent you. If you still have questions, please "
"email [email protected]",
"",
"Would you like to continue?",
]
)
)

[msg] = tester.fake_worker.outbound_messages
assert msg.helper_metadata == {
"document": "https://contenrepo/documents/1/sample.pdf"
}


@pytest.mark.asyncio
async def test_state_location_question_continue(tester: AppTester):
tester.setup_state("state_location_question")
await tester.user_input("1")

tester.assert_state("state_location_province")


@pytest.mark.asyncio
async def test_state_location_question_decline(tester: AppTester):
tester.setup_state("state_location_question")
await tester.user_input("2")

tester.assert_state("state_start")
tester.assert_message(
"That's completely okay, there are no consequences to not taking part in this "
"study. Please enjoy the BWise tool and stay safe."
)


@pytest.mark.asyncio
async def test_state_location_province(tester: AppTester):
tester.setup_state("state_location_introduction")
tester.user.metadata["ejaf_location_survey_status"] = "pending"
await tester.user_input("1")

tester.assert_state("state_location_province")
Expand Down
9 changes: 9 additions & 0 deletions yal/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
from yal.quiz import Application as QuizApplication
from yal.servicefinder import Application as ServiceFinderApplication
from yal.servicefinder_feedback_survey import ServiceFinderFeedbackSurveyApplication
from yal.surveys.baseline import Application as BaselineSurveyApplication
from yal.surveys.endline import Application as EndlineSurveyApplication
from yal.surveys.location import Application as LocationSurveyApplication
from yal.terms_and_conditions import Application as TermsApplication
from yal.tests.test_mainmenu import build_message_detail
from yal.usertest_feedback import Application as FeedbackApplication
Expand Down Expand Up @@ -49,6 +52,9 @@ def get_state_sets():
sf_s_states = set(
s for s in dir(ServiceFinderFeedbackSurveyApplication) if s.startswith("state_")
)
bs_states = set(s for s in dir(BaselineSurveyApplication) if s.startswith("state_"))
es_states = set(s for s in dir(EndlineSurveyApplication) if s.startswith("state_"))
ls_states = set(s for s in dir(LocationSurveyApplication) if s.startswith("state_"))
ss_states = set(s for s in dir(SegmentSurveyApplication) if s.startswith("state_"))
wa_fb_states = set(
s for s in dir(WaFbCrossoverFeedbackApplication) if s.startswith("state_")
Expand All @@ -69,6 +75,9 @@ def get_state_sets():
fb_states,
c_fb_states,
sf_s_states,
bs_states,
es_states,
ls_states,
ss_states,
wa_fb_states,
optin_states,
Expand Down

0 comments on commit 1a205d2

Please sign in to comment.