Skip to content

Commit

Permalink
Merge pull request #58 from praekeltfoundation/shared-flow-loading-he…
Browse files Browse the repository at this point in the history
…lpcentre

Move flow loading to setup_all in HelpCentre tests
  • Loading branch information
jerith authored Oct 22, 2024
2 parents 3db709a + 962981a commit 5ad60ed
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 96 deletions.
7 changes: 3 additions & 4 deletions HelpCentre/QA/tests/agent-greeting_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ defmodule AgentGreetingTest do
use FlowTester.Case
alias FlowTester.WebhookHandler, as: WH
alias HelpCentre.QA.Helpers
# alias FlowTester.FlowStep, as: Step
defp flow_path(flow_name), do: Path.join([__DIR__, "..", "flows_json", flow_name <> ".json"])

def setup_fake_cms(auth_token) do
use FakeCMS
Expand Down Expand Up @@ -46,14 +44,15 @@ defmodule AgentGreetingTest do
})
end

setup_all _ctx, do: %{init_flow: Helpers.load_flow("agent-greeting")}

defp setup_flow(ctx) do
# When talking to real contentrepo, get the auth token from the CMS_AUTH_TOKEN envvar.
auth_token = System.get_env("CMS_AUTH_TOKEN", "CRauthTOKEN123")
kind = if auth_token == "CRauthTOKEN123", do: :fake, else: :real

flow =
flow_path("agent-greeting")
|> FlowTester.from_json!()
ctx.init_flow
|> real_or_fake_cms("https://content-repo-api-qa.prk-k8s.prd-p6t.org/", auth_token, kind)
|> FlowTester.set_global_dict("settings", %{"contentrepo_qa_token" => auth_token})
|> Helpers.setup_fake_turn(ctx)
Expand Down
40 changes: 22 additions & 18 deletions HelpCentre/QA/tests/agent-wrap-up_test.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
defmodule AgentWrapUpTest do
use FlowTester.Case
alias FlowTester.WebhookHandler, as: WH
# alias FlowTester.FlowStep
defp flow_path(flow_name), do: Path.join([__DIR__, "..", "flows_json", flow_name <> ".json"])
alias HelpCentre.QA.Helpers

def setup_fake_cms(auth_token) do
use FakeCMS
Expand Down Expand Up @@ -130,18 +129,23 @@ defmodule AgentWrapUpTest do
})
end

defp setup_flow() do
setup_all _ctx, do: %{init_flow: Helpers.load_flow("agent-wrap-up")}

defp setup_flow(%{init_flow: init_flow}) do
# When talking to real contentrepo, get the auth token from the CMS_AUTH_TOKEN envvar.
auth_token = System.get_env("CMS_AUTH_TOKEN", "CRauthTOKEN123")
kind = if auth_token == "CRauthTOKEN123", do: :fake, else: :real

flow_path("agent-wrap-up")
|> FlowTester.from_json!()
|> real_or_fake_cms("https://content-repo-api-qa.prk-k8s.prd-p6t.org/", auth_token, kind)
|> FlowTester.set_global_dict("settings", %{"contentrepo_qa_token" => auth_token})
|> set_config()
flow =
init_flow
|> real_or_fake_cms("https://content-repo-api-qa.prk-k8s.prd-p6t.org/", auth_token, kind)
|> FlowTester.set_global_dict("settings", %{"contentrepo_qa_token" => auth_token})
|> set_config()
%{flow: flow}
end

setup [:setup_flow]

# 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)
Expand All @@ -158,16 +162,16 @@ defmodule AgentWrapUpTest do
end

describe "Agent wrap up:" do
test "query resolved" do
setup_flow()
test "query resolved", %{flow: flow} do
flow
|> FlowTester.start()
|> receive_message(%{
text: "Was your query successfully resolved?"
})
end

test "query resolved yes" do
setup_flow()
test "query resolved yes", %{flow: flow} do
flow
|> FlowTester.start()
|> receive_message(%{
text: "Was your query successfully resolved?"
Expand All @@ -179,8 +183,8 @@ defmodule AgentWrapUpTest do
})
end

