From 1e637f9205b7ebe1774fc47e679b56b1ffc73aa3 Mon Sep 17 00:00:00 2001 From: Robert Timis <65460527+TimisRobert@users.noreply.github.com> Date: Tue, 16 Jul 2024 21:39:04 +0200 Subject: [PATCH] test: replicate error when building json object and using inline aggregate (#350) --- test/complex_calculations_test.exs | 17 +++++++++++++++++ .../resources/documentation.ex | 2 ++ .../complex_calculations/resources/skill.ex | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/test/complex_calculations_test.exs b/test/complex_calculations_test.exs index da13ab3..a1268c0 100644 --- a/test/complex_calculations_test.exs +++ b/test/complex_calculations_test.exs @@ -86,6 +86,23 @@ defmodule AshPostgres.Test.ComplexCalculationsTest do assert certification.count_of_skills_ever_demonstrated == 1 end + test "calculation of inline aggregate" do + skill = + AshPostgres.Test.ComplexCalculations.Skill + |> Ash.Changeset.new() + |> Ash.create!() + + AshPostgres.Test.ComplexCalculations.Documentation + |> Ash.Changeset.for_create(:create, %{status: :demonstrated}) + |> Ash.Changeset.manage_relationship(:skill, skill, type: :append) + |> Ash.create!() + + skill = Ash.load!(skill, [:documentations_custom]) + + assert %{one: "One", documentations: [%{two: "Two", status: :demonstrated}]} = + skill.documentations_custom + end + test "channel: first_member and second member" do channel = AshPostgres.Test.ComplexCalculations.Channel diff --git a/test/support/complex_calculations/resources/documentation.ex b/test/support/complex_calculations/resources/documentation.ex index 7ec7940..ad96189 100644 --- a/test/support/complex_calculations/resources/documentation.ex +++ b/test/support/complex_calculations/resources/documentation.ex @@ -29,6 +29,8 @@ defmodule AshPostgres.Test.ComplexCalculations.Documentation do end calculations do + calculate(:custom_map, :map, expr(%{status: status, two: "Two"})) + calculate( :timestamp, :utc_datetime_usec, diff --git a/test/support/complex_calculations/resources/skill.ex b/test/support/complex_calculations/resources/skill.ex index 7715900..6c81ced 100644 --- a/test/support/complex_calculations/resources/skill.ex +++ b/test/support/complex_calculations/resources/skill.ex @@ -39,6 +39,12 @@ defmodule AshPostgres.Test.ComplexCalculations.Skill do ) end + calculate( + :documentations_custom, + :map, + expr(%{one: "One", documentations: list(documentations, field: :custom_map)}) + ) + calculate :count_ever_demonstrated, :integer do calculation( expr(