diff options
author | Tusooa Zhu <tusooa@kazv.moe> | 2022-07-11 14:58:38 -0400 |
---|---|---|
committer | Tusooa Zhu <tusooa@kazv.moe> | 2022-08-20 20:43:40 -0400 |
commit | 06678fb4ad42fcaecb99eccc2237c3b863a2b9a5 (patch) | |
tree | 9c27440d3e12cb15aecd5e42e77396330ce669b5 /test/pleroma | |
parent | 6ccab516a3f62682fe15f8efec36be82acafc155 (diff) | |
download | pleroma-06678fb4ad42fcaecb99eccc2237c3b863a2b9a5.tar.gz |
Add function to calculate associated object id
Diffstat (limited to 'test/pleroma')
-rw-r--r-- | test/pleroma/activity_test.exs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/test/pleroma/activity_test.exs b/test/pleroma/activity_test.exs index b5bb4bafe..e38384c9c 100644 --- a/test/pleroma/activity_test.exs +++ b/test/pleroma/activity_test.exs @@ -278,4 +278,78 @@ defmodule Pleroma.ActivityTest do assert Repo.aggregate(Activity, :count, :id) == 2 end + + describe "associated_object_id() sql function" do + test "with json object" do + %{rows: [[object_id]]} = + Ecto.Adapters.SQL.query!( + Pleroma.Repo, + """ + select associated_object_id('{"object": {"id":"foobar"}}'::jsonb); + """ + ) + + assert object_id == "foobar" + end + + test "with string object" do + %{rows: [[object_id]]} = + Ecto.Adapters.SQL.query!( + Pleroma.Repo, + """ + select associated_object_id('{"object": "foobar"}'::jsonb); + """ + ) + + assert object_id == "foobar" + end + + test "with array object" do + %{rows: [[object_id]]} = + Ecto.Adapters.SQL.query!( + Pleroma.Repo, + """ + select associated_object_id('{"object": ["foobar", {}]}'::jsonb); + """ + ) + + assert object_id == "foobar" + end + + test "invalid" do + %{rows: [[object_id]]} = + Ecto.Adapters.SQL.query!( + Pleroma.Repo, + """ + select associated_object_id('{"object": {}}'::jsonb); + """ + ) + + assert is_nil(object_id) + end + + test "invalid object id" do + %{rows: [[object_id]]} = + Ecto.Adapters.SQL.query!( + Pleroma.Repo, + """ + select associated_object_id('{"object": {"id": 123}}'::jsonb); + """ + ) + + assert is_nil(object_id) + end + + test "no object field" do + %{rows: [[object_id]]} = + Ecto.Adapters.SQL.query!( + Pleroma.Repo, + """ + select associated_object_id('{}'::jsonb); + """ + ) + + assert is_nil(object_id) + end + end end |