+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations/Test_Opinions.xml b/.idea/runConfigurations/Test_Opinions.xml
new file mode 100644
index 0000000..a6bb955
--- /dev/null
+++ b/.idea/runConfigurations/Test_Opinions.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/sql/functions/follow/find_follow.sql b/src/main/resources/sql/functions/follow/find_follow.sql
new file mode 100644
index 0000000..412bb69
--- /dev/null
+++ b/src/main/resources/sql/functions/follow/find_follow.sql
@@ -0,0 +1,25 @@
+create or replace function find_follow(
+ _target_id uuid,
+ _citizen_id uuid,
+ out resource json,
+ out following boolean
+) language plpgsql as
+$$
+begin
+ select to_json(t)
+ into resource
+ from (
+ select
+ f.*,
+ json_build_object('id', f.target_id, 'reference', f.target_reference) as target,
+ find_citizen_by_id(f.created_by_id) as created_by
+ from follow as f
+ where f.created_by_id = _citizen_id
+ and f.target_id = _target_id
+ ) as t;
+
+ select resource is not null into following;
+end;
+$$;
+
+-- drop function if exists find_follow(uuid, uuid);
diff --git a/src/test/sql/follow.sql b/src/test/sql/follow.sql
index e432d41..ca364ab 100644
--- a/src/test/sql/follow.sql
+++ b/src/test/sql/follow.sql
@@ -25,6 +25,9 @@ declare
"email":"george.michel2@gmail.com"
}
$json$;
+
+ created_article json := '{"version_id":"933b6a1b-50c9-42b6-989f-c02a57814ef9", "title": "Love the world", "anonymous": false, "content": "bla bal bla", "tags": ["love", "test"], "draft":false}';
+ first_article_id uuid;
begin
-- insert user for context
select insert_user(created_user) into created_user;
@@ -41,15 +44,27 @@ begin
perform follow('citizen'::regclass, _citizen_id, _citizen_id2);
- assert (select count(*) > 0 from follow), 'follow must be inserted';
+ assert (select count(*) = 1 from follow), 'follow must be inserted';
+ assert (select following = true from find_follow(_citizen_id, _citizen_id2)), 'find_follow must return the following';
perform follow('citizen'::regclass, _citizen_id, _citizen_id2);
- assert (select count(*) > 0 from follow), 'follow must be inserted';
+ assert (select count(*) = 1 from follow), 'follow must be inserted';
perform unfollow('citizen'::regclass, _citizen_id, _citizen_id2);
assert (select count(*) = 0 from follow), 'follow must be deleted after unfollow';
+ -- upsert article
+ created_article := jsonb_set(created_article::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
+ select upsert_article(created_article) into created_article;
+ first_article_id = (created_article->>'id')::uuid;
+
+ perform follow('article'::regclass, first_article_id, _citizen_id);
+ assert (select following = true from find_follow(first_article_id, _citizen_id)), 'find_follow must return the following';
+ assert (select following = false from find_follow(first_article_id, _citizen_id2)), 'find_follow must not return the following if not followinf';
+
-- delete follow and context
+ delete from follow;
+ delete from article;
delete from citizen;
delete from "user";