Skip to content

Commit

Permalink
cleanup(ex/test): general cleanup related to upgrading to the latest …
Browse files Browse the repository at this point in the history
…Phoenix version and Template (#2868)

* cleanup(ex/test_helper): combine `ensure_application_started` calls

* doc:cleanup(ex/test_helper): add mocks section

* chore:test(ex/data_case): update `errors_on` helper to `phx.new` template

* cleanup:test(ex/conn_case): reorder 'using' macro acording to `phx.new` template
  • Loading branch information
firestack authored Oct 28, 2024
1 parent 4da7628 commit 2ffaa59
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions test/support/conn_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ defmodule SkateWeb.ConnCase do

using do
quote do
# Import conveniences for testing with connections
import Plug.Conn
import Phoenix.ConnTest
alias SkateWeb.Router.Helpers, as: Routes

# The default endpoint for testing
@endpoint SkateWeb.Endpoint

use SkateWeb, :verified_routes

# Import conveniences for testing with connections
import Plug.Conn
import Phoenix.ConnTest
import SkateWeb.ConnCase
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/support/data_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ defmodule Skate.DataCase do
end

@doc """
A helper that transform changeset errors to a map of messages.
A helper that transforms changeset errors into a map of messages.
assert {:error, changeset} = Accounts.create_user(%{password: "short"})
assert "password is too short" in errors_on(changeset).password
Expand All @@ -50,8 +50,8 @@ defmodule Skate.DataCase do
"""
def errors_on(changeset) do
Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
Enum.reduce(opts, message, fn {key, value}, acc ->
String.replace(acc, "%{#{key}}", to_string(value))
Regex.replace(~r"%{(\w+)}", message, fn _, key ->
opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string()
end)
end)
end
Expand Down
8 changes: 6 additions & 2 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Application.ensure_all_started(:stream_data)
{:ok, _} = Application.ensure_all_started(:ex_machina)
{:ok, _} =
Application.ensure_all_started([
:stream_data,
:ex_machina
])

ExUnit.start(
capture_log: true,
Expand All @@ -13,6 +16,7 @@ ExUnit.start(

Ecto.Adapters.SQL.Sandbox.mode(Skate.Repo, :manual)

# Mocks
Mox.defmock(Skate.OpenRouteServiceAPI.MockClient, for: Skate.OpenRouteServiceAPI.Client)

Application.put_env(:skate, Skate.OpenRouteServiceAPI,
Expand Down

0 comments on commit 2ffaa59

Please sign in to comment.