From 59e67b76a509c1f6180c0cc3bb9e06742f1ef837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Garc=C3=ADa=20Isa=C3=ADa?= Date: Tue, 5 Nov 2024 10:57:24 -0300 Subject: [PATCH] Fix SurveyResults tests Small changes, nothing too relevant. See #2350 --- lib/ask/survey_results.ex | 3 +- test/ask/survey_results_test.exs | 51 +++++++++++++++++--------------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/lib/ask/survey_results.ex b/lib/ask/survey_results.ex index e835de770..1cdb4b538 100644 --- a/lib/ask/survey_results.ex +++ b/lib/ask/survey_results.ex @@ -383,7 +383,7 @@ defmodule Ask.SurveyResults do seconds_to_process_file = Timex.diff(Timex.now(), initial_datetime, :seconds) Logger.info( - "Generation of #{file_type} file (survey_id: #{survey.id}) took #{seconds_to_process_file} seconds" + "Generation of #{file_prefix(file_type)} file (survey_id: #{survey.id}) took #{seconds_to_process_file} seconds" ) end @@ -430,6 +430,7 @@ defmodule Ask.SurveyResults do defp file_prefix(:interactions), do: "respondents_interactions" defp file_prefix(:incentives), do: "respondents_incentives" defp file_prefix(:disposition_history), do: "disposition_history" + defp file_prefix(:respondents_results), do: "respondents" defp file_prefix({:respondents_results, filter}) do if RespondentsFilter.empty?(filter) do "respondents" diff --git a/test/ask/survey_results_test.exs b/test/ask/survey_results_test.exs index b5963ff90..a51aca33d 100644 --- a/test/ask/survey_results_test.exs +++ b/test/ask/survey_results_test.exs @@ -23,7 +23,7 @@ defmodule Ask.SurveyResultsTest do test "generates empty interactions file" do survey = insert(:survey) assert {:noreply, _, _} = SurveyResults.handle_cast({:interactions, survey.id, nil}, nil) - path = SurveyResults.file_path(survey, :interactions) + path = "./priv/static/" <> SurveyResults.file_path(survey, :interactions) assert "ID,Respondent ID,Mode,Channel,Disposition,Action Type,Action Data,Timestamp\r\n" == File.read!(path) end @@ -136,7 +136,7 @@ defmodule Ask.SurveyResultsTest do end ]) - path = SurveyResults.file_path(survey, :interactions) + path = "./priv/static/" <> SurveyResults.file_path(survey, :interactions) lines = File.read!(path) |> String.split("\r\n") |> Enum.reject(fn x -> String.length(x) == 0 end) assert length(lines) == length(expected_list) assert lines == expected_list @@ -192,9 +192,9 @@ defmodule Ask.SurveyResultsTest do insert(:response, respondent: respondent_2, field_name: "Smokes", value: "No") - assert {:noreply, _, _} = SurveyResults.handle_cast({:respondent_result, survey.id, %RespondentsFilter{}}, nil) + assert {:noreply, _, _} = SurveyResults.handle_cast({:respondents_results, survey.id, %RespondentsFilter{}}, nil) - path = SurveyResults.file_path(survey, :respondent_result) + path = "./priv/static/" <> SurveyResults.file_path(survey, :respondents_results) csv = File.read!(path) [line1, line2, line3, _] = csv |> String.split("\r\n") @@ -311,9 +311,9 @@ defmodule Ask.SurveyResultsTest do insert(:response, respondent: respondent, field_name: "Exercises", value: "No") insert(:response, respondent: respondent, field_name: "Perfect Number", value: "100") - assert {:noreply, _, _} = SurveyResults.handle_cast({:respondent_result, survey.id, %RespondentsFilter{}}, nil) + assert {:noreply, _, _} = SurveyResults.handle_cast({:respondents_results, survey.id, %RespondentsFilter{}}, nil) - path = SurveyResults.file_path(survey, :respondent_result) + path = "./priv/static/" <> SurveyResults.file_path(survey, :respondents_results) csv = File.read!(path) [line1, line2, _] = csv |> String.split("\r\n") @@ -376,8 +376,8 @@ defmodule Ask.SurveyResultsTest do insert(:response, respondent: respondent_2, field_name: "Smokes", value: "No") - assert {:noreply, _, _} = SurveyResults.handle_cast({:respondent_result, survey.id, %RespondentsFilter{}}, nil) - path = SurveyResults.file_path(survey, :respondent_result) + assert {:noreply, _, _} = SurveyResults.handle_cast({:respondents_results, survey.id, %RespondentsFilter{}}, nil) + path = "./priv/static/" <> SurveyResults.file_path(survey, :respondents_results) csv = File.read!(path) [line1, line2, line3, _] = csv |> String.split("\r\n") @@ -502,8 +502,8 @@ defmodule Ask.SurveyResultsTest do insert(:response, respondent: respondent_2, field_name: "Smokes", value: "No") - assert {:noreply, _, _} = SurveyResults.handle_cast({:respondent_result, survey.id, %RespondentsFilter{}}, nil) - path = SurveyResults.file_path(survey, :respondent_result) + assert {:noreply, _, _} = SurveyResults.handle_cast({:respondents_results, survey.id, %RespondentsFilter{}}, nil) + path = "./priv/static/" <> SurveyResults.file_path(survey, :respondents_results) csv = File.read!(path) [line1, line2, line3, _] = csv |> String.split("\r\n") @@ -600,8 +600,9 @@ defmodule Ask.SurveyResultsTest do insert(:response, respondent: respondent_2, field_name: "Smokes", value: "No") - assert {:noreply, _, _} = SurveyResults.handle_cast({:respondent_result, survey.id, %RespondentsFilter{disposition: :registered}}, nil) - path = SurveyResults.file_path(survey, :respondent_result) + filter = %RespondentsFilter{disposition: :registered} + assert {:noreply, _, _} = SurveyResults.handle_cast({:respondents_results, survey.id, filter}, nil) + path = "./priv/static/" <> SurveyResults.file_path(survey, {:respondents_results, filter}) csv = File.read!(path) [line1, line2, _] = csv |> String.split("\r\n") @@ -673,8 +674,9 @@ defmodule Ask.SurveyResultsTest do insert(:response, respondent: respondent_2, field_name: "Smokes", value: "No") - assert {:noreply, _, _} = SurveyResults.handle_cast({:respondent_result, survey.id, %RespondentsFilter{since: Timex.shift(Timex.now(), hours: 2)}}, nil) - path = SurveyResults.file_path(survey, :respondent_result) + filter = %RespondentsFilter{since: Timex.shift(Timex.now(), hours: 2)} + assert {:noreply, _, _} = SurveyResults.handle_cast({:respondents_results, survey.id, filter}, nil) + path = "./priv/static/" <> SurveyResults.file_path(survey, {:respondents_results, filter}) csv = File.read!(path) [line1, line2, _] = csv |> String.split("\r\n") @@ -744,8 +746,9 @@ defmodule Ask.SurveyResultsTest do insert(:response, respondent: respondent_2, field_name: "Smokes", value: "No") - assert {:noreply, _, _} = SurveyResults.handle_cast({:respondent_result, survey.id, %RespondentsFilter{state: :completed}}, nil) - path = SurveyResults.file_path(survey, :respondent_result) + filter = %RespondentsFilter{state: :completed} + assert {:noreply, _, _} = SurveyResults.handle_cast({:respondents_results, survey.id, filter}, nil) + path = "./priv/static/" <> SurveyResults.file_path(survey, {:respondents_results, filter}) csv = File.read!(path) [line1, line2, _] = csv |> String.split("\r\n") @@ -845,8 +848,8 @@ defmodule Ask.SurveyResultsTest do insert(:response, respondent: respondent_4, field_name: "Smokes", value: "Yes") insert(:response, respondent: respondent_4, field_name: "Exercises", value: "No") - assert {:noreply, _, _} = SurveyResults.handle_cast({:respondent_result, survey.id, %RespondentsFilter{}}, nil) - path = SurveyResults.file_path(survey, :respondent_result) + assert {:noreply, _, _} = SurveyResults.handle_cast({:respondents_results, survey.id, %RespondentsFilter{}}, nil) + path = "./priv/static/" <> SurveyResults.file_path(survey, :respondents_results) csv = File.read!(path) assert !String.contains?(group_1.name, [" ", ",", "*", ":", "?", "\\", "|", "/", "<", ">"]) @@ -1001,8 +1004,8 @@ defmodule Ask.SurveyResultsTest do insert(:response, respondent: respondent_2, field_name: "Smokes", value: "No") - assert {:noreply, _, _} = SurveyResults.handle_cast({:respondent_result, survey.id, %RespondentsFilter{}}, nil) - path = SurveyResults.file_path(survey, :respondent_result) + assert {:noreply, _, _} = SurveyResults.handle_cast({:respondents_results, survey.id, %RespondentsFilter{}}, nil) + path = "./priv/static/" <> SurveyResults.file_path(survey, :respondents_results) csv = File.read!(path) [line1, line2, line3, _] = csv |> String.split("\r\n") @@ -1103,8 +1106,8 @@ defmodule Ask.SurveyResultsTest do insert(:response, respondent: respondent_1, field_name: "language", value: "es") - assert {:noreply, _, _} = SurveyResults.handle_cast({:respondent_result, survey.id, %RespondentsFilter{}}, nil) - path = SurveyResults.file_path(survey, :respondent_result) + assert {:noreply, _, _} = SurveyResults.handle_cast({:respondents_results, survey.id, %RespondentsFilter{}}, nil) + path = "./priv/static/" <> SurveyResults.file_path(survey, :respondents_results) csv = File.read!(path) [line1, line2, _] = csv |> String.split("\r\n") @@ -1174,7 +1177,7 @@ defmodule Ask.SurveyResultsTest do ) assert {:noreply, _, _} = SurveyResults.handle_cast({:disposition_history, survey.id, %RespondentsFilter{}}, nil) - path = SurveyResults.file_path(survey, :disposition_history) + path = "./priv/static/" <> SurveyResults.file_path(survey, :disposition_history) csv = File.read!(path) lines = csv |> String.split("\r\n") |> Enum.reject(fn x -> String.length(x) == 0 end) @@ -1236,7 +1239,7 @@ defmodule Ask.SurveyResultsTest do ) assert {:noreply, _, _} = SurveyResults.handle_cast({:incentives, survey.id, %RespondentsFilter{}}, nil) - path = SurveyResults.file_path(survey, :incentives) + path = "./priv/static/" <> SurveyResults.file_path(survey, :incentives) csv = File.read!(path) lines = csv |> String.split("\r\n") |> Enum.reject(fn x -> String.length(x) == 0 end)