improvement: add test for aggregates

This commit is contained in:
Zach Daniel 2024-02-24 18:08:00 -05:00
parent 98f24b1923
commit f6d029d85b
2 changed files with 20 additions and 0 deletions

View file

@ -1164,6 +1164,22 @@ defmodule AshPostgres.AggregateTest do
|> Api.count!()
end
test "a count with a limit and a filter can be aggregated at the query level" do
Post
|> Ash.Changeset.new(%{title: "foo"})
|> Api.create!()
Post
|> Ash.Changeset.new(%{title: "bar"})
|> Api.create!()
assert 1 ==
Post
|> Ash.Query.for_read(:title_is_foo)
|> Ash.Query.limit(1)
|> Api.count!()
end
test "a count can filter independently of the query" do
assert {:ok, %{count: 0, count2: 0}} =
Post

View file

@ -75,6 +75,10 @@ defmodule AshPostgres.Test.Post do
actions do
defaults([:update, :destroy])
read :title_is_foo do
filter(expr(title == "foo"))
end
read :read do
primary?(true)
end