Skip to content

Commit

Permalink
Merge pull request #54 from praekeltfoundation/test-fake-time
Browse files Browse the repository at this point in the history
Add a test using fake time
  • Loading branch information
HawkiesZA authored Sep 25, 2024
2 parents 2f88346 + 9c96922 commit 6269387
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 8 deletions.
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.2.2
ref: v0.3.0
path: flow_tester
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}

Expand Down
1 change: 1 addition & 0 deletions HelpCentre/QA/tests/agent-greeting_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule AgentGreetingTest do
defp flow_path(flow_name), do: Path.join([__DIR__, "..", "flows_json", flow_name <> ".json"])

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down
1 change: 1 addition & 0 deletions HelpCentre/QA/tests/agent-wrap-up_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule AgentWrapUpTest do
defp flow_path(flow_name), do: Path.join([__DIR__, "..", "flows_json", flow_name <> ".json"])

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down
1 change: 1 addition & 0 deletions HelpCentre/QA/tests/intro-human-agent_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule IntroHumanAgentTest do
defp flow_path(flow_name), do: Path.join([__DIR__, "..", "flows_json", flow_name <> ".json"])

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down
1 change: 1 addition & 0 deletions HelpCentre/QA/tests/intro-to-helpcentre_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule IntroToHelpCentreTest do
defp flow_path(flow_name), do: Path.join([__DIR__, "..", "flows_json", flow_name <> ".json"])

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule ScheduledCallbackConfirmationTest do
defp flow_path(flow_name), do: Path.join([__DIR__, "..", "flows_json", flow_name <> ".json"])

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down
1 change: 1 addition & 0 deletions HelpCentre/QA/tests/scheduled-callback-followup_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule ScheduledCallbackfollowupTest do
defp flow_path(flow_name), do: Path.join([__DIR__, "..", "flows_json", flow_name <> ".json"])

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down
1 change: 1 addition & 0 deletions HelpCentre/QA/tests/scheduled-query-rating_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule ScheduledQueryRatingTest do
defp flow_path(flow_name), do: Path.join([__DIR__, "..", "flows_json", flow_name <> ".json"])

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule ScheduledTopicsNoResponseFollowupTest do
defp flow_path(flow_name), do: Path.join([__DIR__, "..", "flows_json", flow_name <> ".json"])

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down
1 change: 1 addition & 0 deletions Onboarding/QA/tests/basic-questions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule BasicQuestionsTest do
import Onboarding.QA.Helpers.Macros

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down
3 changes: 1 addition & 2 deletions Onboarding/QA/tests/intro-and-welcome_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ defmodule IntroAndWelcomeTest do

alias FlowTester.WebhookHandler, as: WH

alias FlowTester.WebhookHandler.FakeCMS.Content.Document

alias Onboarding.QA.Helpers

import Onboarding.QA.Helpers.Macros

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down
1 change: 1 addition & 0 deletions Onboarding/QA/tests/personal-profile-questions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule PersonalProfileQuestionsTest do
alias Onboarding.QA.Helpers

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down
1 change: 1 addition & 0 deletions Onboarding/QA/tests/profile-generic_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule ProfileGenericTest do
import Onboarding.QA.Helpers.Macros

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down
1 change: 1 addition & 0 deletions Onboarding/QA/tests/profile-hcw_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule ProfileHCWTest do
import Onboarding.QA.Helpers.Macros

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down
153 changes: 148 additions & 5 deletions Onboarding/QA/tests/profile-pregnancy-health_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ defmodule ProfilePregnancyHealthTest do
use FlowTester.Case

alias FlowTester.WebhookHandler, as: WH
alias FlowTester.WebhookHandler.FakeCMS.Content.{Image}

alias Onboarding.QA.Helpers

import Onboarding.QA.Helpers.Macros

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down Expand Up @@ -801,8 +801,7 @@ defmodule ProfilePregnancyHealthTest do
context |> FlowTester.set_contact_properties(%{"gender" => "", "name" => "Lily", "opted_in" => "true"})
end

defp get_months() do
this_month = DateTime.utc_now()
defp get_months(this_month \\ DateTime.utc_now()) do
[
this_month,
Date.shift(this_month, month: 1),
Expand Down Expand Up @@ -1323,8 +1322,152 @@ defmodule ProfilePregnancyHealthTest do
})
end

# TODO: Tests for Feb, long months, and short months. This requires us to be able to mock the return value of now() so that we can dictacte what options
# are available in the list of months.
test "edd day then feb 29 is valid" do
fake_time = ~U[2023-02-28 00:00:00Z]
months = get_months(fake_time)
month_words = get_month_words(months)
{list_of_months, edd_confirmation_text, _full_edd} = get_edd(months, month_words, 29, 0)
month = elem(Enum.at(list_of_months, 0), 0)

setup_flow()
|> FlowTester.set_fake_time(fake_time)
|> Helpers.init_contact_fields()
|> init_contact_fields()
|> init_pregnancy_info()
|> FlowTester.start()
|> receive_message(%{})
|> FlowTester.send(button_label: "I'm pregnant")
|> receive_message(%{})
|> FlowTester.send(month)
|> receive_message(%{})
|> FlowTester.send("29")
|> receive_message(%{
text: ^edd_confirmation_text,
buttons: button_labels(["Yes, that's right", "Pick another date"])
})
end

