Improve query findFollowsByTarget & add tests
This commit is contained in:
@@ -7,17 +7,19 @@ declare
|
||||
_version_id1 uuid = uuid_generate_v4();
|
||||
first_article_id uuid := fixture_article(_citizen_id := _citizen_id, _version_id := _version_id1);
|
||||
first_article_updated_id uuid;
|
||||
_follow_count int = 0;
|
||||
begin
|
||||
perform follow('citizen'::regclass, _citizen_id, _citizen_id2);
|
||||
assert (select count(*) = 1 from follow), 'follow must be inserted';
|
||||
assert (select following = true from find_follow(_citizen_id, _citizen_id2, 'citizen')), 'find_follow must return the following';
|
||||
|
||||
perform follow('citizen'::regclass, _citizen_id, _citizen_id2);
|
||||
assert (select count(*) = 1 from follow), 'follow must be inserted';
|
||||
assert (select count(*) = 1 from follow), 're follow must be do nothing';
|
||||
|
||||
perform unfollow('citizen'::regclass, _citizen_id, _citizen_id2);
|
||||
assert (select count(*) = 0 from follow), 'follow must be deleted after unfollow';
|
||||
|
||||
|
||||
perform follow('article'::regclass, first_article_id, _citizen_id);
|
||||
assert (select following = true from find_follow(first_article_id, _citizen_id, 'article')), 'find_follow must return the following';
|
||||
assert (select following = false from find_follow(first_article_id, _citizen_id2, 'article')), 'find_follow must not return the following if not followinf';
|
||||
@@ -29,11 +31,17 @@ begin
|
||||
assert (select following = true from find_follow(first_article_id, _citizen_id, 'article')), '(v1) find_follow must return the following';
|
||||
assert (select following = true from find_follow(first_article_updated_id, _citizen_id, 'article')), '(v2) find_follow must return the following';
|
||||
|
||||
assert (select f.total = 1 from find_follows_article_by_target(first_article_id) as f), 'find_follows_article_by_target must return 1 follow';
|
||||
assert (select (f.resource#>>'{0, created_by, id}')::uuid = _citizen_id from find_follows_article_by_target(first_article_id) as f), 'find_follows_article_by_target must return follows with creator';
|
||||
assert (select count(*) = 1 from follow), 'must be only 1 follow';
|
||||
perform follow('citizen'::regclass, _citizen_id, _citizen_id2);
|
||||
assert (select count(*) = 2 from follow), 'follow citizen must be inserted';
|
||||
|
||||
assert (select json_array_length(f.resource) = 2 from find_follows_article_by_target(first_article_id) as f), 'find_follows_article_by_target must return 2 follows';
|
||||
assert (select (f.resource#>>'{0, created_by, id}')::uuid = _citizen_id from find_follows_article_by_target(first_article_id) as f), 'find_follows_article_by_target must return follows with creator';
|
||||
assert (select (f.resource#>>'{1, created_by, id}')::uuid = _citizen_id2 from find_follows_article_by_target(first_article_id) as f), 'find_follows_article_by_target must return follows with creator';
|
||||
|
||||
_follow_count = (select count(*) from follow);
|
||||
perform unfollow('article'::regclass, first_article_id, _citizen_id);
|
||||
assert (select count(*) = 0 from follow), 'follow must be deleted after unfollow, event if article is on other version';
|
||||
assert (select count(*) = _follow_count-1 from follow), 'follow must be deleted after unfollow, event if article is on other version';
|
||||
|
||||
rollback;
|
||||
raise notice 'follow test pass';
|
||||
|
||||
Reference in New Issue
Block a user