Skip to content

Commit

Permalink
send correct message after invite not interested and remove unnecessa…
Browse files Browse the repository at this point in the history
…ry if statemen
  • Loading branch information
Hlamallama committed Nov 16, 2023
1 parent 229ddb1 commit f59fc45
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 61 deletions.
1 change: 1 addition & 0 deletions yal/assessments.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class Application(BaseApplication):
LATER_STATE = "state_assessment_later_submit"
REMINDER_STATE = "state_handle_assessment_reminder_response"
REMINDER_NOT_INTERESTED_STATE = "state_reminder_not_interested"
NOT_INTERESTED_STATE = "state_not_interested"

def clean_name(self, name):
return name.removeprefix("state_").removesuffix("_assessment")
Expand Down
17 changes: 1 addition & 16 deletions yal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ async def process_message(self, message):
)

endline_survey_started = self.user.metadata.get("endline_survey_started")
endline_reminder = self.user.metadata.get("endline_reminder")
feedback_state = await self.get_feedback_state()
payload = utils.get_by_path(
message.transport_metadata, "message", "button", "payload"
Expand Down Expand Up @@ -232,21 +231,7 @@ async def process_message(self, message):
if keyword == "remind me tomorrow":
self.state_name = AssessmentApplication.REMINDER_STATE
elif keyword == "i m not interested":
if endline_reminder:
self.state_name = (
AssessmentApplication.REMINDER_NOT_INTERESTED_STATE
)
else:
self.state_name = EndlineTermsApplication.NO_CONSENT_STATE

data = {
"endline_survey_started": "not_interested",
}
error = await rapidpro.update_profile(
whatsapp_id, data, self.user.metadata
)
if error:
return await self.go_to_state("state_error")
self.state_name = AssessmentApplication.NOT_INTERESTED_STATE
else:
self.state_name = EndlineTermsApplication.START_STATE

Expand Down
31 changes: 1 addition & 30 deletions yal/tests/surveys/test_endline.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,36 +149,7 @@ async def test_endline_invitation_not_interested(

[reply] = await app.process_message(msg)

assert user.state.name == "state_no_consent"


@pytest.mark.asyncio
async def test_endline_reminder_not_interested(
tester: AppTester,
rapidpro_mock,
):
user = User(
addr="278201234567",
state=StateData(),
session_id=1,
metadata={
"baseline_survey_completed": True,
"endline_reminder": True,
"endline_survey_started": "Pending",
},
)
app = Application(user)
msg = Message(
content="I'm not interested",
to_addr="27820001002",
from_addr="27820001003",
transport_name="whatsapp",
transport_type=Message.TRANSPORT_TYPE.HTTP_API,
)

[reply] = await app.process_message(msg)

assert user.state.name == "state_reminder_not_interested"
assert user.state.name == "state_not_interested"


@pytest.mark.asyncio
Expand Down
16 changes: 1 addition & 15 deletions yal/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,20 +873,6 @@ async def test_endline_remind_me_tomorrow_keywords(
tester.assert_state("state_remind_tomorrow")


@pytest.mark.asyncio
async def test_endline_survey_not_interested_reminder_keywords(
tester: AppTester, rapidpro_mock, contentrepo_api_mock
):
rapidpro_mock.tstate.contact_fields["onboarding_completed"] = True
rapidpro_mock.tstate.contact_fields["terms_accepted"] = True
rapidpro_mock.tstate.contact_fields["baseline_survey_completed"] = True
rapidpro_mock.tstate.contact_fields["endline_survey_completed"] = False
rapidpro_mock.tstate.contact_fields["endline_reminder"] = True

await tester.user_input("I'm not interested")
tester.assert_state("state_reminder_not_interested")


@pytest.mark.asyncio
async def test_endline_survey_not_interested_keywords(
tester: AppTester, rapidpro_mock, contentrepo_api_mock
Expand All @@ -897,7 +883,7 @@ async def test_endline_survey_not_interested_keywords(
rapidpro_mock.tstate.contact_fields["endline_survey_completed"] = False

await tester.user_input("I'm not interested")
tester.assert_state("state_no_consent")
tester.assert_state("state_not_interested")

tester.assert_metadata("endline_survey_started", "not_interested")

Expand Down

0 comments on commit f59fc45

Please sign in to comment.