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

Add support for testing that flows have run #49

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: praekeltfoundation/flow_tester
ref: v0.1.1
ref: v0.2.1
path: flow_tester
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}

Expand Down
62 changes: 19 additions & 43 deletions Onboarding/QA/tests/profile-generic_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ defmodule ProfileGenericTest do

alias FlowTester.WebhookHandler, as: WH

alias Onboarding.QA.Helpers

import Onboarding.QA.Helpers.Macros

defp flow_path(flow_name), do: Path.join([__DIR__, "..","flows", flow_name <> ".json"])

def setup_fake_cms(auth_token) do
Expand Down Expand Up @@ -112,45 +116,16 @@ defmodule ProfileGenericTest do
|> FlowTester.set_global_dict("config", %{"contentrepo_token" => auth_token})
end

defp init_basic_info(context) do
context |> FlowTester.set_contact_properties(%{"year_of_birth" => "1988", "province" => "Western Cape", "area_type" => "", "gender" => "male"})
end

defp init_personal_info(context) do
context |> FlowTester.set_contact_properties(%{"relationship_status" => "", "education" => "", "socio_economic" => "", "other_children" => ""})
end

defp init_daily_life(context) do
context |> FlowTester.set_contact_properties(%{"dma_01" => "answer", "dma_02" => "", "dma_03" => "", "dma_04" => "", "dma_05" => ""})
end

# This lets us have cleaner button/list assertions.
def indexed_list(var, labels) do
Enum.with_index(labels, fn lbl, idx -> {"@#{var}[#{idx}]", lbl} end)
end

# The common case for buttons.
defmacro button_labels(labels) do
quote do: unquote(indexed_list("button_labels", labels))
end

# The common case for lists.
defmacro list_items(labels) do
quote do: unquote(indexed_list("list_items", labels))
end

