Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
albertored committed May 27, 2020
1 parent 75e4a99 commit 55734e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
22 changes: 22 additions & 0 deletions test/ex_sieve/builder/join_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,27 @@ defmodule ExSieve.Builder.JoinTest do

assert original == built
end

test "work with from queries" do
grouping = sample_grouping(name: [])

original = from(u in User) |> (&Ecto.Adapters.SQL.to_sql(:all, ExSieve.Repo, &1)).()
built = User |> Join.build(grouping, []) |> (&Ecto.Adapters.SQL.to_sql(:all, ExSieve.Repo, &1)).()

assert original == built
end

test "work with existent joins" do
grouping = sample_grouping(title: [:posts])

original =
User
|> join(:inner, [u], p in assoc(u, :posts), as: :posts)
|> inspect()

built = User |> Join.build(grouping, []) |> inspect()

assert original == built
end
end
end
6 changes: 5 additions & 1 deletion test/ex_sieve_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule ExSieveTest do
{:ok, config: %Config{ignore_errors: false}}
end

describe "ExSieve.filter/3" do
describe "ExSieve.Filter.filter/3" do
test "return ordered by id and body", %{config: config} do
[%{body: body} | _] = insert_pair(:post)

Expand Down Expand Up @@ -56,6 +56,10 @@ defmodule ExSieveTest do
ids = User |> ExSieve.Filter.filter(%{"cash_lteq" => %Money{amount: 1000}}, config) |> ids()
assert ids == ids(User)
end

test "return error with invalid queries", %{config: config} do
assert {:error, :invalid_query} = ExSieve.Filter.filter(InvalidUser, %{}, config)
end
end

defp ids(query), do: query |> Repo.all() |> Enum.map(& &1.id)
Expand Down

0 comments on commit 55734e1

Please sign in to comment.