Skip to content

Commit

Permalink
Fix the language selection step export (#1898)
Browse files Browse the repository at this point in the history
The language selection step isn't being exported properly since #1832.

Avoid cleaning the language selection step prompt.
Because it's a singular step, treat it differently.

Fix #1894
  • Loading branch information
Andrés Atencio authored May 31, 2021
1 parent 0acbeca commit c0fdd4f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/ask/runtime/questionnaire_action.ex
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ defmodule Ask.Runtime.CleanI18n do
forward_path = fn positions -> String.slice(path, positions..-1) end

cond do
path == ".prompt" and language_selection_step?(entity) ->
# Don't clean the language selection step
entity

# Base case
path == "" ->
clean_base_case(entity, filter_languages)
Expand All @@ -225,6 +229,9 @@ defmodule Ask.Runtime.CleanI18n do
end
end

defp language_selection_step?(%{"type" => "language-selection"} = _entity), do: true
defp language_selection_step?(_entity), do: false

defp clean_key(entity, langs, path, forward_path) do
key = String.split(path, ".") |> Enum.at(1)
path = forward_path.(String.length(key) + 1)
Expand Down
30 changes: 30 additions & 0 deletions test/lib/runtime/questionnaire_action_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ defmodule Ask.Runtime.QuestionnaireExportTest do
build_expected_export(quiz, [@ivr_audio_id])
end

test "IVR - exports a questionnaire with language selection step" do
quiz =
build_quiz(
@ivr_empty_quiz,
name: @quiz_title,
settings: @ivr_simple_quiz_settings,
steps: [
@ivr_language_selection_step
]
)

export_result = modelize_quiz(quiz) |> QuestionnaireExport.export()

assert export_result ==
build_expected_export(quiz, [@ivr_audio_id])
end



test "Mobile Web - exports a simple questionnaire" do
quiz =
build_quiz(
Expand Down Expand Up @@ -191,6 +210,17 @@ defmodule Ask.Runtime.QuestionnaireExportTest do
assert clean == %{"foo" => "bar"}
end

test "doesn't clean the language selection prompt" do
step = %{
"type" => "language-selection",
"prompt" => %{"foo" => "bar"}
}

clean = CleanI18n.clean(step, ["baz"], ".prompt")

assert clean == step
end

test "cleans choices (when the content of one of the requested keys isn't a map)" do
# A real case cut that was making it crash.
# What was making it crash: `"ivr" => []`. Because [] isn't a map.
Expand Down
15 changes: 15 additions & 0 deletions test/support/dummy_questionnaires.ex
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,21 @@ defmodule Ask.DummyQuestionnaires do
choices: []
)

@ivr_language_selection_step %{
"type" => "language-selection",
"title" => "Language selection",
"store" => "language",
"prompt" => %{
"sms" => "",
"mobileweb" => "",
"ivr" => %{
"text" => "foo",
"audio_source" => "upload",
"audio_id" => @ivr_audio_id
}
}
}

@ivr_simple_choice_step build_step(
@simple_choice_step,
prompt: @ivr_question_prompt,
Expand Down

0 comments on commit c0fdd4f

Please sign in to comment.