describe "profile generic" do
test "30% complete" do
setup_flow()
|> init_basic_info()
|> init_personal_info()
|> init_daily_life()
|> FlowTester.start()
|> Helpers.handle_basic_profile_flow()
|> fn step ->
[msg] = step.messages
assert String.contains?(msg.text, "Basic information 3/4")
assert String.contains?(msg.text, "Personal information 0/4")
assert String.contains?(msg.text, "Daily life 1/5")
assert String.contains?(msg.text, "Daily life 0/5")
step
end.()
|> receive_message(%{
Expand All @@ -161,15 +136,13 @@ defmodule ProfileGenericTest do

test "30% complete -> why -> let's go" do
setup_flow()
|> FlowTester.set_contact_properties(%{"year_of_birth" => "1988", "province" => "Western Cape", "area_type" => "", "gender" => "male"}) # Basic Information
|> FlowTester.set_contact_properties(%{"relationship_status" => "", "education" => "", "socio_economic" => "", "other_children" => ""}) # Personal Information
|> FlowTester.set_contact_properties(%{"dma_01" => "answer", "dma_02" => "answer2",}) # Daily Life
|> FlowTester.start()
|> Helpers.handle_basic_profile_flow()
|> fn step ->
[msg] = step.messages
assert String.contains?(msg.text, "Basic information 3/4")
assert String.contains?(msg.text, "Personal information 0/4")
assert String.contains?(msg.text, "Daily life 2/5")
assert String.contains?(msg.text, "Daily life 0/5")
step
end.()
|> receive_message(%{
Expand All @@ -182,6 +155,9 @@ defmodule ProfileGenericTest do
buttons: button_labels(["Yes, let's go", "Not right now"])
})
|> FlowTester.send(button_label: "Yes, let's go")
|> Helpers.handle_personal_info_flow()
|> Helpers.handle_daily_life_flow()
|> Helpers.handle_opt_in_reminder_flow()
|> receive_message(%{
text: "🟩🟩🟩🟩🟩🟩🟩🟩\r\n\r\nYour profile is 100% complete" <> _,
buttons: button_labels(["Explore health guide", "View topics for you", "Go to main menu"])
Expand All @@ -190,10 +166,8 @@ defmodule ProfileGenericTest do

test "30% complete -> why -> not right now" do
setup_flow()
|> FlowTester.set_contact_properties(%{"year_of_birth" => "1988", "province" => "Western Cape", "area_type" => "", "gender" => "male"}) # Basic Information
|> FlowTester.set_contact_properties(%{"relationship_status" => "", "education" => "", "socio_economic" => "", "other_children" => ""}) # Personal Information
|> FlowTester.set_contact_properties(%{}) # Daily Life
|> FlowTester.start()
|> Helpers.handle_basic_profile_flow()
|> fn step ->
[msg] = step.messages
assert String.contains?(msg.text, "Basic information 3/4")
Expand All @@ -219,16 +193,17 @@ defmodule ProfileGenericTest do

test "100% complete - all complete" do
setup_flow()
|> FlowTester.set_contact_properties(%{"year_of_birth" => "1988", "province" => "Western Cape", "area_type" => "something", "gender" => "male"}) # Basic Information
|> FlowTester.set_contact_properties(%{"relationship_status" => "married", "education" => "degree", "socio_economic" => "something", "other_children" => "0"}) # Personal Information
|> FlowTester.set_contact_properties(%{"name" => "Severus"})
|> FlowTester.set_contact_properties(%{"opted_in" => "true"})
|> FlowTester.start()
|> Helpers.handle_basic_profile_flow(year_of_birth: "1988", province: "Western Cape", area_type: "rural", gender: "male")
|> receive_message(%{
text: "Your profile is already 30% complete" <> _,
buttons: button_labels(["Continue", "Why?"])
})
|> FlowTester.send(button_label: "Continue")
|> Helpers.handle_personal_info_flow(relationship_status: "single", education: "degree", socio_economic: "i get by", other_children: "0")
|> Helpers.handle_daily_life_flow()
|> fn step ->
[msg] = step.messages
assert String.contains?(msg.text, "*Name:* Severus")
Expand All @@ -245,17 +220,18 @@ defmodule ProfileGenericTest do

test "100% complete - incomplete basic info" do
setup_flow()
|> FlowTester.set_contact_properties(%{"year_of_birth" => "1988", "province" => "Western Cape", "area_type" => "", "gender" => "male"}) # Basic Information
|> FlowTester.set_contact_properties(%{"relationship_status" => "", "education" => "", "socio_economic" => "", "other_children" => ""}) # Personal Information
|> FlowTester.set_contact_properties(%{}) # Daily Life
|> FlowTester.set_contact_properties(%{"name" => "Severus"})
|> FlowTester.set_contact_properties(%{"opted_in" => "false"})
|> FlowTester.start()
|> Helpers.handle_basic_profile_flow()
|> receive_message(%{
text: "Your profile is already 30% complete" <> _,
buttons: button_labels(["Continue", "Why?"])
})
|> FlowTester.send(button_label: "Continue")
|> Helpers.handle_personal_info_flow()
|> Helpers.handle_daily_life_flow()
|> Helpers.handle_opt_in_reminder_flow()
|> fn step ->
[msg] = step.messages
assert String.contains?(msg.text, "*Name:* Severus")
Expand Down
41 changes: 11 additions & 30 deletions Onboarding/QA/tests/profile-pregnancy-health_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ defmodule ProfilePregnancyHealthTest do

alias FlowTester.WebhookHandler, as: WH

alias Onboarding.QA.Helpers

import Onboarding.QA.Helpers.Macros

defp flow_path(flow_name), do: Path.join([__DIR__, "..","flows", flow_name <> ".json"])

def setup_fake_cms(auth_token) do
Expand Down Expand Up @@ -279,35 +283,12 @@ defmodule ProfilePregnancyHealthTest do
|> FlowTester.set_global_dict("config", %{"contentrepo_token" => auth_token})
end

defp init_basic_info(context) do
context |> FlowTester.set_contact_properties(%{"year_of_birth" => "1988", "province" => "Western Cape", "area_type" => "", "gender" => "male"})
end

defp init_personal_info(context) do
context |> FlowTester.set_contact_properties(%{"relationship_status" => "", "education" => "", "socio_economic" => "", "other_children" => ""})
end

defp init_daily_life(context) do
context |> FlowTester.set_contact_properties(%{"dma_01" => "", "dma_02" => "", "dma_03" => "", "dma_04" => "", "dma_05" => ""})
end

defp init_pregnancy_info(context) do
context |> FlowTester.set_contact_properties(%{"pregnancy_status" => "im_pregnant", "edd" => "24/04/2026", "pregnancy_sentiment" => "excited"})
end

# This lets us have cleaner button/list assertions.
def indexed_list(var, labels) do
Enum.with_index(labels, fn lbl, idx -> {"@#{var}[#{idx}]", lbl} end)
end

# The common case for buttons.
defmacro button_labels(labels) do
quote do: unquote(indexed_list("button_labels", labels))
end

# The common case for lists.
defmacro list_items(labels) do
quote do: unquote(indexed_list("list_items", labels))
defp init_contact_fields(context) do
context |> FlowTester.set_contact_properties(%{"gender" => "", "name" => "Lily", "opted_in" => "true"})
end

describe "profile pregnancy health" do
Expand Down Expand Up @@ -352,12 +333,9 @@ defmodule ProfilePregnancyHealthTest do
full_edd = Calendar.strftime(this_month_plus_one, "%Y") <> "-" <> "#{edd_month}" <> "-25"

setup_flow()
|> Helpers.init_contact_fields()
|> init_contact_fields()
|> init_pregnancy_info()
|> init_basic_info()
|> init_personal_info()
|> init_daily_life()
|> FlowTester.set_contact_properties(%{"gender" => "", "name" => "Lily"})
|> FlowTester.set_contact_properties(%{"opted_in" => "true"})
|> FlowTester.start()
|> receive_message(%{
text: "I've got a *lot* of information on pregnancy" <> _,
Expand Down Expand Up @@ -422,6 +400,7 @@ defmodule ProfilePregnancyHealthTest do
buttons: button_labels(["➡️ Complete profile", "View topics for you", "Explore health guide"])
})
|> FlowTester.send(button_label: "➡️ Complete profile")
|> Helpers.handle_basic_profile_flow(year_of_birth: "1988", province: "Western Cape", area_type: "", gender: "male")
|> contact_matches(%{"profile_completion" => "50%"})
|> fn step ->
[msg] = step.messages
Expand All @@ -436,6 +415,8 @@ defmodule ProfilePregnancyHealthTest do
buttons: button_labels(["Continue"])
})
|> FlowTester.send(button_label: "Continue")
|> Helpers.handle_personal_info_flow(relationship_status: "", education: "", socio_economic: "", other_children: "")
|> Helpers.handle_daily_life_flow()
|> contact_matches(%{"profile_completion" => "100%"})
|> fn step ->
[msg] = step.messages
Expand Down
48 changes: 9 additions & 39 deletions Onboarding/QA/tests/profile-pregnant-nurse_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ defmodule ProfilePregnantNurseTest do

alias FlowTester.WebhookHandler, as: WH

alias Onboarding.QA.Helpers

import Onboarding.QA.Helpers.Macros

defp flow_path(flow_name), do: Path.join([__DIR__, "..","flows", flow_name <> ".json"])

def setup_fake_cms(auth_token) do
Expand Down Expand Up @@ -129,57 +133,23 @@ defmodule ProfilePregnantNurseTest do
|> FlowTester.set_global_dict("config", %{"contentrepo_token" => auth_token})
end

defp init_basic_info(context) do
context |> FlowTester.set_contact_properties(%{"year_of_birth" => "", "province" => "", "area_type" => "", "gender" => ""})
end

defp init_personal_info(context) do
context |> FlowTester.set_contact_properties(%{"relationship_status" => "", "education" => "", "socio_economic" => "", "other_children" => ""})
end

defp init_daily_life(context) do
context |> FlowTester.set_contact_properties(%{"dma_01" => "", "dma_02" => "", "dma_03" => "", "dma_04" => "", "dma_05" => ""})
end

defp init_hcw_info(context) do
context |> FlowTester.set_contact_properties(%{"occupational_role" => "", "facility_type" => "", "professional_support" => ""})
end

defp init_pregnancy_info(context) do
context |> FlowTester.set_contact_properties(%{"pregnancy_status" => "im_pregnant", "edd" => "24/04/2026", "pregnancy_sentiment" => "excited"})
end

# This lets us have cleaner button/list assertions.
def indexed_list(var, labels) do
Enum.with_index(labels, fn lbl, idx -> {"@#{var}[#{idx}]", lbl} end)
end

# The common case for buttons.
defmacro button_labels(labels) do
quote do: unquote(indexed_list("button_labels", labels))
end

# The common case for lists.
defmacro list_items(labels) do
quote do: unquote(indexed_list("list_items", labels))
end

describe "profile pregnant nurse" do
test "100% complete" do
setup_flow()
|> init_pregnancy_info()
|> init_basic_info()
|> init_personal_info()
|> init_daily_life()
|> init_hcw_info()
|> Helpers.init_contact_fields()
|> FlowTester.start()
|> contact_matches(%{"profile_completion" => "20%", "checkpoint" => "pregnant_nurse_profile_20"})
|> receive_message(%{
text: "🟩🟩⬜⬜⬜⬜⬜⬜\r\n\r\nYour profile is already 20% complete!" <> _,
buttons: button_labels(["➡️ Complete profile", "View topics for you", "Explore health guide"])
})
|> FlowTester.set_contact_properties(%{"occupational_role" => "EN", "facility_type" => "Clinic", "professional_support" => "sometimes"}) # HCW
|> FlowTester.send(button_label: "➡️ Complete profile")
|> Helpers.handle_profile_hcw_flow(occupational_role: "EN", facility_type: "Clinic", professional_support: "sometimes")
|> contact_matches(%{"profile_completion" => "40%", "checkpoint" => "pregnant_nurse_profile_40"})
|> fn step ->
[msg] = step.messages
Expand All @@ -194,8 +164,8 @@ defmodule ProfilePregnantNurseTest do
text: "🟩🟩🟩🟩⬜⬜⬜⬜\r\n\r\nYour profile is already 40% complete! 🎉" <> _,
buttons: button_labels(["Continue"])
})
|> FlowTester.set_contact_properties(%{"year_of_birth" => "1998", "province" => "prov_1", "area_type" => "rural", "gender" => "female"}) # Basic Information
|> FlowTester.send(button_label: "Continue")
|> Helpers.handle_basic_profile_flow(year_of_birth: "1998", province: "prov_1", area_type: "rural", gender: "female")
|> contact_matches(%{"profile_completion" => "60%", "checkpoint" => "pregnant_nurse_profile_60"})
|> fn step ->
[msg] = step.messages
Expand All @@ -210,8 +180,8 @@ defmodule ProfilePregnantNurseTest do
text: "Thanks for sharing!\r\n\r\nNow is your chance to tell me more about yourself." <> _,
buttons: button_labels(["Continue ➡️", "Why should I?"])
})
|> FlowTester.set_contact_properties(%{"relationship_status" => "married", "education" => "school", "other_children" => "1"}) # Personal Information
|> FlowTester.send(button_label: "Continue ➡️")
|> Helpers.handle_personal_info_flow(relationship_status: "married", education: "school", socio_economic: "", other_children: "1")
|> contact_matches(%{"profile_completion" => "80%", "checkpoint" => "pregnant_nurse_profile_80"})
|> fn step ->
[msg] = step.messages
Expand All @@ -226,8 +196,8 @@ defmodule ProfilePregnantNurseTest do
text: "🟩🟩🟩🟩🟩🟩⬜⬜" <> _,
buttons: button_labels(["➡️ Complete it!", "Remind me later"])
})
|> FlowTester.set_contact_properties(%{"dma_01" => "answer", "dma_02" => ""}) # Daily Life
|> FlowTester.send(button_label: "➡️ Complete it!")
|> Helpers.handle_daily_life_flow()
|> fn step ->
[msg] = step.messages
assert String.contains?(msg.text, "Pregnancy info 3/3")
Expand Down
Loading
Loading