From 1f28caeeafa177d0cd7ab93a7efaae71b7cfe986 Mon Sep 17 00:00:00 2001 From: Erik Harding Date: Wed, 30 Aug 2023 09:48:12 +0200 Subject: [PATCH] Add tiktok trigger keyword --- yal/main.py | 4 ++++ yal/tests/test_main.py | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/yal/main.py b/yal/main.py index a29374c1..51bbcaf1 100644 --- a/yal/main.py +++ b/yal/main.py @@ -63,6 +63,7 @@ "i saw this on facebook", } TRACKING_KEYWORDS_ROUND_3 = {"youth", "yth", "yuth", "yut", "yoth", "yot", "yoh"} +TRACKING_KEYWORDS_TIKTOK = {"sho"} OPTOUT_KEYWORDS = {"stop", "opt out", "cancel", "quit"} ONBOARDING_REMINDER_KEYWORDS = { "continue", @@ -156,6 +157,7 @@ async def process_message(self, message): or keyword in TRACKING_KEYWORDS or keyword in TRACKING_KEYWORDS_ROUND_2 or keyword in TRACKING_KEYWORDS_ROUND_3 + or keyword in TRACKING_KEYWORDS_TIKTOK ): self.user.session_id = None self.state_name = self.START_STATE @@ -329,6 +331,7 @@ async def state_start(self): inbound in TRACKING_KEYWORDS or inbound in TRACKING_KEYWORDS_ROUND_2 or inbound in TRACKING_KEYWORDS_ROUND_3 + or inbound in TRACKING_KEYWORDS_TIKTOK ): self.save_answer("state_source_tracking", inbound) @@ -339,6 +342,7 @@ async def state_start(self): or inbound in TRACKING_KEYWORDS or inbound in TRACKING_KEYWORDS_ROUND_2 or inbound in TRACKING_KEYWORDS_ROUND_3 + or inbound in TRACKING_KEYWORDS_TIKTOK ): if terms_accepted and onboarding_completed: return await self.go_to_state(MainMenuApplication.START_STATE) diff --git a/yal/tests/test_main.py b/yal/tests/test_main.py index 67fd2ae5..5dbeed5e 100644 --- a/yal/tests/test_main.py +++ b/yal/tests/test_main.py @@ -987,6 +987,32 @@ async def test_tracked_keywords_saved_for_new_user_ads_round_3( tester.assert_answer("state_source_tracking", "yoth") +@pytest.mark.asyncio +async def test_tracked_keywords_tiktok( + tester: AppTester, rapidpro_mock, contentrepo_api_mock +): + rapidpro_mock.tstate.contact_fields["onboarding_completed"] = "True" + rapidpro_mock.tstate.contact_fields["terms_accepted"] = "True" + await tester.user_input("sho") + tester.assert_state("state_mainmenu") + tester.assert_num_messages(2) + + tester.assert_answer("state_source_tracking", "sho") + + +@pytest.mark.asyncio +async def test_tracked_keywords_saved_for_new_user_tiktok( + tester: AppTester, rapidpro_mock, contentrepo_api_mock +): + rapidpro_mock.tstate.contact_fields["onboarding_completed"] = "" + rapidpro_mock.tstate.contact_fields["terms_accepted"] = "" + await tester.user_input("sho") + tester.assert_state("state_welcome") + tester.assert_num_messages(1) + + tester.assert_answer("state_source_tracking", "sho") + + @pytest.mark.asyncio async def test_onboarding_reminder_response_to_reminder_handler( tester: AppTester, rapidpro_mock