test "edd day then feb 30 is not valid" do
fake_time = ~U[2023-02-28 00:00:00Z]
months = get_months(fake_time)
month_words = get_month_words(months)
{list_of_months, _edd_confirmation_text, _full_edd} = get_edd(months, month_words)
month = elem(Enum.at(list_of_months, 0), 0)

setup_flow()
|> FlowTester.set_fake_time(fake_time)
|> Helpers.init_contact_fields()
|> init_contact_fields()
|> init_pregnancy_info()
|> FlowTester.start()
|> receive_message(%{})
|> FlowTester.send(button_label: "I'm pregnant")
|> receive_message(%{})
|> FlowTester.send(month)
|> receive_message(%{})
|> FlowTester.send("30")
|> receive_message(%{
text: "I don't understand your reply.\r\n\r\n👇🏽 Please try that again and respond with the number that comes before your answer."
})
end

test "edd day then long month 31 is valid" do
fake_time = ~U[2023-01-01 00:00:00Z] # January
months = get_months(fake_time)
month_words = get_month_words(months)
{list_of_months, edd_confirmation_text, _full_edd} = get_edd(months, month_words, 31, 0)
month = elem(Enum.at(list_of_months, 0), 0)

setup_flow()
|> FlowTester.set_fake_time(fake_time)
|> Helpers.init_contact_fields()
|> init_contact_fields()
|> init_pregnancy_info()
|> FlowTester.start()
|> receive_message(%{})
|> FlowTester.send(button_label: "I'm pregnant")
|> receive_message(%{})
|> FlowTester.send(month)
|> receive_message(%{})
|> FlowTester.send("31")
|> receive_message(%{
text: ^edd_confirmation_text,
buttons: button_labels(["Yes, that's right", "Pick another date"])
})
end

test "edd day then long month 32 is invalid" do
fake_time = ~U[2024-01-01 00:00:00Z] # January
months = get_months(fake_time)
month_words = get_month_words(months)
{list_of_months, _edd_confirmation_text, _full_edd} = get_edd(months, month_words)
month = elem(Enum.at(list_of_months, 0), 0)

setup_flow()
|> FlowTester.set_fake_time(fake_time)
|> Helpers.init_contact_fields()
|> init_contact_fields()
|> init_pregnancy_info()
|> FlowTester.start()
|> receive_message(%{})
|> FlowTester.send(button_label: "I'm pregnant")
|> receive_message(%{})
|> FlowTester.send(month)
|> receive_message(%{})
|> FlowTester.send("32")
|> receive_message(%{
text: "I don't understand your reply.\r\n\r\n👇🏽 Please try that again and respond with the number that comes before your answer."
})
end

test "edd day then short month 30 is valid" do
fake_time = ~U[2024-04-01 00:00:00Z] # April
months = get_months(fake_time)
month_words = get_month_words(months)
{list_of_months, edd_confirmation_text, _full_edd} = get_edd(months, month_words, 30, 0)
month = elem(Enum.at(list_of_months, 0), 0)

setup_flow()
|> FlowTester.set_fake_time(fake_time)
|> Helpers.init_contact_fields()
|> init_contact_fields()
|> init_pregnancy_info()
|> FlowTester.start()
|> receive_message(%{})
|> FlowTester.send(button_label: "I'm pregnant")
|> receive_message(%{})
|> FlowTester.send(month)
|> receive_message(%{})
|> FlowTester.send("30")
|> receive_message(%{
text: ^edd_confirmation_text,
buttons: button_labels(["Yes, that's right", "Pick another date"])
})
end

test "edd day then short month 31 is invalid" do
fake_time = ~U[2024-04-01 00:00:00Z] # April
months = get_months(fake_time)
month_words = get_month_words(months)
{list_of_months, _edd_confirmation_text, _full_edd} = get_edd(months, month_words)
month = elem(Enum.at(list_of_months, 0), 0)

setup_flow()
|> FlowTester.set_fake_time(fake_time)
|> Helpers.init_contact_fields()
|> init_contact_fields()
|> init_pregnancy_info()
|> FlowTester.start()
|> receive_message(%{})
|> FlowTester.send(button_label: "I'm pregnant")
|> receive_message(%{})
|> FlowTester.send(month)
|> receive_message(%{})
|> FlowTester.send("31")
|> receive_message(%{
text: "I don't understand your reply.\r\n\r\n👇🏽 Please try that again and respond with the number that comes before your answer."
})
end

test "edd confirm then error" do
months = get_months()
Expand Down
1 change: 1 addition & 0 deletions Onboarding/QA/tests/profile-pregnant-nurse_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule ProfilePregnantNurseTest do
import Onboarding.QA.Helpers.Macros

def setup_fake_cms(auth_token) do
use FakeCMS
# Start the handler.
wh_pid = start_link_supervised!({FakeCMS, %FakeCMS.Config{auth_token: auth_token}})

Expand Down

0 comments on commit 6269387

Please sign in to comment.