Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add tiny_maps to help with condensed test syntax #16

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ defmodule Flick.MixProject do
# For test-driven development.
{:mix_test_watch, "~> 1.0", only: [:dev, :test], runtime: false},

# To allow our test descriptions to use a condensed map syntax.
{:tiny_maps, "~> 3.0"},

# Unorganized
{:bandit, "~> 1.2"},
{:dns_cluster, "~> 0.1.1"},
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"telemetry_metrics": {:hex, :telemetry_metrics, "0.6.2", "2caabe9344ec17eafe5403304771c3539f3b6e2f7fb6a6f602558c825d0d0bfb", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "9b43db0dc33863930b9ef9d27137e78974756f5f198cae18409970ed6fa5b561"},
"telemetry_poller": {:hex, :telemetry_poller, "1.0.0", "db91bb424e07f2bb6e73926fcafbfcbcb295f0193e0a00e825e589a0a47e8453", [:rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "b3a24eafd66c3f42da30fc3ca7dda1e9d546c12250a2d60d7b81d264fbec4f6e"},
"thousand_island": {:hex, :thousand_island, "1.3.5", "6022b6338f1635b3d32406ff98d68b843ba73b3aa95cfc27154223244f3a6ca5", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2be6954916fdfe4756af3239fb6b6d75d0b8063b5df03ba76fd8a4c87849e180"},
"tiny_maps": {:hex, :tiny_maps, "3.0.0", "afe01a2aa19bd0e8fc5b856529792205e90448caa1d96d934bb0ab5bddfeba49", [:mix], [], "hexpm", "29246bb7fa7a96ced99cf1761d0e51b96b12d0eead1f0fb0e245919e70a6bd6a"},
"websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"},
"websock_adapter": {:hex, :websock_adapter, "0.5.6", "0437fe56e093fd4ac422de33bf8fc89f7bc1416a3f2d732d8b2c8fd54792fe60", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "e04378d26b0af627817ae84c92083b7e97aca3121196679b73c73b99d0d133ea"},
}
12 changes: 3 additions & 9 deletions test/flick/votes_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ defmodule Flick.VotesTest do
{:ok, published_ballot: ballot}
end

test "success: creates a vote recording the passed in answers", %{
published_ballot: published_ballot
} do
test "success: creates a vote recording the passed in answers", ~M{published_ballot} do
published_ballot_id = published_ballot.id

assert {:ok, vote} =
Expand All @@ -45,9 +43,7 @@ defmodule Flick.VotesTest do
} = vote
end

test "success: a vote does not need to rank every possible answer", %{
published_ballot: published_ballot
} do
test "success: a vote does not need to rank every possible answer", ~M{published_ballot} do
published_ballot_id = published_ballot.id

assert {:ok, vote} =
Expand Down Expand Up @@ -110,9 +106,7 @@ defmodule Flick.VotesTest do
assert "answers must not be duplicated" in errors_on(pizza_2).value
end

test "failure: a vote needs to include at least one ranked answer", %{
published_ballot: published_ballot
} do
test "failure: a vote needs to include at least one ranked answer", ~M{published_ballot} do
attrs = %{
"ranked_answers" => [
%{"value" => ""},
Expand Down
2 changes: 1 addition & 1 deletion test/flick_web/live/ballots/editor_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule FlickWeb.Ballots.EditorLiveTest do
use FlickWeb.ConnCase, async: true

test "renders create ballot form", %{conn: conn} do
test "renders create ballot form", ~M{conn} do
assert {:ok, view, _html} = live(conn, ~p"/ballots/new")
assert has_element?(view, "#ballot_question_title")
assert has_element?(view, "#ballot_possible_answers")
Expand Down
2 changes: 1 addition & 1 deletion test/flick_web/live/ballots/index_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule FlickWeb.Ballots.IndexLiveTest do
use FlickWeb.ConnCase, async: true

test "renders list of ballots", %{conn: conn} do
test "renders list of ballots", ~M{conn} do
ballots = Enum.map(1..3, fn _ -> ballot_fixture() end)
assert {:ok, view, _html} = live(conn, ~p"/ballots")
assert has_element?(view, "table#ballots")
Expand Down
4 changes: 2 additions & 2 deletions test/flick_web/live/ballots/viewer_live_test.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
defmodule FlickWeb.Ballots.ViewerLiveTest do
use FlickWeb.ConnCase, async: true

test "renders ballot details", %{conn: conn} do
test "renders ballot details", ~M{conn} do
ballot = ballot_fixture()
assert {:ok, view, _html} = live(conn, ~p"/ballots/#{ballot}")
assert has_element?(view, "#ballot-question-title", ballot.question_title)
end

test "responds with 404 when no ballot is found", %{conn: conn} do
test "responds with 404 when no ballot is found", ~M{conn} do
assert_raise Ecto.NoResultsError, fn ->
live(conn, ~p"/ballots/#{Ecto.UUID.generate()}")
end
Expand Down
1 change: 1 addition & 0 deletions test/support/conn_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ defmodule FlickWeb.ConnCase do
import Phoenix.ConnTest
import FlickWeb.ConnCase
import Phoenix.LiveViewTest
import TinyMaps

import Support.Fixtures.BallotFixture
end
Expand Down
1 change: 1 addition & 0 deletions test/support/data_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ defmodule Flick.DataCase do
import Ecto.Changeset
import Ecto.Query
import Flick.DataCase
import TinyMaps

import Support.Fixtures.BallotFixture
end
Expand Down