test "query resolved no" do
setup_flow()
test "query resolved no", %{flow: flow} do
flow
|> FlowTester.start()
|> receive_message(%{
text: "Was your query successfully resolved?"
Expand All @@ -192,8 +196,8 @@ defmodule AgentWrapUpTest do
})
end

test "query unresolved call me back" do
setup_flow()
test "query unresolved call me back", %{flow: flow} do
flow
|> FlowTester.start()
|> receive_message(%{
text: "Was your query successfully resolved?"
Expand All @@ -210,8 +214,8 @@ defmodule AgentWrapUpTest do
})
end

test "call_back_number_confirmation" do
setup_flow()
test "call_back_number_confirmation", %{flow: flow} do
flow
|> FlowTester.start()
|> receive_message(%{
text: "Was your query successfully resolved?"
Expand Down
36 changes: 20 additions & 16 deletions HelpCentre/QA/tests/intro-human-agent_test.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
defmodule IntroHumanAgentTest do
use FlowTester.Case
alias FlowTester.WebhookHandler, as: WH
# alias FlowTester.FlowStep
defp flow_path(flow_name), do: Path.join([__DIR__, "..", "flows_json", flow_name <> ".json"])
alias HelpCentre.QA.Helpers

def setup_fake_cms(auth_token) do
use FakeCMS
Expand Down Expand Up @@ -78,18 +77,23 @@ defmodule IntroHumanAgentTest do
})
end

defp setup_flow() do
setup_all _ctx, do: %{init_flow: Helpers.load_flow("intro-human-agent")}

defp setup_flow(%{init_flow: init_flow}) do
# When talking to real contentrepo, get the auth token from the CMS_AUTH_TOKEN envvar.
auth_token = System.get_env("CMS_AUTH_TOKEN", "CRauthTOKEN123")
kind = if auth_token == "CRauthTOKEN123", do: :fake, else: :real

flow_path("intro-human-agent")
|> FlowTester.from_json!()
|> real_or_fake_cms("https://content-repo-api-qa.prk-k8s.prd-p6t.org/", auth_token, kind)
|> FlowTester.set_global_dict("settings", %{"contentrepo_qa_token" => auth_token})
|> set_config()
flow =
init_flow
|> real_or_fake_cms("https://content-repo-api-qa.prk-k8s.prd-p6t.org/", auth_token, kind)
|> FlowTester.set_global_dict("settings", %{"contentrepo_qa_token" => auth_token})
|> set_config()
%{flow: flow}
end

setup [:setup_flow]

# 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)
Expand All @@ -106,17 +110,17 @@ defmodule IntroHumanAgentTest do
end

describe "get pre handover message:" do
test "emergency" do
setup_flow()
test "emergency", %{flow: flow} do
flow
|> FlowTester.set_contact_properties(%{"route_to_operator_origin" => "emergency"})
|> FlowTester.start()
|> receive_message(%{
text: "We will let the helpdesk know that this is an emergency situation" <> _
})
end

test "search myhealth" do
setup_flow()
test "search myhealth", %{flow: flow} do
flow
|> FlowTester.set_contact_properties(%{"route_to_operator_origin" => "search_myhealth"})
|> FlowTester.set_contact_properties(%{
"route_to_operator_search_text" => "mock search myhealth query"
Expand All @@ -127,8 +131,8 @@ defmodule IntroHumanAgentTest do
})
end

test "tech support" do
setup_flow()
test "tech support", %{flow: flow} do
flow
|> FlowTester.set_contact_properties(%{"route_to_operator_origin" => "tech_support"})
|> FlowTester.set_contact_properties(%{
"route_to_operator_search_text" => "mock tech support query"
Expand All @@ -139,8 +143,8 @@ defmodule IntroHumanAgentTest do
})
end

test "failed attempts" do
setup_flow()
test "failed attempts", %{flow: flow} do
flow
|> FlowTester.set_contact_properties(%{"route_to_operator_origin" => "failed_attempts"})
|> FlowTester.start()
|> receive_message(%{
Expand Down
7 changes: 3 additions & 4 deletions HelpCentre/QA/tests/intro-to-helpcentre_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ defmodule IntroToHelpCentreTest do
alias FlowTester.WebhookHandler.Generic
alias HelpCentre.QA.Helpers

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.
Expand Down Expand Up @@ -317,14 +315,15 @@ defmodule IntroToHelpCentreTest do
})
end

