Skip to content

Commit

Permalink
test: add test for behavior fixed in ash
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Sep 16, 2024
1 parent 873a1f8 commit ee0c2a0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/calculation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,45 @@ defmodule AshPostgres.CalculationTest do
require Ash.Query
import Ash.Expr

test "a calculation that references a first optimizable aggregate can be sorted on" do
author1 =
Author
|> Ash.Changeset.for_create(:create, %{
first_name: "abc"
})
|> Ash.create!()

post =
Post
|> Ash.Changeset.for_create(:create, %{title: "match", author_id: author1.id})
|> Ash.create!()

author2 =
Author
|> Ash.Changeset.for_create(:create, %{
first_name: "def"
})
|> Ash.create!()

post2 =
Post
|> Ash.Changeset.for_create(:create, %{title: "match", author_id: author2.id})
|> Ash.create!()

post1_id = post.id
post2_id = post2.id

assert [%{id: ^post2_id}, %{id: ^post1_id}] =
Post
|> Ash.Query.sort(author_first_name_ref_agg_calc: :desc)
|> Ash.read!()

assert [%{id: ^post1_id}, %{id: ^post2_id}] =
Post
|> Ash.Query.sort(author_first_name_ref_agg_calc: :asc)
|> Ash.read!()
end

test "an expression calculation can be filtered on" do
post =
Post
Expand Down
1 change: 1 addition & 0 deletions test/support/resources/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,7 @@ defmodule AshPostgres.Test.Post do
)

calculate(:author_first_name_calc, :string, expr(author.first_name))
calculate(:author_first_name_ref_agg_calc, :string, expr(author_first_name))

calculate(:author_profile_description_from_agg, :string, expr(author_profile_description))
end
Expand Down

0 comments on commit ee0c2a0

Please sign in to comment.