diff --git a/yal/surveys/location.py b/yal/surveys/location.py index 6571d9f1..5095a04a 100644 --- a/yal/surveys/location.py +++ b/yal/surveys/location.py @@ -1,3 +1,5 @@ +import asyncio + from vaccine.base_application import BaseApplication from vaccine.states import ( Choice, @@ -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 @@ -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): @@ -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 bwise@praekelt.org", + "", + "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": @@ -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( [ diff --git a/yal/tests/states_dictionary.md b/yal/tests/states_dictionary.md index ebc4776a..eb80de2d 100644 --- a/yal/tests/states_dictionary.md +++ b/yal/tests/states_dictionary.md @@ -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 diff --git a/yal/tests/surveys/test_location.py b/yal/tests/surveys/test_location.py index 84287ffa..94511104 100644 --- a/yal/tests/surveys/test_location.py +++ b/yal/tests/surveys/test_location.py @@ -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 bwise@praekelt.org", + "", + "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") diff --git a/yal/tests/test_main.py b/yal/tests/test_main.py index f38f9864..14b030ad 100644 --- a/yal/tests/test_main.py +++ b/yal/tests/test_main.py @@ -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 @@ -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_") @@ -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,