From ff65c402bb7ce5be77603f8481a132ce8d811c67 Mon Sep 17 00:00:00 2001 From: leandroradusky Date: Mon, 16 May 2022 15:16:38 -0300 Subject: [PATCH] Added enum type for survey state (#2079) * Added enum type for survey state --- lib/ask/channel.ex | 12 +- lib/ask/floip_pusher.ex | 4 +- lib/ask/runtime/broker.ex | 2 +- lib/ask/runtime/panel_survey.ex | 4 +- lib/ask/runtime/questionnaire_simulator.ex | 2 +- lib/ask/runtime/survey_action.ex | 8 +- lib/ask/survey.ex | 46 ++++--- lib/ask/survey_respondents_canceller.ex | 2 +- .../controllers/mobile_survey_controller.ex | 2 +- lib/ask_web/controllers/project_controller.ex | 2 +- .../controllers/respondent_controller.ex | 2 +- lib/ask_web/controllers/survey_controller.ex | 4 +- .../survey_simulation_controller.ex | 2 +- ...13180125_set_default_state_for_surveys.exs | 4 +- ...name_survey_state_default_to_not_ready.exs | 8 +- ..._exit_message_and_exit_code_to_surveys.exs | 4 +- test/ask/floip_pusher_test.exs | 38 +++--- test/ask/respondents_filter_test.exs | 4 +- test/ask/runtime/broker_test.exs | 94 ++++++------- .../runtime/channel_status_server_test.exs | 16 +-- test/ask/runtime/panel_survey_test.exs | 6 +- test/ask/runtime/retries_histogram_test.exs | 2 +- test/ask/runtime/survey_action_test.exs | 2 +- test/ask/runtime/survey_test.exs | 40 +++--- test/ask/runtime/verboice_channel_test.exs | 30 ++--- test/ask/survey_canceller_test.exs | 6 +- test/ask/survey_test.exs | 10 +- .../controllers/floip_controller_test.exs | 24 ++-- .../mobile_survey_controller_test.exs | 18 +-- .../oauth_client_controller_test.exs | 8 +- .../panel_survey_controller_test.exs | 6 +- .../controllers/project_controller_test.exs | 10 +- .../questionnaire_controller_test.exs | 14 +- .../respondent_controller_test.exs | 66 ++++----- .../respondent_group_controller_test.exs | 22 +-- .../controllers/survey_controller_test.exs | 126 +++++++++--------- .../survey_simulation_controller_test.exs | 2 +- test/support/factory.ex | 2 +- test/support/test_helpers.ex | 4 +- 39 files changed, 334 insertions(+), 324 deletions(-) diff --git a/lib/ask/channel.ex b/lib/ask/channel.ex index cfe74afc6..5261abbfd 100644 --- a/lib/ask/channel.ex +++ b/lib/ask/channel.ex @@ -49,8 +49,8 @@ defmodule Ask.Channel do end # Deletes a channel and: - # - marks related "ready" surveys as "not_ready" - # - marks related "running" surveys as "terminated" with exit code 3 + # - marks related :ready surveys as :not_ready + # - marks related :running surveys as :terminated with exit code 3 def delete(channel) do surveys = Repo.all( @@ -64,17 +64,17 @@ defmodule Ask.Channel do Enum.each(surveys, fn survey -> case survey.state do - "ready" -> + :ready -> survey - |> Ask.Survey.changeset(%{state: "not_ready"}) + |> Ask.Survey.changeset(%{state: :not_ready}) |> Repo.update!() - "running" -> + :running -> Ask.Survey.cancel_respondents(survey) survey |> Ask.Survey.changeset(%{ - state: "terminated", + state: :terminated, exit_code: 3, exit_message: "Channel '#{channel.name}' no longer exists" }) diff --git a/lib/ask/floip_pusher.ex b/lib/ask/floip_pusher.ex index 02ce72187..51eb53ff8 100644 --- a/lib/ask/floip_pusher.ex +++ b/lib/ask/floip_pusher.ex @@ -31,7 +31,7 @@ defmodule Ask.FloipPusher do from endpoint in FloipEndpoint, join: survey in Survey, on: endpoint.survey_id == survey.id, - where: survey.state == "running" or survey.state == "terminated", + where: survey.state == :running or survey.state == :terminated, where: endpoint.retries < 10, where: endpoint.state == "enabled", order_by: endpoint.survey_id @@ -78,7 +78,7 @@ defmodule Ask.FloipPusher do ) end else - if endpoint.survey.state == "terminated" do + if endpoint.survey.state == :terminated do endpoint_change = Ecto.Changeset.change(endpoint, state: "terminated") Repo.update!(endpoint_change) diff --git a/lib/ask/runtime/broker.ex b/lib/ask/runtime/broker.ex index e39b58361..778a24399 100644 --- a/lib/ask/runtime/broker.ex +++ b/lib/ask/runtime/broker.ex @@ -102,7 +102,7 @@ defmodule Ask.Runtime.Broker do all_running_surveys = Repo.all( from(s in Survey, - where: s.state == "running", + where: s.state == :running, preload: [respondent_groups: [respondent_group_channels: :channel]] ) ) diff --git a/lib/ask/runtime/panel_survey.ex b/lib/ask/runtime/panel_survey.ex index 913aa5db4..24c16906a 100644 --- a/lib/ask/runtime/panel_survey.ex +++ b/lib/ask/runtime/panel_survey.ex @@ -18,7 +18,7 @@ defmodule Ask.Runtime.PanelSurvey do name: PanelSurvey.new_wave_name(), description: survey.description, mode: survey.mode, - state: "ready", + state: :ready, started_at: Timex.now(), panel_survey_id: survey.panel_survey_id } @@ -72,7 +72,7 @@ defmodule Ask.Runtime.PanelSurvey do def create_panel_survey_from_survey(%{ state: state }) - when state != "ready", + when state != :ready, do: { :error, "Survey must be ready to launch to generate a panel survey" diff --git a/lib/ask/runtime/questionnaire_simulator.ex b/lib/ask/runtime/questionnaire_simulator.ex index d01640b27..bd60882ac 100644 --- a/lib/ask/runtime/questionnaire_simulator.ex +++ b/lib/ask/runtime/questionnaire_simulator.ex @@ -174,7 +174,7 @@ defmodule Ask.Runtime.QuestionnaireSimulator do project_id: project.id, name: questionnaire.name, mode: [[mode]], - state: "running", + state: :running, cutoff: 1, schedule: Ask.Schedule.always(), started_at: Timex.now() diff --git a/lib/ask/runtime/survey_action.ex b/lib/ask/runtime/survey_action.ex index 63d8e3e5a..af0df830a 100644 --- a/lib/ask/runtime/survey_action.ex +++ b/lib/ask/runtime/survey_action.ex @@ -31,7 +31,7 @@ defmodule Ask.Runtime.SurveyAction do |> Repo.preload([:questionnaires]) |> Repo.preload(respondent_groups: :channels) - if survey.state == "ready" do + if survey.state == :ready do channels = survey.respondent_groups |> Enum.flat_map(& &1.channels) @@ -68,7 +68,7 @@ defmodule Ask.Runtime.SurveyAction do survey = Repo.preload(survey, [:quota_buckets, :project]) case [survey.state, survey.locked] do - ["terminated", false] -> + [:terminated, false] -> # Cancelling a cancelled survey is idempotent. # We must not error, because this can happen if a user has the survey # UI open with the cancel button, and meanwhile the survey is cancelled @@ -78,7 +78,7 @@ defmodule Ask.Runtime.SurveyAction do # UI open with the cancel button, and meanwhile the survey finished {:ok, %{survey: survey}} - ["running", false] -> + [:running, false] -> changeset = Survey.changeset(survey, %{ state: "cancelling", @@ -117,7 +117,7 @@ defmodule Ask.Runtime.SurveyAction do defp perform_start(survey) do changeset = Survey.changeset(survey, %{ - state: "running", + state: :running, started_at: SystemTime.time().now, last_window_ends_at: Schedule.last_window_ends_at(survey.schedule) }) diff --git a/lib/ask/survey.ex b/lib/ask/survey.ex index 040f30950..ce35d0eee 100644 --- a/lib/ask/survey.ex +++ b/lib/ask/survey.ex @@ -48,7 +48,17 @@ defmodule Ask.Survey do # * 2nd mode sequence: SMS as primary mode, no fallback mode field :mode, JSON # not_ready, ready, pending, running, terminated, cancelling - field :state, :string, default: "not_ready" + field :state, Ecto.Enum, + values: [ + :not_ready, + :ready, + :pending, + :running, + :terminated, + :cancelling + ], + default: :not_ready + field :locked, :boolean, default: false field :exit_code, :integer field :exit_message, :string @@ -59,9 +69,9 @@ defmodule Ask.Survey do field :cutoff, :integer field :count_partial_results, :boolean, default: false field :schedule, Schedule, default: Schedule.default() - # The moment when the survey changes to %{state: "running"} and the moment when the survey + # The moment when the survey changes to %{state: :running} and the moment when the survey # becomes actually active may differ because of its schedule configuration. - # started_at: the moment when the survey change to %{state: "running"}. + # started_at: the moment when the survey change to %{state: :running}. field :started_at, :utc_datetime # first_window_started_at: the moment when the survey becomes actually active for the first time. @@ -166,7 +176,7 @@ defmodule Ask.Survey do end defp set_ended_at_in_terminated_survey(changeset) do - if get_field(changeset, :state) == "terminated" do + if get_field(changeset, :state) == :terminated do change(changeset, ended_at: SystemTime.time().now |> DateTime.truncate(:second)) else changeset @@ -207,19 +217,19 @@ defmodule Ask.Survey do state = get_field(changeset, :state) cond do - state == "not_ready" && ready -> - change(changeset, state: "ready") + state == :not_ready && ready -> + change(changeset, state: :ready) - state == "ready" && !ready -> - change(changeset, state: "not_ready") + state == :ready && !ready -> + change(changeset, state: :not_ready) true -> changeset end end - def editable?(%{state: "running"}), do: false - def editable?(%{state: "terminated"}), do: false + def editable?(%{state: :running}), do: false + def editable?(%{state: :terminated}), do: false def editable?(_), do: true def validate_from_less_than_to(changeset) do @@ -426,7 +436,7 @@ defmodule Ask.Survey do do: ConfigHelper.get_config(Ask.Runtime.Broker, name, &String.to_integer/1) def launched?(survey) do - survey.state in ["running", "terminated"] + survey.state in [:running, :terminated] end def adjust_timezone(date_time, %Survey{} = survey) do @@ -442,20 +452,20 @@ defmodule Ask.Survey do end def completed?(survey) do - survey.state == "terminated" && survey.exit_code == 0 + survey.state == :terminated && survey.exit_code == 0 end def cancelled?(survey) do - survey.state == "terminated" && survey.exit_code == 1 + survey.state == :terminated && survey.exit_code == 1 end def has_floip_package?(survey) do - survey.state == "running" || survey.state == "terminated" + survey.state == :running || survey.state == :terminated end def cancel_respondents(survey) do from(r in Respondent, where: r.state == :active and r.survey_id == ^survey.id) - |> Repo.update_all(set: [state: "cancelled", session: nil, timeout_at: nil]) + |> Repo.update_all(set: [state: :cancelled, session: nil, timeout_at: nil]) end def with_links(%Survey{} = survey, level \\ "owner") do @@ -490,7 +500,7 @@ defmodule Ask.Survey do def running_channels() do query = from s in Survey, - where: s.state == "running", + where: s.state == :running, join: group in RespondentGroup, on: s.id == group.survey_id, join: rgc in RespondentGroupChannel, @@ -742,7 +752,7 @@ defmodule Ask.Survey do end) end - def terminated?(survey), do: survey.state == "terminated" + def terminated?(survey), do: survey.state == :terminated def succeeded?(survey), do: terminated?(survey) and survey.exit_code == 0 @@ -805,7 +815,7 @@ defmodule Ask.Survey do end # Running surveys aren't deletable - def deletable?(%{state: "running"} = _survey), do: false + def deletable?(%{state: :running} = _survey), do: false # Only wave of a panel survey isn't deletable (because a panel survey cannot be empty) def deletable?(survey), do: not only_wave_of_panel_survey?(survey) diff --git a/lib/ask/survey_respondents_canceller.ex b/lib/ask/survey_respondents_canceller.ex index 55d9cab15..5473df56a 100644 --- a/lib/ask/survey_respondents_canceller.ex +++ b/lib/ask/survey_respondents_canceller.ex @@ -18,7 +18,7 @@ defmodule Ask.RespondentsCancellerProducer do query = from( s in Survey, - where: s.state == "cancelling", + where: s.state == :cancelling, select: s.id ) diff --git a/lib/ask_web/controllers/mobile_survey_controller.ex b/lib/ask_web/controllers/mobile_survey_controller.ex index 4f9c52828..b611c658f 100644 --- a/lib/ask_web/controllers/mobile_survey_controller.ex +++ b/lib/ask_web/controllers/mobile_survey_controller.ex @@ -103,7 +103,7 @@ defmodule AskWeb.MobileSurveyController do survey = Repo.preload(respondent, :survey).survey cond do - survey.state == "terminated" -> + survey.state == :terminated -> questionnaires = Repo.preload(survey, :questionnaires).questionnaires questionnaire = Enum.random(questionnaires) diff --git a/lib/ask_web/controllers/project_controller.ex b/lib/ask_web/controllers/project_controller.ex index ad2bd257c..b9f1d6d5e 100644 --- a/lib/ask_web/controllers/project_controller.ex +++ b/lib/ask_web/controllers/project_controller.ex @@ -51,7 +51,7 @@ defmodule AskWeb.ProjectController do from p in Project, join: s in Survey, select: {p.id, count(s.id)}, - where: s.project_id == p.id and s.state == "running", + where: s.project_id == p.id and s.state == :running, group_by: p.id ) |> Enum.into(%{}) diff --git a/lib/ask_web/controllers/respondent_controller.ex b/lib/ask_web/controllers/respondent_controller.ex index 06c2287eb..5bd24bc90 100644 --- a/lib/ask_web/controllers/respondent_controller.ex +++ b/lib/ask_web/controllers/respondent_controller.ex @@ -470,7 +470,7 @@ defmodule AskWeb.RespondentController do percents_by_date = [{started_at |> DateTime.to_date(), 0}] ++ percents_by_date percents_by_date = - if state == "running" do + if state == :running do percents_by_date ++ [{DateTime.utc_now() |> DateTime.to_date(), 0}] else percents_by_date diff --git a/lib/ask_web/controllers/survey_controller.ex b/lib/ask_web/controllers/survey_controller.ex index 4fe0a2a59..106baf655 100644 --- a/lib/ask_web/controllers/survey_controller.ex +++ b/lib/ask_web/controllers/survey_controller.ex @@ -31,7 +31,7 @@ defmodule AskWeb.SurveyController do if params["state"] do if params["state"] == "completed" do # Same as Survey.succeeded?(s) - dynamic([s], s.state == "terminated" and s.exit_code == 0 and ^dynamic) + dynamic([s], s.state == :terminated and s.exit_code == 0 and ^dynamic) else dynamic([s], s.state == ^params["state"] and ^dynamic) end @@ -432,7 +432,7 @@ defmodule AskWeb.SurveyController do |> Survey.with_links(user_level(project_id, current_user(conn).id)) case survey.state do - "running" -> + :running -> [survey_changeset, activity_log] = case locked do true -> diff --git a/lib/ask_web/controllers/survey_simulation_controller.ex b/lib/ask_web/controllers/survey_simulation_controller.ex index d773976c4..7816f4569 100644 --- a/lib/ask_web/controllers/survey_simulation_controller.ex +++ b/lib/ask_web/controllers/survey_simulation_controller.ex @@ -32,7 +32,7 @@ defmodule AskWeb.SurveySimulationController do project_id: project.id, name: questionnaire.name, mode: [[mode]], - state: "ready", + state: :ready, cutoff: 1, schedule: Ask.Schedule.always() } diff --git a/priv/repo/migrations/20160913180125_set_default_state_for_surveys.exs b/priv/repo/migrations/20160913180125_set_default_state_for_surveys.exs index 9fc32a016..5f0340bd3 100644 --- a/priv/repo/migrations/20160913180125_set_default_state_for_surveys.exs +++ b/priv/repo/migrations/20160913180125_set_default_state_for_surveys.exs @@ -4,13 +4,13 @@ defmodule Ask.Repo.Migrations.SetDefaultStateForSurveys do def up do alter table(:surveys) do - modify :state, :string, default: "pending" + modify :state, :string, default: :pending end flush() from(s in Ask.Survey, where: is_nil(s.state)) - |> Ask.Repo.update_all(set: [state: "pending"]) + |> Ask.Repo.update_all(set: [state: :pending]) end def down do diff --git a/priv/repo/migrations/20160915191129_rename_survey_state_default_to_not_ready.exs b/priv/repo/migrations/20160915191129_rename_survey_state_default_to_not_ready.exs index f1688865f..4a7819430 100644 --- a/priv/repo/migrations/20160915191129_rename_survey_state_default_to_not_ready.exs +++ b/priv/repo/migrations/20160915191129_rename_survey_state_default_to_not_ready.exs @@ -3,12 +3,12 @@ defmodule Ask.Repo.Migrations.RenameSurveyStateDefaultToNotReady do import Ecto.Query def up do - from(s in Ask.Survey, where: s.state == "pending") - |> Ask.Repo.update_all(set: [state: "not_ready"]) + from(s in Ask.Survey, where: s.state == :pending) + |> Ask.Repo.update_all(set: [state: :not_ready]) end def down do - from(s in Ask.Survey, where: s.state == "not_ready") - |> Ask.Repo.update_all(set: [state: "pending"]) + from(s in Ask.Survey, where: s.state == :not_ready) + |> Ask.Repo.update_all(set: [state: :pending]) end end diff --git a/priv/repo/migrations/20170523174141_add_exit_message_and_exit_code_to_surveys.exs b/priv/repo/migrations/20170523174141_add_exit_message_and_exit_code_to_surveys.exs index aac952572..20c393125 100644 --- a/priv/repo/migrations/20170523174141_add_exit_message_and_exit_code_to_surveys.exs +++ b/priv/repo/migrations/20170523174141_add_exit_message_and_exit_code_to_surveys.exs @@ -12,12 +12,12 @@ defmodule Ask.Repo.Migrations.AddExitMessageAndExitCodeToSurveys do from(s in "surveys", where: s.state == "completed") |> Ask.Repo.update_all( - set: [state: "terminated", exit_code: 0, exit_message: "Successfully completed"] + set: [state: :terminated, exit_code: 0, exit_message: "Successfully completed"] ) from(s in "surveys", where: s.state == "cancelled") |> Ask.Repo.update_all( - set: [state: "terminated", exit_code: 1, exit_message: "Cancelled by user"] + set: [state: :terminated, exit_code: 1, exit_message: "Cancelled by user"] ) end diff --git a/test/ask/floip_pusher_test.exs b/test/ask/floip_pusher_test.exs index 2efaedfda..ae953ba13 100644 --- a/test/ask/floip_pusher_test.exs +++ b/test/ask/floip_pusher_test.exs @@ -70,8 +70,8 @@ defmodule Ask.FloipPusherTest do test "writes last successfully pushed response for each endpoint", %{server: server} do # 2 running surveys - survey1 = insert(:survey, state: "running") - survey2 = insert(:survey, state: "running") + survey1 = insert(:survey, state: :running) + survey2 = insert(:survey, state: :running) # 2 endpoints per survey endpoint_1_survey_1 = insert_endpoint(survey1) @@ -99,8 +99,8 @@ defmodule Ask.FloipPusherTest do test "pushes to all endpoints that have new responses", %{server: server} do # 2 running surveys - survey1 = insert(:survey, state: "running") - survey2 = insert(:survey, state: "running") + survey1 = insert(:survey, state: :running) + survey2 = insert(:survey, state: :running) # 2 endpoints per survey insert_endpoint(survey1, uri: "http://localhost:#{server.port}/1.1") @@ -126,8 +126,8 @@ defmodule Ask.FloipPusherTest do test "does not overwrite last_pushed_response_id if push fails", %{server: server} do # 2 running surveys - survey1 = insert(:survey, state: "running") - survey2 = insert(:survey, state: "running") + survey1 = insert(:survey, state: :running) + survey2 = insert(:survey, state: :running) # 2 endpoints per survey endpoint_1_survey_1 = insert_endpoint(survey1, uri: "http://localhost:#{server.port}/1.1") @@ -159,8 +159,8 @@ defmodule Ask.FloipPusherTest do test "does not push to endpoints with no new responses", %{server: server} do # 2 running surveys - survey1 = insert(:survey, state: "running") - survey2 = insert(:survey, state: "running") + survey1 = insert(:survey, state: :running) + survey2 = insert(:survey, state: :running) # 2 responses per survey insert_response(survey1) @@ -191,7 +191,7 @@ defmodule Ask.FloipPusherTest do test "does not send more than 1000 responses per run per endpoint", %{server: server} do # 1 running survey - survey = insert(:survey, state: "running") + survey = insert(:survey, state: :running) # Add 1 endpoint to the survey endpoint = insert_endpoint(survey, uri: "http://localhost:#{server.port}/1.1") @@ -218,7 +218,7 @@ defmodule Ask.FloipPusherTest do test "increments endpoint retry counter if push fails", %{server: server} do # 1 running survey - survey = insert(:survey, state: "running") + survey = insert(:survey, state: :running) # Add 1 endpoint to the survey endpoint = insert_endpoint(survey, uri: "http://localhost:#{server.port}/1.1") @@ -239,7 +239,7 @@ defmodule Ask.FloipPusherTest do test "resets endpoint retry counter if push succeeds", %{server: server} do # Create 1 survey - survey = insert(:survey, state: "running") + survey = insert(:survey, state: :running) # Add 1 endpoint to the survey, with retry counter == 8 endpoint = insert_endpoint(survey, uri: "http://localhost:#{server.port}/1.1", retries: 8) @@ -262,8 +262,8 @@ defmodule Ask.FloipPusherTest do server: server } do # 2 running surveys - survey1 = insert(:survey, state: "running") - survey2 = insert(:survey, state: "running") + survey1 = insert(:survey, state: :running) + survey2 = insert(:survey, state: :running) # 2 responses per survey insert_response(survey1) @@ -294,7 +294,7 @@ defmodule Ask.FloipPusherTest do test "ignores disabled endpoints", %{server: server} do # 1 survey - survey1 = insert(:survey, state: "running") + survey1 = insert(:survey, state: :running) # 1 endpoint in "disabled" state insert_endpoint(survey1, @@ -312,7 +312,7 @@ defmodule Ask.FloipPusherTest do test "marks endpoint as disabled if it reaches 10 retries", %{server: server} do # 1 survey - survey1 = insert(:survey, state: "running") + survey1 = insert(:survey, state: :running) # 1 endpoint with 9 retries endpoint = @@ -356,7 +356,7 @@ defmodule Ask.FloipPusherTest do server: server } do # 1 survey terminated - survey1 = insert(:survey, state: "terminated") + survey1 = insert(:survey, state: :terminated) # 1 response last_response = insert_response(survey1) @@ -379,7 +379,7 @@ defmodule Ask.FloipPusherTest do test "does not mark endpoint as terminated if survey terminated but there still are pending messages to push", %{server: server} do # 1 survey terminated - survey1 = insert(:survey, state: "terminated") + survey1 = insert(:survey, state: :terminated) # 2000 responses respondent = insert(:respondent, survey: survey1) @@ -410,7 +410,7 @@ defmodule Ask.FloipPusherTest do # for terminated surveys to which we already pushed all responses. test "ignores terminated endpoints", %{server: server} do # 1 survey terminated - survey1 = insert(:survey, state: "terminated") + survey1 = insert(:survey, state: :terminated) # 1 response insert_response(survey1) @@ -425,7 +425,7 @@ defmodule Ask.FloipPusherTest do end test "sets auth token", %{server: server} do - survey1 = insert(:survey, state: "running") + survey1 = insert(:survey, state: :running) insert_response(survey1) insert_endpoint(survey1, uri: "http://localhost:#{server.port}/1.1", auth_token: "IM_A_TOKEN") diff --git a/test/ask/respondents_filter_test.exs b/test/ask/respondents_filter_test.exs index 4146a3a45..cbb2f49dd 100644 --- a/test/ask/respondents_filter_test.exs +++ b/test/ask/respondents_filter_test.exs @@ -425,13 +425,13 @@ defmodule Ask.RespondentsFilterTest do for _ <- 1..1, do: - insert(:respondent, disposition: "queued", state: "pending", mode: ["sms", "sms", "ivr"]) + insert(:respondent, disposition: "queued", state: :pending, mode: ["sms", "sms", "ivr"]) for _ <- 1..2, do: insert(:respondent, disposition: "queued", - state: "pending", + state: :pending, updated_at: two_days_ago, mode: ["ivr", "mobileweb", "mobileweb"] ) diff --git a/test/ask/runtime/broker_test.exs b/test/ask/runtime/broker_test.exs index c0d6a3768..7a27b8b58 100644 --- a/test/ask/runtime/broker_test.exs +++ b/test/ask/runtime/broker_test.exs @@ -83,7 +83,7 @@ defmodule Ask.Runtime.BrokerTest do assert respondent.state == :failed survey = Repo.get(Survey, survey.id) - assert survey.state == "terminated" + assert survey.state == :terminated end @tag :time_mock @@ -162,7 +162,7 @@ defmodule Ask.Runtime.BrokerTest do assert respondent.stats.attempts["sms"] == 2 refute respondent.timeout_at survey = Repo.get(Survey, survey.id) - assert survey.state == "terminated" + assert survey.state == :terminated end test "mobileweb mode" do @@ -191,7 +191,7 @@ defmodule Ask.Runtime.BrokerTest do }" survey = Repo.get(Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get!(Respondent, respondent.id) assert respondent.stats.attempts["mobileweb"] == 1 @@ -235,7 +235,7 @@ defmodule Ask.Runtime.BrokerTest do refute respondent.timeout_at survey = Repo.get(Survey, survey.id) - assert survey.state == "terminated" + assert survey.state == :terminated :ok = broker |> GenServer.stop() end @@ -349,7 +349,7 @@ defmodule Ask.Runtime.BrokerTest do survey = insert(:survey, %{ schedule: Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [sequence_mode] }) @@ -464,7 +464,7 @@ defmodule Ask.Runtime.BrokerTest do survey = insert(:survey, %{ schedule: Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [["ivr", "sms"]] }) @@ -599,7 +599,7 @@ defmodule Ask.Runtime.BrokerTest do survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running assert_respondents_by_state(survey, 6, 15) @@ -682,7 +682,7 @@ defmodule Ask.Runtime.BrokerTest do # In the beginning it shouldn't be completed survey = Ask.Survey |> Repo.get(survey.id) - assert survey.state == "running" + assert survey.state == :running # Not yet completed: missing fourth bucket qb1 |> QuotaBucket.changeset(%{count: 1}) |> Repo.update!() @@ -692,7 +692,7 @@ defmodule Ask.Runtime.BrokerTest do Broker.handle_info(:poll, nil) survey = Ask.Survey |> Repo.get(survey.id) - assert survey.state == "running" + assert survey.state == :running # Now it should be completed qb4 |> QuotaBucket.changeset(%{count: 4}) |> Repo.update!() @@ -769,7 +769,7 @@ defmodule Ask.Runtime.BrokerTest do Broker.handle_info(:poll, nil) survey = Ask.Survey |> Repo.get(survey.id) - assert survey.state == "running" + assert survey.state == :running qb1 |> QuotaBucket.changeset(%{count: 1}) |> Repo.update!() qb2 |> QuotaBucket.changeset(%{count: 2}) |> Repo.update!() @@ -805,7 +805,7 @@ defmodule Ask.Runtime.BrokerTest do end test "when there are no respondents" do - survey = insert(:survey, %{schedule: Schedule.always(), state: "running"}) + survey = insert(:survey, %{schedule: Schedule.always(), state: :running}) Broker.handle_info(:poll, nil) survey = Repo.get(Ask.Survey, survey.id) @@ -852,7 +852,7 @@ defmodule Ask.Runtime.BrokerTest do # Start date is set for tomorrow, so the survey isn't poll yet. start_date = Timex.shift(now, days: 1) |> Timex.to_date() schedule = %{Schedule.always() | start_date: start_date} - survey = insert(:survey, %{schedule: schedule, state: "running"}) + survey = insert(:survey, %{schedule: schedule, state: :running}) Broker.handle_info(:poll, nil) @@ -891,13 +891,13 @@ defmodule Ask.Runtime.BrokerTest do survey1 = insert(:survey, %{ schedule: Map.merge(Schedule.always(), %{day_of_week: schedule1}), - state: "running" + state: :running }) survey2 = insert(:survey, %{ schedule: Map.merge(Schedule.always(), %{day_of_week: schedule2}), - state: "running" + state: :running }) Broker.handle_info(:poll, nil) @@ -906,7 +906,7 @@ defmodule Ask.Runtime.BrokerTest do survey2 = Repo.get(Ask.Survey, survey2.id) assert Ask.Survey.completed?(survey1) - assert survey2.state == "running" + assert survey2.state == :running # Only polled surveys have first_window_started_at assert DateTime.compare(survey1.first_window_started_at, now) == :eq @@ -922,27 +922,27 @@ defmodule Ask.Runtime.BrokerTest do survey = insert(:survey, %{ schedule: schedule, - state: "running", + state: :running, last_window_ends_at: Timex.shift(now, days: -1) }) stop_surveys_result = Broker.poll_active_surveys(now) survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "cancelling" + assert survey.state == :cancelling Enum.each(stop_surveys_result, fn {:ok, %{processes: processes}} -> wait_all_cancellations_from_pids(processes) end) survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "terminated" + assert survey.state == :terminated end test "doesn't stop the survey if it isn't expired" do {:ok, now, _} = DateTime.from_iso8601("2021-02-11T12:00:00Z") schedule = %{Schedule.always() | end_date: ~D[2021-02-19]} - survey = insert(:survey, %{schedule: schedule, state: "running"}) + survey = insert(:survey, %{schedule: schedule, state: :running}) Broker.handle_info(:poll, nil, now) @@ -951,12 +951,12 @@ defmodule Ask.Runtime.BrokerTest do end test "only polls surveys if today is not blocked" do - survey1 = insert(:survey, %{schedule: Schedule.always(), state: "running"}) + survey1 = insert(:survey, %{schedule: Schedule.always(), state: :running}) survey2 = insert(:survey, %{ schedule: Map.merge(Schedule.always(), %{blocked_days: [Date.utc_today()]}), - state: "running" + state: :running }) Broker.handle_info(:poll, nil) @@ -964,7 +964,7 @@ defmodule Ask.Runtime.BrokerTest do survey1 = Repo.get(Ask.Survey, survey1.id) survey2 = Repo.get(Ask.Survey, survey2.id) assert Ask.Survey.completed?(survey1) - assert survey2.state == "running" + assert survey2.state == :running end test "doesn't poll surveys with a start time schedule greater than the current hour" do @@ -978,13 +978,13 @@ defmodule Ask.Runtime.BrokerTest do survey = insert(:survey, %{ schedule: Map.merge(Schedule.always(), %{start_time: start_time, end_time: end_time}), - state: "running" + state: :running }) Broker.handle_info(:poll, nil, ten_oclock) survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running end test "doesn't poll surveys with an end time schedule smaller than the current hour" do @@ -998,13 +998,13 @@ defmodule Ask.Runtime.BrokerTest do survey = insert(:survey, %{ schedule: Map.merge(Schedule.always(), %{start_time: start_time, end_time: end_time}), - state: "running" + state: :running }) Broker.handle_info(:poll, nil, twelve_oclock) survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running end test "doesn't poll surveys with an end time schedule smaller than the current hour considering timezone" do @@ -1016,13 +1016,13 @@ defmodule Ask.Runtime.BrokerTest do end_time: ~T[12:00:00], timezone: "Asia/Shanghai" }), - state: "running" + state: :running }) Broker.handle_info(:poll, nil, Timex.parse!("2016-01-01T11:00:00Z", "{ISO:Extended}")) survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running end test "does poll surveys with an end time schedule higher than the current hour considering timezone" do @@ -1034,7 +1034,7 @@ defmodule Ask.Runtime.BrokerTest do end_time: ~T[12:00:00], timezone: "America/Buenos_Aires" }), - state: "running" + state: :running }) Broker.handle_info(:poll, nil, Timex.parse!("2016-01-01T14:00:00Z", "{ISO:Extended}")) @@ -1052,7 +1052,7 @@ defmodule Ask.Runtime.BrokerTest do end_time: ~T[23:59:00], timezone: "America/Mexico_City" }, - state: "running" + state: :running } survey = insert(:survey, attrs) @@ -1076,7 +1076,7 @@ defmodule Ask.Runtime.BrokerTest do end_time: ~T[23:59:00], timezone: "America/Mexico_City" }, - state: "running" + state: :running } survey = insert(:survey, attrs) @@ -1088,7 +1088,7 @@ defmodule Ask.Runtime.BrokerTest do # Survey shouldn't have started yet survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running end test "continue polling respondents when one of the quotas was exceeded " do @@ -1111,7 +1111,7 @@ defmodule Ask.Runtime.BrokerTest do survey = insert(:survey, %{ schedule: Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [["sms"]] }) @@ -1173,7 +1173,7 @@ defmodule Ask.Runtime.BrokerTest do ] survey = Repo.get(Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active assert respondent.disposition == :queued @@ -1218,7 +1218,7 @@ defmodule Ask.Runtime.BrokerTest do ] survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active assert respondent.disposition == :queued @@ -1268,7 +1268,7 @@ defmodule Ask.Runtime.BrokerTest do ] survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active assert respondent.disposition == :queued @@ -1383,7 +1383,7 @@ defmodule Ask.Runtime.BrokerTest do Broker.handle_info(:poll, nil) survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running updated_respondent = Repo.get(Respondent, respondent.id) assert updated_respondent.disposition == :queued end @@ -1445,7 +1445,7 @@ defmodule Ask.Runtime.BrokerTest do Broker.handle_info(:poll, nil) survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running updated_respondent = Repo.get(Respondent, respondent.id) assert updated_respondent.state == :active @@ -1476,17 +1476,17 @@ defmodule Ask.Runtime.BrokerTest do Broker.handle_info(:poll, nil) survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "not_ready" + assert survey.state == :not_ready end test "does nothing when there are no pending respondents" do - survey = insert(:survey, %{schedule: Schedule.always(), state: "running"}) + survey = insert(:survey, %{schedule: Schedule.always(), state: :running}) insert(:respondent, survey: survey, state: :active) Broker.handle_info(:poll, nil) survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running end test "should not keep setting pending to actives when all the quotas are completed" do @@ -1545,7 +1545,7 @@ defmodule Ask.Runtime.BrokerTest do Broker.handle_info(:poll, nil) survey = Ask.Survey |> Repo.get(survey.id) - assert survey.state == "running" + assert survey.state == :running qb1 |> QuotaBucket.changeset(%{count: 1}) |> Repo.update!() qb2 |> QuotaBucket.changeset(%{count: 2}) |> Repo.update!() @@ -1580,7 +1580,7 @@ defmodule Ask.Runtime.BrokerTest do Broker.handle_info(:poll, nil) assert_respondents_by_state(survey, 0, 20) - assert survey.state == "running" + assert survey.state == :running end test "always keeps batch_size number of respondents running" do @@ -1591,7 +1591,7 @@ defmodule Ask.Runtime.BrokerTest do survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running assert_respondents_by_state(survey, 10, 11) @@ -1706,7 +1706,7 @@ defmodule Ask.Runtime.BrokerTest do survey = insert(:survey, %{ schedule: Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz1, quiz2], mode: [["sms"], ["ivr"]], comparisons: [ @@ -1755,7 +1755,7 @@ defmodule Ask.Runtime.BrokerTest do survey = insert(:survey, %{ schedule: Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz1, quiz2], mode: [["sms"], ["ivr"]], comparisons: [ @@ -1813,7 +1813,7 @@ defmodule Ask.Runtime.BrokerTest do insert( :survey, schedule: Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [[mode]], count_partial_results: true, diff --git a/test/ask/runtime/channel_status_server_test.exs b/test/ask/runtime/channel_status_server_test.exs index 4b0c04118..790009462 100644 --- a/test/ask/runtime/channel_status_server_test.exs +++ b/test/ask/runtime/channel_status_server_test.exs @@ -18,10 +18,10 @@ defmodule Ask.Runtime.ChannelStatusServerTest do user = insert(:user) surveys = [ - insert(:survey, state: "pending"), - insert(:survey, state: "running"), - insert(:survey, state: "running"), - insert(:survey, state: "running") + insert(:survey, state: :pending), + insert(:survey, state: :running), + insert(:survey, state: :running), + insert(:survey, state: :running) ] channels = [ @@ -62,7 +62,7 @@ defmodule Ask.Runtime.ChannelStatusServerTest do {:ok, pid} = ChannelStatusServer.start_link() Process.register(self(), :mail_target) user = insert(:user) - survey = insert(:survey, state: "running") + survey = insert(:survey, state: :running) channel = TestChannel.create_channel(user, "test", TestChannel.settings(TestChannel.new(), 1, :down)) @@ -79,7 +79,7 @@ defmodule Ask.Runtime.ChannelStatusServerTest do {:ok, pid} = ChannelStatusServer.start_link() Process.register(self(), :mail_target) user = insert(:user) - survey = insert(:survey, state: "running") + survey = insert(:survey, state: :running) channel = TestChannel.create_channel(user, "test", TestChannel.settings(TestChannel.new(), 1, :error)) @@ -96,7 +96,7 @@ defmodule Ask.Runtime.ChannelStatusServerTest do {:ok, pid} = ChannelStatusServer.start_link() Process.register(self(), :mail_target) user = insert(:user) - survey = insert(:survey, state: "running") + survey = insert(:survey, state: :running) channel = TestChannel.create_channel(user, "test", TestChannel.settings(TestChannel.new(), 1, :down)) @@ -114,7 +114,7 @@ defmodule Ask.Runtime.ChannelStatusServerTest do {:ok, pid} = ChannelStatusServer.start_link() Process.register(self(), :mail_target) user = insert(:user) - survey = insert(:survey, state: "running") + survey = insert(:survey, state: :running) channel = TestChannel.create_channel(user, "test", TestChannel.settings(TestChannel.new(), 1, :error)) diff --git a/test/ask/runtime/panel_survey_test.exs b/test/ask/runtime/panel_survey_test.exs index c3f8616d4..137fd870a 100644 --- a/test/ask/runtime/panel_survey_test.exs +++ b/test/ask/runtime/panel_survey_test.exs @@ -14,7 +14,7 @@ defmodule Ask.Runtime.PanelSurveyTest do assert result == :ok new_wave = Map.get(data, :new_wave) assert new_wave - assert new_wave.state == "ready" + assert new_wave.state == :ready assert new_wave.panel_survey_id == panel_survey.id end @@ -208,7 +208,7 @@ defmodule Ask.Runtime.PanelSurveyTest do test "rejects creating a panel survey when the survey isn't ready to launch" do survey = panel_survey_generator_survey() - |> Survey.changeset(%{state: "not_ready"}) + |> Survey.changeset(%{state: :not_ready}) |> Repo.update!() {result, error} = PanelSurvey.create_panel_survey_from_survey(survey) @@ -240,7 +240,7 @@ defmodule Ask.Runtime.PanelSurveyTest do project = insert(:project) survey = - insert(:survey, project: project, generates_panel_survey: true, state: "ready", name: nil) + insert(:survey, project: project, generates_panel_survey: true, state: :ready, name: nil) {result, panel_survey} = PanelSurvey.create_panel_survey_from_survey(survey) diff --git a/test/ask/runtime/retries_histogram_test.exs b/test/ask/runtime/retries_histogram_test.exs index 24c88f80f..ff03f5b62 100644 --- a/test/ask/runtime/retries_histogram_test.exs +++ b/test/ask/runtime/retries_histogram_test.exs @@ -409,7 +409,7 @@ defmodule Ask.Runtime.RetriesHistogramTest do survey = insert(:survey, %{ schedule: Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [sequence_mode], fallback_delay: "3h" diff --git a/test/ask/runtime/survey_action_test.exs b/test/ask/runtime/survey_action_test.exs index 729fb1b9f..dc4795e6c 100644 --- a/test/ask/runtime/survey_action_test.exs +++ b/test/ask/runtime/survey_action_test.exs @@ -79,7 +79,7 @@ defmodule Ask.Runtime.SurveyActionTest do defp ready_survey() do project = insert(:project) - insert(:survey, state: "ready", project: project) + insert(:survey, state: :ready, project: project) end defp ready_survey_in_folder() do diff --git a/test/ask/runtime/survey_test.exs b/test/ask/runtime/survey_test.exs index 82bf5906a..f77f0cab9 100644 --- a/test/ask/runtime/survey_test.exs +++ b/test/ask/runtime/survey_test.exs @@ -53,7 +53,7 @@ defmodule Ask.Runtime.SurveyTest do ] survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -236,7 +236,7 @@ defmodule Ask.Runtime.SurveyTest do Broker.poll() survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -408,7 +408,7 @@ defmodule Ask.Runtime.SurveyTest do }" survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -531,7 +531,7 @@ defmodule Ask.Runtime.SurveyTest do ] survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -713,7 +713,7 @@ defmodule Ask.Runtime.SurveyTest do ] survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -882,7 +882,7 @@ defmodule Ask.Runtime.SurveyTest do Broker.poll() survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -1157,7 +1157,7 @@ defmodule Ask.Runtime.SurveyTest do Survey.delivery_confirm(respondent, "Do you smoke?") survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -1319,7 +1319,7 @@ defmodule Ask.Runtime.SurveyTest do Broker.poll() survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -1822,7 +1822,7 @@ defmodule Ask.Runtime.SurveyTest do survey = insert(:survey, %{ schedule: Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [["sms"]], count_partial_results: true @@ -1941,7 +1941,7 @@ defmodule Ask.Runtime.SurveyTest do survey = insert(:survey, %{ schedule: Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [["sms"]], count_partial_results: true @@ -2305,7 +2305,7 @@ defmodule Ask.Runtime.SurveyTest do ] survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -2316,7 +2316,7 @@ defmodule Ask.Runtime.SurveyTest do assert respondent.state == :active assert respondent.disposition == :"interim partial" survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running histories = RespondentDispositionHistory |> Repo.all() assert length(histories) == 2 @@ -2582,14 +2582,14 @@ defmodule Ask.Runtime.SurveyTest do assert respondent.state == :active assert respondent.disposition == :"interim partial" survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running reply = Survey.sync_step(respondent, Flow.Message.reply("Yes")) assert {:reply, ReplyHelper.simple("Is this the last question?"), _} = reply respondent = Repo.get(Respondent, respondent.id) |> Repo.preload(:responses) - assert survey.state == "running" + assert survey.state == :running assert respondent.state == :active assert respondent.disposition == :"interim partial" assert hd(respondent.responses).value == "Yes" @@ -3060,7 +3060,7 @@ defmodule Ask.Runtime.SurveyTest do # If there's a problem with one respondent, continue the survey with others # and mark this one as failed survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :failed @@ -3104,7 +3104,7 @@ defmodule Ask.Runtime.SurveyTest do Broker.poll() survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -3155,7 +3155,7 @@ defmodule Ask.Runtime.SurveyTest do Broker.poll() survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -3212,7 +3212,7 @@ defmodule Ask.Runtime.SurveyTest do survey = insert(:survey, %{ schedule: Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [["ivr", "sms"]] }) @@ -3263,7 +3263,7 @@ defmodule Ask.Runtime.SurveyTest do survey = insert(:survey, %{ schedule: Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [["sms", "mobileweb"]] }) @@ -3320,7 +3320,7 @@ defmodule Ask.Runtime.SurveyTest do }" survey = Repo.get(Ask.Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active diff --git a/test/ask/runtime/verboice_channel_test.exs b/test/ask/runtime/verboice_channel_test.exs index 5b99ce39c..a66c23081 100644 --- a/test/ask/runtime/verboice_channel_test.exs +++ b/test/ask/runtime/verboice_channel_test.exs @@ -396,7 +396,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do survey = insert( :survey, - Map.merge(@survey, %{state: "running", questionnaires: [quiz], mode: [["ivr"]]}) + Map.merge(@survey, %{state: :running, questionnaires: [quiz], mode: [["ivr"]]}) ) group = @@ -416,7 +416,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do Broker.poll() survey = Repo.get(Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -470,7 +470,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do survey = insert( :survey, - Map.merge(@survey, %{state: "running", questionnaires: [quiz], mode: [["ivr"]]}) + Map.merge(@survey, %{state: :running, questionnaires: [quiz], mode: [["ivr"]]}) ) group = @@ -490,7 +490,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do Broker.poll() survey = Repo.get(Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -521,7 +521,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do survey = insert( :survey, - Map.merge(@survey, %{state: "running", questionnaires: [quiz], mode: [["ivr"]]}) + Map.merge(@survey, %{state: :running, questionnaires: [quiz], mode: [["ivr"]]}) ) group = @@ -541,7 +541,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do Broker.poll() survey = Repo.get(Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -572,7 +572,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do survey = insert( :survey, - Map.merge(@survey, %{state: "running", questionnaires: [quiz], mode: [["ivr"]]}) + Map.merge(@survey, %{state: :running, questionnaires: [quiz], mode: [["ivr"]]}) ) group = @@ -592,7 +592,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do Broker.poll() survey = Repo.get(Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -622,7 +622,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do survey = insert( :survey, - Map.merge(@survey, %{state: "running", questionnaires: [quiz], mode: [["ivr"]]}) + Map.merge(@survey, %{state: :running, questionnaires: [quiz], mode: [["ivr"]]}) ) group = @@ -642,7 +642,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do Broker.poll() survey = Repo.get(Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -674,7 +674,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do survey = insert( :survey, - Map.merge(@survey, %{state: "running", questionnaires: [quiz], mode: [["ivr"]]}) + Map.merge(@survey, %{state: :running, questionnaires: [quiz], mode: [["ivr"]]}) ) group = @@ -694,7 +694,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do Broker.poll() survey = Repo.get(Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -726,7 +726,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do survey = insert( :survey, - Map.merge(@survey, %{state: "running", questionnaires: [quiz], mode: [["ivr"]]}) + Map.merge(@survey, %{state: :running, questionnaires: [quiz], mode: [["ivr"]]}) ) group = @@ -750,7 +750,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do Broker.handle_info(:poll, nil, Timex.now()) survey = Repo.get(Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running %Respondent{mode: mode} = respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -831,7 +831,7 @@ defmodule Ask.Runtime.VerboiceChannelTest do survey = insert( :survey, - Map.merge(@survey, %{state: "running", questionnaires: [quiz], mode: [["ivr"]]}) + Map.merge(@survey, %{state: :running, questionnaires: [quiz], mode: [["ivr"]]}) ) group = diff --git a/test/ask/survey_canceller_test.exs b/test/ask/survey_canceller_test.exs index 5b9027ea4..8f9873348 100644 --- a/test/ask/survey_canceller_test.exs +++ b/test/ask/survey_canceller_test.exs @@ -157,9 +157,9 @@ defmodule Ask.SurveyCancellerTest do } do project = create_project_for_user(user) questionnaire = insert(:questionnaire, name: "test", project: project) - survey_1 = insert(:survey, project: project, state: "cancelling") - survey_2 = insert(:survey, project: project, state: "cancelling") - survey_3 = insert(:survey, project: project, state: "running") + survey_1 = insert(:survey, project: project, state: :cancelling) + survey_2 = insert(:survey, project: project, state: :cancelling) + survey_3 = insert(:survey, project: project, state: :running) test_channel = TestChannel.new(false) channel = diff --git a/test/ask/survey_test.exs b/test/ask/survey_test.exs index df0752e79..88199bcec 100644 --- a/test/ask/survey_test.exs +++ b/test/ask/survey_test.exs @@ -59,12 +59,12 @@ defmodule Ask.SurveyTest do end test "survey has FLOIP package if it is running" do - survey = %Survey{state: "running"} + survey = %Survey{state: :running} assert length(survey |> Survey.packages()) == 1 end test "survey has FLOIP package if it is terminated" do - survey = %Survey{state: "terminated"} + survey = %Survey{state: :terminated} assert length(survey |> Survey.packages()) == 1 end @@ -92,14 +92,14 @@ defmodule Ask.SurveyTest do TimeMock |> expect(:now, fn -> test_now end) - changeset = Survey.changeset(%Survey{state: "terminated"}) + changeset = Survey.changeset(%Survey{state: :terminated}) assert get_field(changeset, :ended_at) == test_now end test "enumerates channels of running surveys" do surveys = [ - insert(:survey, state: "pending"), - insert(:survey, state: "running") + insert(:survey, state: :pending), + insert(:survey, state: :running) ] channels = [ diff --git a/test/ask_web/controllers/floip_controller_test.exs b/test/ask_web/controllers/floip_controller_test.exs index b103753e8..fc279baf8 100644 --- a/test/ask_web/controllers/floip_controller_test.exs +++ b/test/ask_web/controllers/floip_controller_test.exs @@ -46,7 +46,7 @@ defmodule AskWeb.FloipControllerTest do test "injects a self referential link to the view", %{conn: conn, user: user} do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "running") + survey = insert(:survey, project: project, state: :running) conn = conn |> put_req_header("accept", "application/vnd.api+json") @@ -66,7 +66,7 @@ defmodule AskWeb.FloipControllerTest do test "does not leak packages that dont belong to user", %{conn: conn, user: _user} do user2 = insert(:user) project = create_project_for_user(user2) - survey = insert(:survey, project: project, state: "running", floip_package_id: "foo") + survey = insert(:survey, project: project, state: :running, floip_package_id: "foo") assert_error_sent :forbidden, fn -> get( @@ -84,7 +84,7 @@ defmodule AskWeb.FloipControllerTest do test "ensures provided package id is correct", %{conn: conn, user: user} do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "running", floip_package_id: "foo") + survey = insert(:survey, project: project, state: :running, floip_package_id: "foo") assert_error_sent :forbidden, fn -> get( @@ -99,7 +99,7 @@ defmodule AskWeb.FloipControllerTest do user: user } do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "not_ready", floip_package_id: "foo") + survey = insert(:survey, project: project, state: :not_ready, floip_package_id: "foo") assert_error_sent :forbidden, fn -> get( @@ -115,7 +115,7 @@ defmodule AskWeb.FloipControllerTest do survey = insert(:survey, project: project, - state: "running", + state: :running, floip_package_id: "foo", started_at: DateTime.utc_now() ) @@ -166,7 +166,7 @@ defmodule AskWeb.FloipControllerTest do survey = insert(:survey, project: project, - state: "running", + state: :running, floip_package_id: "foo", started_at: DateTime.utc_now() ) @@ -215,7 +215,7 @@ defmodule AskWeb.FloipControllerTest do survey = insert(:survey, project: project, - state: "running", + state: :running, floip_package_id: "foo", started_at: DateTime.utc_now() ) @@ -256,7 +256,7 @@ defmodule AskWeb.FloipControllerTest do survey = insert(:survey, project: project, - state: "running", + state: :running, floip_package_id: "foo", started_at: DateTime.utc_now() ) @@ -314,7 +314,7 @@ defmodule AskWeb.FloipControllerTest do survey = insert(:survey, project: project, - state: "running", + state: :running, floip_package_id: "foo", started_at: DateTime.utc_now() ) @@ -350,7 +350,7 @@ defmodule AskWeb.FloipControllerTest do test "does not leak packages that dont belong to user", %{conn: conn, user: _user} do user2 = insert(:user) project = create_project_for_user(user2) - survey = insert(:survey, project: project, state: "running", floip_package_id: "foo") + survey = insert(:survey, project: project, state: :running, floip_package_id: "foo") assert_error_sent :forbidden, fn -> get( @@ -362,7 +362,7 @@ defmodule AskWeb.FloipControllerTest do test "ensures provided package id is correct", %{conn: conn, user: user} do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "running", floip_package_id: "foo") + survey = insert(:survey, project: project, state: :running, floip_package_id: "foo") assert_error_sent :forbidden, fn -> get( @@ -377,7 +377,7 @@ defmodule AskWeb.FloipControllerTest do user: user } do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "not_ready", floip_package_id: "foo") + survey = insert(:survey, project: project, state: :not_ready, floip_package_id: "foo") assert_error_sent :forbidden, fn -> get( diff --git a/test/ask_web/controllers/mobile_survey_controller_test.exs b/test/ask_web/controllers/mobile_survey_controller_test.exs index 32033642b..f74b84751 100644 --- a/test/ask_web/controllers/mobile_survey_controller_test.exs +++ b/test/ask_web/controllers/mobile_survey_controller_test.exs @@ -37,7 +37,7 @@ defmodule AskWeb.MobileSurveyControllerTest do survey = insert(:survey, %{ schedule: Ask.Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [["mobileweb"]] }) @@ -96,7 +96,7 @@ defmodule AskWeb.MobileSurveyControllerTest do survey = insert(:survey, %{ schedule: Ask.Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [["mobileweb"]] }) @@ -135,7 +135,7 @@ defmodule AskWeb.MobileSurveyControllerTest do }" survey = Repo.get(Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -385,7 +385,7 @@ defmodule AskWeb.MobileSurveyControllerTest do survey = insert(:survey, %{ schedule: Ask.Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [["mobileweb"]] }) @@ -455,7 +455,7 @@ defmodule AskWeb.MobileSurveyControllerTest do survey = insert(:survey, %{ schedule: Ask.Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [["mobileweb"]] }) @@ -502,7 +502,7 @@ defmodule AskWeb.MobileSurveyControllerTest do survey = insert(:survey, %{ schedule: Ask.Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [["mobileweb"]] }) @@ -554,7 +554,7 @@ defmodule AskWeb.MobileSurveyControllerTest do survey = insert(:survey, %{ schedule: Ask.Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [["mobileweb"]] }) @@ -592,7 +592,7 @@ defmodule AskWeb.MobileSurveyControllerTest do }" survey = Repo.get(Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running respondent = Repo.get(Respondent, respondent.id) assert respondent.state == :active @@ -634,7 +634,7 @@ defmodule AskWeb.MobileSurveyControllerTest do survey = insert(:survey, %{ schedule: Ask.Schedule.always(), - state: "running", + state: :running, questionnaires: [quiz], mode: [["mobileweb"]] }) diff --git a/test/ask_web/controllers/oauth_client_controller_test.exs b/test/ask_web/controllers/oauth_client_controller_test.exs index 8b7b602a5..cdf376b6b 100644 --- a/test/ask_web/controllers/oauth_client_controller_test.exs +++ b/test/ask_web/controllers/oauth_client_controller_test.exs @@ -99,7 +99,7 @@ defmodule AskWeb.OAuthClientControllerTest do insert(:oauth_token, user: user, provider: "provider", base_url: "http://test.com") channel = insert(:channel, user: user, provider: "provider", base_url: "http://test.com") - survey = insert(:survey, state: "ready") + survey = insert(:survey, state: :ready) respondent_group = insert(:respondent_group, survey: survey) insert(:respondent_group_channel, @@ -111,7 +111,7 @@ defmodule AskWeb.OAuthClientControllerTest do delete(conn, o_auth_client_path(conn, :delete, "provider", base_url: "http://test.com")) survey = Repo.get!(Ask.Survey, survey.id) - assert survey.state == "not_ready" + assert survey.state == :not_ready refute Ask.Channel |> Repo.get(channel.id) end @@ -123,7 +123,7 @@ defmodule AskWeb.OAuthClientControllerTest do insert(:oauth_token, user: user, provider: "provider", base_url: "http://test.com") channel = insert(:channel, user: user, provider: "provider", base_url: "http://test.com") - survey = insert(:survey, state: "running") + survey = insert(:survey, state: :running) respondent_group = insert(:respondent_group, survey: survey) respondent = @@ -138,7 +138,7 @@ defmodule AskWeb.OAuthClientControllerTest do delete(conn, o_auth_client_path(conn, :delete, "provider", base_url: "http://test.com")) survey = Repo.get!(Ask.Survey, survey.id) - assert survey.state == "terminated" + assert survey.state == :terminated assert survey.exit_code == 3 assert survey.exit_message == "Channel '#{channel.name}' no longer exists" diff --git a/test/ask_web/controllers/panel_survey_controller_test.exs b/test/ask_web/controllers/panel_survey_controller_test.exs index beb6cb4e5..63be7ae4a 100644 --- a/test/ask_web/controllers/panel_survey_controller_test.exs +++ b/test/ask_web/controllers/panel_survey_controller_test.exs @@ -103,7 +103,7 @@ defmodule AskWeb.PanelSurveyControllerTest do insert(:survey, project: project, generates_panel_survey: true, - state: "ready", + state: :ready, name: @foo_string ) @@ -126,7 +126,7 @@ defmodule AskWeb.PanelSurveyControllerTest do project: project, generates_panel_survey: true, folder: folder, - state: "ready", + state: :ready, name: @foo_string ) @@ -213,7 +213,7 @@ defmodule AskWeb.PanelSurveyControllerTest do defp assert_new_wave(response_panel_survey, previous_wave, panel_survey) do new_wave = PanelSurvey.latest_wave(panel_survey) assert new_wave.id > previous_wave.id - assert new_wave.state == "ready" + assert new_wave.state == :ready assert assert_panel_survey(response_panel_survey, panel_survey) end diff --git a/test/ask_web/controllers/project_controller_test.exs b/test/ask_web/controllers/project_controller_test.exs index df0b88841..82104a36b 100644 --- a/test/ask_web/controllers/project_controller_test.exs +++ b/test/ask_web/controllers/project_controller_test.exs @@ -139,14 +139,14 @@ defmodule AskWeb.ProjectControllerTest do test "shows running survey count", %{conn: conn, user: user} do project1 = create_project_for_user(user) project1 = Project |> Repo.get(project1.id) - insert(:survey, project: project1, state: "running") - insert(:survey, project: project1, state: "running") - insert(:survey, project: project1, state: "pending") + insert(:survey, project: project1, state: :running) + insert(:survey, project: project1, state: :running) + insert(:survey, project: project1, state: :pending) project2 = create_project_for_user(user) project2 = Project |> Repo.get(project2.id) - insert(:survey, project: project2, state: "running") - insert(:survey, project: project2, state: "pending") + insert(:survey, project: project2, state: :running) + insert(:survey, project: project2, state: :pending) project3 = create_project_for_user(user) project3 = Project |> Repo.get(project3.id) diff --git a/test/ask_web/controllers/questionnaire_controller_test.exs b/test/ask_web/controllers/questionnaire_controller_test.exs index eedf7832d..5aef6900e 100644 --- a/test/ask_web/controllers/questionnaire_controller_test.exs +++ b/test/ask_web/controllers/questionnaire_controller_test.exs @@ -439,7 +439,7 @@ defmodule AskWeb.QuestionnaireControllerTest do insert(:survey, project: project, questionnaires: [questionnaire_with_survey], - state: "ready" + state: :ready ) insert(:survey_questionnaire, survey: survey, questionnaire: questionnaire_with_survey) @@ -672,25 +672,25 @@ defmodule AskWeb.QuestionnaireControllerTest do test "updates survey ready state when valid changes", %{conn: conn, user: user} do project = create_project_for_user(user) questionnaire = insert(:questionnaire, project: project, valid: true) - survey = insert(:survey, project: project, questionnaires: [questionnaire], state: "ready") + survey = insert(:survey, project: project, questionnaires: [questionnaire], state: :ready) put conn, project_questionnaire_path(conn, :update, project, questionnaire), questionnaire: %{"valid" => false, steps: [], settings: %{}} survey = Ask.Survey |> Repo.get!(survey.id) - assert survey.state == "not_ready" + assert survey.state == :not_ready end test "updates survey ready state when mode changes", %{conn: conn, user: user} do project = create_project_for_user(user) questionnaire = insert(:questionnaire, project: project) - survey = insert(:survey, project: project, questionnaires: [questionnaire], state: "ready") + survey = insert(:survey, project: project, questionnaires: [questionnaire], state: :ready) put conn, project_questionnaire_path(conn, :update, project, questionnaire), questionnaire: %{"modes" => ["ivr"], steps: [], settings: %{}} survey = Ask.Survey |> Repo.get!(survey.id) - assert survey.state == "not_ready" + assert survey.state == :not_ready end end @@ -1088,13 +1088,13 @@ defmodule AskWeb.QuestionnaireControllerTest do test "remove reference from survey when questionnaire is deleted", %{conn: conn, user: user} do project = create_project_for_user(user) questionnaire = insert(:questionnaire, project: project) - survey = insert(:survey, project: project, questionnaires: [questionnaire], state: "ready") + survey = insert(:survey, project: project, questionnaires: [questionnaire], state: :ready) delete(conn, project_questionnaire_path(conn, :delete, project, questionnaire)) survey = Ask.Survey |> preload(:questionnaires) |> Repo.get!(survey.id) assert survey.questionnaires == [] - assert survey.state == "not_ready" + assert survey.state == :not_ready end end diff --git a/test/ask_web/controllers/respondent_controller_test.exs b/test/ask_web/controllers/respondent_controller_test.exs index 9fa00806c..f13de73c3 100644 --- a/test/ask_web/controllers/respondent_controller_test.exs +++ b/test/ask_web/controllers/respondent_controller_test.exs @@ -484,7 +484,7 @@ defmodule AskWeb.RespondentControllerTest do :survey, project: project, questionnaires: [q1, q2], - state: "running", + state: :running, cutoff: 10, mode: [["sms"], ["ivr"]], started_at: t, @@ -580,7 +580,7 @@ defmodule AskWeb.RespondentControllerTest do :survey, project: project, questionnaires: [q1, q2], - state: "terminated", + state: :terminated, cutoff: 10, mode: [["sms"], ["ivr"]], started_at: t, @@ -1105,7 +1105,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 10, started_at: t, - state: "running", + state: :running, questionnaires: [questionnaire] ) @@ -1659,7 +1659,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule(), mode: [["sms", "ivr"], ["mobileweb"], ["sms", "mobileweb"]] ) @@ -1702,7 +1702,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule(), mode: [["sms", "ivr"], ["mobileweb"], ["sms", "mobileweb"]] ) @@ -2224,7 +2224,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule(), mode: [["sms", "ivr"], ["mobileweb"], ["sms", "mobileweb"]] ) @@ -2362,7 +2362,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule(), mode: [["sms", "ivr"], ["mobileweb"], ["sms", "mobileweb"]] ) @@ -2423,7 +2423,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule(), mode: [["sms", "ivr"], ["mobileweb"], ["sms", "mobileweb"]] ) @@ -2560,7 +2560,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule(), mode: [["sms", "ivr"], ["mobileweb"], ["sms", "mobileweb"]] ) @@ -2672,7 +2672,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -2750,7 +2750,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -2831,7 +2831,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -2913,7 +2913,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule(), mode: [["sms", "ivr"], ["mobileweb"], ["sms", "mobileweb"]] ) @@ -3096,7 +3096,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -3191,7 +3191,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -3268,7 +3268,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -3338,7 +3338,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -3411,7 +3411,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire, questionnaire2], - state: "ready", + state: :ready, schedule: completed_schedule(), comparisons: [ %{"mode" => ["sms"], "questionnaire_id" => questionnaire.id, "ratio" => 50}, @@ -3525,7 +3525,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire, questionnaire2], - state: "ready", + state: :ready, schedule: completed_schedule(), comparisons: [ %{"mode" => ["sms"], "questionnaire_id" => questionnaire.id, "ratio" => 50}, @@ -3646,7 +3646,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -3694,7 +3694,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -3773,7 +3773,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -3843,7 +3843,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -3960,7 +3960,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -4064,7 +4064,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule(), mode: [["sms", "ivr"], ["mobileweb"], ["sms", "mobileweb"]] ) @@ -4102,7 +4102,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -4184,7 +4184,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule(), mode: [["sms", "ivr"], ["mobileweb"], ["sms", "mobileweb"]] ) @@ -4226,7 +4226,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -4286,7 +4286,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -4323,7 +4323,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -4435,7 +4435,7 @@ defmodule AskWeb.RespondentControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -4749,7 +4749,7 @@ defmodule AskWeb.RespondentControllerTest do :survey, project: project, schedule: Schedule.always(), - state: "running", + state: :running, questionnaires: questionnaires, mode: [[mode]], comparisons: [ @@ -4768,7 +4768,7 @@ defmodule AskWeb.RespondentControllerTest do :survey, project: project, schedule: Schedule.always(), - state: "running", + state: :running, questionnaires: questionnaires, mode: [[mode]] ) diff --git a/test/ask_web/controllers/respondent_group_controller_test.exs b/test/ask_web/controllers/respondent_group_controller_test.exs index e4342e180..1feab6fdb 100644 --- a/test/ask_web/controllers/respondent_group_controller_test.exs +++ b/test/ask_web/controllers/respondent_group_controller_test.exs @@ -110,7 +110,7 @@ defmodule AskWeb.RespondentGroupControllerTest do user: user } do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "running") + survey = insert(:survey, project: project, state: :running) file = %Plug.Upload{ path: "test/fixtures/respondent_phone_numbers.csv", @@ -401,7 +401,7 @@ defmodule AskWeb.RespondentGroupControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -448,7 +448,7 @@ defmodule AskWeb.RespondentGroupControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "running", + state: :running, schedule: completed_schedule() ) @@ -485,7 +485,7 @@ defmodule AskWeb.RespondentGroupControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -553,7 +553,7 @@ defmodule AskWeb.RespondentGroupControllerTest do test "it doesn't deletes a group when the survey is running", %{conn: conn, user: user} do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "running") + survey = insert(:survey, project: project, state: :running) local_time = DateTime.utc_now() |> DateTime.truncate(:second) group = insert(:respondent_group, survey: survey) @@ -693,7 +693,7 @@ defmodule AskWeb.RespondentGroupControllerTest do project: project, cutoff: 4, questionnaires: [questionnaire], - state: "ready", + state: :ready, schedule: completed_schedule() ) @@ -704,7 +704,7 @@ defmodule AskWeb.RespondentGroupControllerTest do insert(:respondent, phone_number: "12345678", survey: survey, respondent_group: group) - assert survey.state == "ready" + assert survey.state == :ready conn = delete( @@ -722,7 +722,7 @@ defmodule AskWeb.RespondentGroupControllerTest do new_survey = Repo.get(Ask.Survey, survey.id) - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready end end @@ -740,7 +740,7 @@ defmodule AskWeb.RespondentGroupControllerTest do user: user } do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "running") + survey = insert(:survey, project: project, state: :running) perform_add_test_for_survey(conn, project, survey) # It logs if the survey is running assert Repo.get_by(ActivityLog, action: "add_respondents", entity_id: survey.id) @@ -829,7 +829,7 @@ defmodule AskWeb.RespondentGroupControllerTest do test "doesn't add more respondents if survey is locked", %{conn: conn, user: user} do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "running", locked: true) + survey = insert(:survey, project: project, state: :running, locked: true) group = insert(:respondent_group, @@ -869,7 +869,7 @@ defmodule AskWeb.RespondentGroupControllerTest do test "duplicated respondents should be ignored even if the sanitized_phone_number has changed", %{conn: conn, user: user} do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "running") + survey = insert(:survey, project: project, state: :running) group = insert(:respondent_group, diff --git a/test/ask_web/controllers/survey_controller_test.exs b/test/ask_web/controllers/survey_controller_test.exs index 386f80dfc..7a6f8aafb 100644 --- a/test/ask_web/controllers/survey_controller_test.exs +++ b/test/ask_web/controllers/survey_controller_test.exs @@ -109,11 +109,11 @@ defmodule AskWeb.SurveyControllerTest do test "list only running surveys", %{conn: conn, user: user} do project = create_project_for_user(user) - insert(:survey, project: project, state: "terminated", exit_code: 0) - survey = insert(:survey, project: project, state: "running") + insert(:survey, project: project, state: :terminated, exit_code: 0) + survey = insert(:survey, project: project, state: :running) survey = Survey |> Repo.get(survey.id) - conn = get(conn, project_survey_path(conn, :index, project.id, state: "running")) + conn = get(conn, project_survey_path(conn, :index, project.id, state: :running)) assert json_response(conn, 200)["data"] == [ %{ @@ -189,11 +189,11 @@ defmodule AskWeb.SurveyControllerTest do test "list only completed surveys", %{conn: conn, user: user} do project = create_project_for_user(user) - insert(:survey, project: project, state: "running") - survey = insert(:survey, project: project, state: "terminated", exit_code: 0) + insert(:survey, project: project, state: :running) + survey = insert(:survey, project: project, state: :terminated, exit_code: 0) survey = Survey |> Repo.get(survey.id) - conn = get(conn, project_survey_path(conn, :index, project.id, state: "completed")) + conn = get(conn, project_survey_path(conn, :index, project.id, state: :completed)) assert json_response(conn, 200)["data"] == [ %{ @@ -248,7 +248,7 @@ defmodule AskWeb.SurveyControllerTest do insert(:survey, project: project, updated_at: Timex.shift(Timex.now(), hours: 2, minutes: 3), - state: "running" + state: :running ) survey = Survey |> Repo.get(survey.id) @@ -311,9 +311,9 @@ defmodule AskWeb.SurveyControllerTest do Process.register(self(), :mail_target) project = create_project_for_user(user) - survey_1 = insert(:survey, project: project, state: "running") - survey_2 = insert(:survey, project: project, state: "running") - survey_3 = insert(:survey, project: project, state: "running") + survey_1 = insert(:survey, project: project, state: :running) + survey_2 = insert(:survey, project: project, state: :running) + survey_3 = insert(:survey, project: project, state: :running) up_channel = TestChannel.create_channel(user, "test", TestChannel.settings(TestChannel.new(), 1)) @@ -381,7 +381,7 @@ defmodule AskWeb.SurveyControllerTest do insert(:survey, project: project, description: "initial survey", - state: "terminated", + state: :terminated, started_at: Timex.now(), ended_at: Timex.shift(Timex.now(), days: 1) ) @@ -756,7 +756,7 @@ defmodule AskWeb.SurveyControllerTest do Process.register(self(), :mail_target) project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "running") + survey = insert(:survey, project: project, state: :running) survey = Survey |> Repo.get(survey.id) up_channel = @@ -1902,7 +1902,7 @@ defmodule AskWeb.SurveyControllerTest do test "reject delete if the survey is running", %{conn: conn, user: user} do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "running") + survey = insert(:survey, project: project, state: :running) assert_error_sent :conflict, fn -> delete(conn, project_survey_path(conn, :delete, survey.project, survey)) @@ -1964,7 +1964,7 @@ defmodule AskWeb.SurveyControllerTest do qs = (new_survey |> Repo.preload(:questionnaires)).questionnaires assert length(qs) == 1 assert hd(qs).id == questionnaire.id - assert new_survey.state == "ready" + assert new_survey.state == :ready end test "updates state when selecting mode", %{conn: conn, user: user} do @@ -1985,7 +1985,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "ready" + assert new_survey.state == :ready end test "updates state when selecting mode, missing channel", %{conn: conn, user: user} do @@ -2007,7 +2007,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready end test "updates state when selecting mode, missing channel, multiple modes", %{ @@ -2032,7 +2032,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready end test "updates state when selecting mode, all channels", %{conn: conn, user: user} do @@ -2057,7 +2057,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "ready" + assert new_survey.state == :ready end test "updates state when adding cutoff", %{conn: conn, user: user} do @@ -2077,7 +2077,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "ready" + assert new_survey.state == :ready end test "changes state to not_ready when an invalid retry attempt configuration is passed", %{ @@ -2103,7 +2103,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready end test "changes state to not_ready when an invalid fallback delay is passed", %{ @@ -2129,7 +2129,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready end test "returns state to ready when a valid retry configuration is passed", %{ @@ -2151,7 +2151,7 @@ defmodule AskWeb.SurveyControllerTest do create_group(survey, channel) new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready conn = put conn, project_survey_path(conn, :update, project, survey), @@ -2159,7 +2159,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "ready" + assert new_survey.state == :ready end test "updates state when adding a day in schedule", %{conn: conn, user: user} do @@ -2184,7 +2184,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "ready" + assert new_survey.state == :ready end test "updates state when removing schedule", %{conn: conn, user: user} do @@ -2206,7 +2206,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready end test "updates state when removing questionnaire", %{conn: conn, user: user} do @@ -2217,13 +2217,13 @@ defmodule AskWeb.SurveyControllerTest do project: project, questionnaires: [questionnaire], cutoff: 4, - state: "ready", + state: :ready, schedule: completed_schedule() ) create_group(survey, channel) - assert survey.state == "ready" + assert survey.state == :ready conn = put conn, project_survey_path(conn, :update, project, survey), @@ -2233,7 +2233,7 @@ defmodule AskWeb.SurveyControllerTest do new_survey = Repo.get(Survey, survey.id) qs = (new_survey |> Repo.preload(:questionnaires)).questionnaires assert length(qs) == 0 - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready end test "does not update state when adding cutoff if missing questionnaire", %{ @@ -2243,7 +2243,7 @@ defmodule AskWeb.SurveyControllerTest do [project, _, channel] = prepare_for_state_update(user) survey = insert(:survey, project: project, schedule: completed_schedule()) - assert survey.state == "not_ready" + assert survey.state == :not_ready create_group(survey, channel) @@ -2251,7 +2251,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready end test "does not update state when adding cutoff if missing respondents", %{ @@ -2267,13 +2267,13 @@ defmodule AskWeb.SurveyControllerTest do schedule: completed_schedule() ) - assert survey.state == "not_ready" + assert survey.state == :not_ready conn = put conn, project_survey_path(conn, :update, project, survey), survey: %{cutoff: 4} assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready end test "does not update state when adding questionnaire if missing channel", %{ @@ -2291,7 +2291,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready end test "sets to not ready if comparisons' ratio don't sum 100", %{conn: conn, user: user} do @@ -2316,7 +2316,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready end test "sets to ready if comparisons' ratio sum 100", %{conn: conn, user: user} do @@ -2341,7 +2341,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "ready" + assert new_survey.state == :ready end test "changes state to not_ready when questionnaire is invalid", %{conn: conn, user: user} do @@ -2365,7 +2365,7 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready end test "changes state to not_ready when survey mode doesn't match questionnaire mode", %{ @@ -2391,13 +2391,13 @@ defmodule AskWeb.SurveyControllerTest do assert json_response(conn, 200)["data"]["id"] new_survey = Repo.get(Survey, survey.id) - assert new_survey.state == "not_ready" + assert new_survey.state == :not_ready end end test "prevents launching a survey that is not in the ready state", %{conn: conn, user: user} do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "not_ready") + survey = insert(:survey, project: project, state: :not_ready) conn = post(conn, project_survey_survey_path(conn, :launch, survey.project, survey)) @@ -2406,12 +2406,12 @@ defmodule AskWeb.SurveyControllerTest do test "when launching a survey, it sets the state to running", %{conn: conn, user: user} do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "ready") + survey = insert(:survey, project: project, state: :ready) conn = post(conn, project_survey_survey_path(conn, :launch, survey.project, survey)) assert json_response(conn, 200) - assert Repo.get(Survey, survey.id).state == "running" + assert Repo.get(Survey, survey.id).state == :running end test "when launching a survey, it creates questionnaire snapshots", %{conn: conn, user: user} do @@ -2422,7 +2422,7 @@ defmodule AskWeb.SurveyControllerTest do survey = insert(:survey, project: project, - state: "ready", + state: :ready, questionnaires: [questionnaire], comparisons: [ %{"mode" => ["sms"], "questionnaire_id" => questionnaire.id, "one" => 50}, @@ -2465,7 +2465,7 @@ defmodule AskWeb.SurveyControllerTest do ) survey_ready = - insert(:survey, project: project, state: "ready", questionnaires: [questionnaire]) + insert(:survey, project: project, state: :ready, questionnaires: [questionnaire]) post(conn, project_survey_survey_path(conn, :launch, survey_ready.project, survey_ready)) survey_launched = Repo.get(Survey, survey_ready.id) @@ -2482,7 +2482,7 @@ defmodule AskWeb.SurveyControllerTest do test "forbids launch for project reader", %{conn: conn, user: user} do project = create_project_for_user(user, level: "reader") - survey = insert(:survey, project: project, state: "ready") + survey = insert(:survey, project: project, state: :ready) assert_error_sent :forbidden, fn -> post(conn, project_survey_survey_path(conn, :launch, survey.project, survey)) @@ -2491,7 +2491,7 @@ defmodule AskWeb.SurveyControllerTest do test "forbids launch if project is archived", %{conn: conn, user: user} do project = create_project_for_user(user, archived: true) - survey = insert(:survey, project: project, state: "ready") + survey = insert(:survey, project: project, state: :ready) assert_error_sent :forbidden, fn -> post(conn, project_survey_survey_path(conn, :launch, survey.project, survey)) @@ -2500,7 +2500,7 @@ defmodule AskWeb.SurveyControllerTest do test "launches a survey with channel", %{conn: conn, user: user} do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "ready") + survey = insert(:survey, project: project, state: :ready) test_channel = TestChannel.new() channel = insert(:channel, settings: test_channel |> TestChannel.settings(), type: "sms") create_group(survey, channel) @@ -2508,7 +2508,7 @@ defmodule AskWeb.SurveyControllerTest do conn = post(conn, project_survey_survey_path(conn, :launch, survey.project, survey)) assert json_response(conn, 200) - assert Repo.get(Survey, survey.id).state == "running" + assert Repo.get(Survey, survey.id).state == :running assert_received [:prepare, ^test_channel] end @@ -2519,7 +2519,7 @@ defmodule AskWeb.SurveyControllerTest do } do now = Timex.now() project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "ready") + survey = insert(:survey, project: project, state: :ready) post(conn, project_survey_survey_path(conn, :launch, survey.project, survey)) @@ -2537,7 +2537,7 @@ defmodule AskWeb.SurveyControllerTest do now = Date.add(end_date, -1) mock_time(Timex.to_datetime(now)) schedule = %{completed_schedule() | end_date: end_date} - survey = insert(:survey, project: project, state: "ready", schedule: schedule) + survey = insert(:survey, project: project, state: :ready, schedule: schedule) post(conn, project_survey_survey_path(conn, :launch, survey.project, survey)) @@ -2550,7 +2550,7 @@ defmodule AskWeb.SurveyControllerTest do test "updates project updated_at when a survey is launched", %{conn: conn, user: user} do {:ok, datetime, _} = DateTime.from_iso8601("2000-01-01T00:00:00Z") project = create_project_for_user(user, updated_at: datetime) - survey = insert(:survey, project: project, state: "ready") + survey = insert(:survey, project: project, state: :ready) post(conn, project_survey_survey_path(conn, :launch, survey.project, survey)) @@ -2564,7 +2564,7 @@ defmodule AskWeb.SurveyControllerTest do test "stops survey", %{conn: conn, user: user} do project = create_project_for_user(user) questionnaire = insert(:questionnaire, name: "test", project: project) - survey = insert(:survey, project: project, state: "running") + survey = insert(:survey, project: project, state: :running) test_channel = TestChannel.new(false) channel = insert(:channel, settings: test_channel |> TestChannel.settings(), type: "sms") group = create_group(survey, channel) @@ -2604,8 +2604,8 @@ defmodule AskWeb.SurveyControllerTest do test "stops respondents only for the stopped survey", %{conn: conn, user: user} do project = create_project_for_user(user) questionnaire = insert(:questionnaire, name: "test", project: project) - survey = insert(:survey, project: project, state: "running") - survey2 = insert(:survey, project: project, state: "running") + survey = insert(:survey, project: project, state: :running) + survey2 = insert(:survey, project: project, state: :running) test_channel = TestChannel.new(false) channel = insert(:channel, settings: test_channel |> TestChannel.settings(), type: "sms") group = create_group(survey, channel) @@ -2637,7 +2637,7 @@ defmodule AskWeb.SurveyControllerTest do wait_all_cancellations(conn) assert json_response(conn, 200) - assert Repo.get(Survey, survey2.id).state == "running" + assert Repo.get(Survey, survey2.id).state == :running assert length(Repo.all(from(r in Ask.Respondent, where: r.state == :active))) == 6 assert_receive [:cancel_message, ^test_channel, ^channel_state] end @@ -2673,13 +2673,13 @@ defmodule AskWeb.SurveyControllerTest do test "doesn't stop survey if it is locked", %{conn: conn, user: user} do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "running", locked: true) + survey = insert(:survey, project: project, state: :running, locked: true) conn = post(conn, project_survey_survey_path(conn, :stop, project, survey)) assert response(conn, 422) survey = Repo.get(Survey, survey.id) - assert survey.state == "running" + assert survey.state == :running end end @@ -2691,7 +2691,7 @@ defmodule AskWeb.SurveyControllerTest do survey = insert(:survey, project: project, - state: "running", + state: :running, locked: false, questionnaires: [questionnaire] ) @@ -2717,7 +2717,7 @@ defmodule AskWeb.SurveyControllerTest do survey = insert(:survey, project: project, - state: "running", + state: :running, locked: false, questionnaires: [questionnaire] ) @@ -2741,7 +2741,7 @@ defmodule AskWeb.SurveyControllerTest do survey = insert(:survey, project: project, - state: "running", + state: :running, locked: false, questionnaires: [questionnaire] ) @@ -2766,7 +2766,7 @@ defmodule AskWeb.SurveyControllerTest do project = create_project_for_user(user) questionnaire = insert(:questionnaire, project: project) - ["not_ready", "ready", "pending", "terminated"] + [:not_ready, :ready, :pending, :terminated] |> Enum.each(fn state -> survey = insert(:survey, @@ -2855,7 +2855,7 @@ defmodule AskWeb.SurveyControllerTest do test "generates log after launching a survey", %{conn: conn, user: user} do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "ready") + survey = insert(:survey, project: project, state: :ready) post(conn, project_survey_survey_path(conn, :launch, survey.project, survey)) log = ActivityLog |> Repo.one() @@ -2873,7 +2873,7 @@ defmodule AskWeb.SurveyControllerTest do test "generates logs after stopping a survey", %{conn: conn, user: user} do project = create_project_for_user(user) - survey = insert(:survey, project: project, state: "running") + survey = insert(:survey, project: project, state: :running) post(conn, project_survey_survey_path(conn, :stop, survey.project, survey)) @@ -3021,7 +3021,7 @@ defmodule AskWeb.SurveyControllerTest do survey = insert(:survey, project: project, - state: "running", + state: :running, locked: false, questionnaires: [questionnaire] ) @@ -3050,7 +3050,7 @@ defmodule AskWeb.SurveyControllerTest do survey = insert(:survey, project: project, - state: "running", + state: :running, locked: true, questionnaires: [questionnaire] ) diff --git a/test/ask_web/controllers/survey_simulation_controller_test.exs b/test/ask_web/controllers/survey_simulation_controller_test.exs index f0be39df3..16425bb54 100644 --- a/test/ask_web/controllers/survey_simulation_controller_test.exs +++ b/test/ask_web/controllers/survey_simulation_controller_test.exs @@ -53,7 +53,7 @@ defmodule AskWeb.SurveySimulationControllerTest do survey = Survey |> Repo.get!(json_response(conn, 200)["data"]["id"]) assert survey.mode == [[mode]] - assert survey.state == "running" + assert survey.state == :running assert survey.cutoff == 1 assert survey.simulation == true diff --git a/test/support/factory.ex b/test/support/factory.ex index 9f8877b00..4294b0ede 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -48,7 +48,7 @@ defmodule Ask.Factory do schedule: Ask.Schedule.always(), name: sequence(:survey, &"Survey #{&1}"), mode: [["sms"]], - state: "not_ready", + state: :not_ready, floip_package_id: Ecto.UUID.generate() } end diff --git a/test/support/test_helpers.ex b/test/support/test_helpers.ex index 6adaba46e..c1bcf869c 100644 --- a/test/support/test_helpers.ex +++ b/test/support/test_helpers.ex @@ -64,7 +64,7 @@ defmodule Ask.TestHelpers do survey = %{ schedule: schedule, - state: "running", + state: :running, questionnaires: [quiz], mode: [[mode]], fallback_delay: fallback_delay, @@ -149,7 +149,7 @@ defmodule Ask.TestHelpers do defp panel_survey_generator_survey(project \\ nil) do project = if project, do: project, else: insert(:project) - insert(:survey, state: "ready", project: project, generates_panel_survey: true) + insert(:survey, state: :ready, project: project, generates_panel_survey: true) end defp panel_survey_generator_survey_with_cutoff_and_comparisons() do