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

change endline validation #658

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion yal/assessments.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ async def state_remind_tomorrow(self):

question = "No problem! I'll remind you tomorrow"

if endline_survey_started:
if endline_survey_started == "True":
return FreeText(self, question=question, next=None)
else:
return WhatsAppButtonState(
Expand Down
14 changes: 13 additions & 1 deletion yal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ async def process_message(self, message):
else:
self.state_name = EndlineTermsApplication.START_STATE

data = {
"endline_survey_started": "True",
}
error = await rapidpro.update_profile(
whatsapp_id, data, self.user.metadata
)
if error:
return await self.go_to_state("state_error")

# Fields that RapidPro sets after a feedback push message
elif feedback_state:
if not self.user.session_id:
Expand All @@ -254,7 +263,10 @@ async def process_message(self, message):
self.save_metadata("push_related_page_id", payload.split("_")[-1])
self.state_name = "state_prep_push_msg_related_page"

elif endline_survey_started and keyword not in EJAF_ENDLINE_SURVEY_KEYWORDS:
elif (
endline_survey_started == "Pending"
and keyword not in EJAF_ENDLINE_SURVEY_KEYWORDS
):
self.user.session_id = None
self.state_name = EndlineSurveyApplication.SURVEY_VALIDATION_STATE

Expand Down
44 changes: 37 additions & 7 deletions yal/tests/surveys/test_endline.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ async def test_endline_invitation_i_want_to_answer(tester: AppTester, rapidpro_m
addr="278201234567",
state=StateData(),
session_id=1,
metadata={"baseline_survey_completed": True, "endline_survey_started": True},
metadata={
"baseline_survey_completed": True,
"endline_survey_started": "Pending",
},
)
app = Application(user)
msg = Message(
Expand All @@ -102,7 +105,10 @@ async def test_endline_invitation_remind_me_tomorrow(
addr="278201234567",
state=StateData(),
session_id=1,
metadata={"baseline_survey_completed": True, "endline_survey_started": True},
metadata={
"baseline_survey_completed": True,
"endline_survey_started": "Pending",
},
)
app = Application(user)
msg = Message(
Expand All @@ -127,7 +133,10 @@ async def test_endline_invitation_not_interested(
addr="278201234567",
state=StateData(),
session_id=1,
metadata={"baseline_survey_completed": True, "endline_survey_started": True},
metadata={
"baseline_survey_completed": True,
"endline_survey_started": "Pending",
},
)
app = Application(user)
msg = Message(
Expand Down Expand Up @@ -155,7 +164,7 @@ async def test_endline_reminder_not_interested(
metadata={
"baseline_survey_completed": True,
"endline_reminder": True,
"endline_survey_started": True,
"endline_survey_started": "Pegndin",
},
)
app = Application(user)
Expand All @@ -179,7 +188,10 @@ async def test_endline_invitation_answer(tester: AppTester, rapidpro_mock):
addr="278201234567",
state=StateData(),
session_id=1,
metadata={"baseline_survey_completed": True, "endline_survey_started": True},
metadata={
"baseline_survey_completed": True,
"endline_survey_started": "Pending",
},
)
app = Application(user)
msg = Message(
Expand All @@ -202,7 +214,10 @@ async def test_endline_survey_validation(tester: AppTester, rapidpro_mock):
addr="278201234567",
state=StateData(),
session_id=1,
metadata={"baseline_survey_completed": True, "endline_survey_started": True},
metadata={
"baseline_survey_completed": True,
"endline_survey_started": "Pending",
},
)
app = Application(user)
msg = Message(
Expand Down Expand Up @@ -1039,7 +1054,7 @@ async def test_state_body_image_assessment_endline_reminder(

@pytest.mark.asyncio
async def test_endline_stop_during_assessment(tester: AppTester, rapidpro_mock):
tester.user.metadata["endline_survey_started"] = True
tester.user.metadata["endline_survey_started"] = "Pending"
tester.user.metadata["baseline_survey_completed"] = True
tester.user.metadata["terms_accepted"] = True
tester.user.metadata["onboarding_completed"] = True
Expand Down Expand Up @@ -1264,3 +1279,18 @@ async def test_endline_flow(tester: AppTester, rapidpro_mock):
)

tester.assert_message(message)


@pytest.mark.asyncio
async def test_endline_agree_terms_and_condition(tester: AppTester, rapidpro_mock):
tester.user.metadata["baseline_survey_completed"] = True
tester.user.metadata["endline_survey_started"] = "Pending"
tester.user.metadata["terms_accepted"] = True
tester.user.metadata["onboarding_completed"] = True

await tester.user_input("Yes, I want to answer")
tester.assert_state("state_start_terms")
tester.assert_metadata("endline_survey_started", "True")

await tester.user_input("Yes, I agree")
tester.assert_state("state_accept_consent")
4 changes: 2 additions & 2 deletions yal/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ async def test_endline_catch_all(
rapidpro_mock.tstate.contact_fields["onboarding_completed"] = True
rapidpro_mock.tstate.contact_fields["terms_accepted"] = True
rapidpro_mock.tstate.contact_fields["assessment_reminder_sent"] = True
rapidpro_mock.tstate.contact_fields["endline_survey_started"] = True
rapidpro_mock.tstate.contact_fields["endline_survey_started"] = "Pending"

await tester.user_input("this is giberish")
tester.assert_state("state_survey_validation")
Expand All @@ -468,7 +468,7 @@ async def test_survey_stop(tester: AppTester, rapidpro_mock, contentrepo_api_moc
rapidpro_mock.tstate.contact_fields["onboarding_completed"] = True
rapidpro_mock.tstate.contact_fields["terms_accepted"] = True
rapidpro_mock.tstate.contact_fields["assessment_reminder_sent"] = True
rapidpro_mock.tstate.contact_fields["endline_survey_started"] = True
rapidpro_mock.tstate.contact_fields["endline_survey_started"] = "Pending"

await tester.user_input("stop")
tester.assert_state("state_optout")
Expand Down
Loading