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

test: add failing test for an aggregate of a calculation #92

Merged
merged 1 commit into from
Aug 30, 2023
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
38 changes: 38 additions & 0 deletions test/read_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,44 @@ defmodule AshGraphql.ReadTest do
assert %{data: %{"getCompositePrimaryKey" => %{"id" => ^id}}} = result
end

test "aggregate of a calculation" do
post =
AshGraphql.Test.Post
|> Ash.Changeset.for_create(:create,
text: "foo",
published: true,
score: 9.8
)
|> AshGraphql.Test.Api.create!()

post =
AshGraphql.Test.Post
|> Ash.Changeset.for_create(:create, text: "foo", published: true)
|> AshGraphql.Test.Api.create!()

AshGraphql.Test.Comment
|> Ash.Changeset.for_create(:create, %{text: "stuff"})
|> Ash.Changeset.force_change_attribute(:post_id, post.id)
|> AshGraphql.Test.Api.create!()

resp =
"""
query Post($id: ID!) {
getPost(id: $id) {
latestCommentAt
}
}
"""
|> Absinthe.run(AshGraphql.Test.Schema,
variables: %{
"id" => post.id
}
)

assert {:ok, result} = resp
assert result[:data]["getPost"]["latestCommentAt"]
end

test "a read with custom types works" do
AshGraphql.Test.Post
|> Ash.Changeset.for_create(:create,
Expand Down
10 changes: 10 additions & 0 deletions test/support/resources/comment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ defmodule AshGraphql.Test.Comment do
writable?(false)
default(:comment)
end

create_timestamp(:created_at)
end

calculations do
calculate(
:timestamp,
:utc_datetime_usec,
expr(created_at)
)
end

relationships do
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 @@ -365,6 +365,7 @@ defmodule AshGraphql.Test.Post do

aggregates do
count(:comment_count, :comments)
max(:latest_comment_at, [:comments], :timestamp)
end

relationships do
Expand Down
Loading