Skip to content

Commit

Permalink
Honour results filter when generating file
Browse files Browse the repository at this point in the history
See #2350
  • Loading branch information
matiasgarciaisaia committed Dec 4, 2024
1 parent c9ba84b commit 63a3d36
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/ask/survey_results.ex
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,12 @@ defmodule Ask.SurveyResults do
}
end

defp filter_hash(filter) do
filter
|> :erlang.phash2
|> to_string
end

defp file_prefix(:interactions), do: "respondents_interactions"
defp file_prefix(:incentives), do: "respondents_incentives"
defp file_prefix(:disposition_history), do: "disposition_history"
Expand All @@ -435,7 +441,7 @@ defmodule Ask.SurveyResults do
if RespondentsFilter.empty?(filter) do
"respondents"
else
"respondents_filtered"
"respondents_filtered_#{filter_hash(filter)}"
end
end

Expand Down
26 changes: 26 additions & 0 deletions test/ask/survey_results_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,32 @@ defmodule Ask.SurveyResultsTest do
assert line_3_user_stopped == "true"
end

test "generates different filtered results csv per filter" do
survey = insert(:survey)

filter = RespondentsFilter.parse("")

assert %{files: %{respondents_results: %{created_at: nil}}} = SurveyResults.files_status(survey, [{:respondents_results, filter}])

SurveyResults.handle_cast({:respondents_results, survey.id, filter}, nil)
assert %{files: %{respondents_results: %{created_at: date}}} = SurveyResults.files_status(survey, [{:respondents_results, filter}])
assert date != nil

filter = RespondentsFilter.parse("disposition:queued")
assert %{files: %{respondents_filtered: %{created_at: nil}}} = SurveyResults.files_status(survey, [{:respondents_results, filter}])
SurveyResults.handle_cast({:respondents_results, survey.id, filter}, nil)
assert %{files: %{respondents_filtered: %{created_at: queued_date}}} = SurveyResults.files_status(survey, [{:respondents_results, filter}])
assert queued_date != nil

filter = RespondentsFilter.parse("mode:sms")
assert %{files: %{respondents_filtered: %{created_at: nil}}} = SurveyResults.files_status(survey, [{:respondents_results, filter}])
SurveyResults.handle_cast({:respondents_results, survey.id, filter}, nil)
assert %{files: %{respondents_filtered: %{created_at: mode_date}}} = SurveyResults.files_status(survey, [{:respondents_results, filter}])
assert mode_date != nil

assert %{files: %{respondents_filtered: %{created_at: ^queued_date}}} = SurveyResults.files_status(survey, [{:respondents_results, RespondentsFilter.parse("disposition:queued")}])
end

test "download results csv with non-started last call" do
project = insert(:project)
questionnaire = insert(:questionnaire, name: "test", project: project, steps: @dummy_steps)
Expand Down

0 comments on commit 63a3d36

Please sign in to comment.