setup_all _ctx, do: %{init_flow: Helpers.load_flow("intro-to-helpcentre")}

defp setup_flow(ctx) do
# When talking to real contentrepo, get the auth token from the CMS_AUTH_TOKEN envvar.
auth_token = System.get_env("CMS_AUTH_TOKEN", "CRauthTOKEN123")
kind = if auth_token == "CRauthTOKEN123", do: :fake, else: :real

flow =
flow_path("intro-to-helpcentre")
|> FlowTester.from_json!()
ctx.init_flow
|> real_or_fake_cms("https://content-repo-api-qa.prk-k8s.prd-p6t.org/", auth_token, kind)
|> FlowTester.set_global_dict("settings", %{"contentrepo_qa_token" => auth_token})
|> Helpers.setup_fake_turn(ctx)
Expand Down
40 changes: 22 additions & 18 deletions HelpCentre/QA/tests/scheduled-callback-confirmation_test.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
defmodule ScheduledCallbackConfirmationTest do
use FlowTester.Case
alias FlowTester.WebhookHandler, as: WH
# alias FlowTester.FlowStep
defp flow_path(flow_name), do: Path.join([__DIR__, "..", "flows_json", flow_name <> ".json"])
alias HelpCentre.QA.Helpers

def setup_fake_cms(auth_token) do
use FakeCMS
Expand Down Expand Up @@ -113,18 +112,23 @@ defmodule ScheduledCallbackConfirmationTest do
})
end

defp setup_flow() do
setup_all _ctx, do: %{init_flow: Helpers.load_flow("scheduled-callback-confirmation")}

defp setup_flow(%{init_flow: init_flow}) do
# When talking to real contentrepo, get the auth token from the CMS_AUTH_TOKEN envvar.
auth_token = System.get_env("CMS_AUTH_TOKEN", "CRauthTOKEN123")
kind = if auth_token == "CRauthTOKEN123", do: :fake, else: :real

flow_path("scheduled-callback-confirmation")
|> FlowTester.from_json!()
|> real_or_fake_cms("https://content-repo-api-qa.prk-k8s.prd-p6t.org/", auth_token, kind)
|> FlowTester.set_global_dict("settings", %{"contentrepo_qa_token" => auth_token})
|> set_config()
flow =
init_flow
|> real_or_fake_cms("https://content-repo-api-qa.prk-k8s.prd-p6t.org/", auth_token, kind)
|> FlowTester.set_global_dict("settings", %{"contentrepo_qa_token" => auth_token})
|> set_config()
%{flow: flow}
end

setup [:setup_flow]

# 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)
Expand All @@ -141,8 +145,8 @@ defmodule ScheduledCallbackConfirmationTest do
end

describe "callback confirmation scheduled" do
test "callback confirmation" do
setup_flow()
test "callback confirmation", %{flow: flow} do
flow
|> FlowTester.start()
|> receive_message(%{
text:
Expand All @@ -151,8 +155,8 @@ defmodule ScheduledCallbackConfirmationTest do
})
end

test "confirm yes" do
setup_flow()
test "confirm yes", %{flow: flow} do
flow
|> FlowTester.start()
|> receive_message(%{
text:
Expand All @@ -165,8 +169,8 @@ defmodule ScheduledCallbackConfirmationTest do
})
end

test "confirm yes and yes" do
setup_flow()
test "confirm yes and yes", %{flow: flow} do
flow
|> FlowTester.start()
|> receive_message(%{
text:
Expand All @@ -186,8 +190,8 @@ defmodule ScheduledCallbackConfirmationTest do
|> flow_finished()
end

test "confirm yes and no" do
setup_flow()
test "confirm yes and no", %{flow: flow} do
flow
|> FlowTester.start()
|> receive_message(%{
text:
Expand All @@ -206,8 +210,8 @@ defmodule ScheduledCallbackConfirmationTest do
})
end

test "confirm no" do
setup_flow()
test "confirm no", %{flow: flow} do
flow
|> FlowTester.start()
|> receive_message(%{
text:
Expand Down
Loading

0 comments on commit 5ad60ed

Please sign in to comment.