Add script to launch SQL test

This commit is contained in:
2020-03-18 02:18:10 +01:00
parent 06684120ce
commit 64e3fb0134
70 changed files with 39 additions and 108 deletions

13
.idea/runConfigurations/SQL_Tests.xml generated Normal file
View File

@@ -0,0 +1,13 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="SQL Tests" type="ShConfigurationType">
<option name="INDEPENDENT_SCRIPT_PATH" value="false" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/src/test/test.sh" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/src/test" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="false" />
<option name="INTERPRETER_PATH" value="C:/Program Files/Git/git-bash.exe" />
<option name="INTERPRETER_OPTIONS" value="" />
<method v="2" />
</configuration>
</component>

View File

@@ -7,7 +7,7 @@ begin
delete from vote_for_constitution; delete from vote_for_constitution;
delete from vote_for_comment_on_article; delete from vote_for_comment_on_article;
delete from vote_for_comment_on_constitution; delete from vote_for_comment_on_constitution;
raise notice '%', article_count;
insert into vote_for_article (id, created_by_id, target_id, note, anonymous) insert into vote_for_article (id, created_by_id, target_id, note, anonymous)
select select
uuid_in(md5('vote_for_article'||row_number() over ())::cstring), uuid_in(md5('vote_for_article'||row_number() over ())::cstring),

View File

@@ -25,8 +25,6 @@ begin
join (select *, row_number() over () rn from article) a using (rn); join (select *, row_number() over () rn from article) a using (rn);
end loop; end loop;
raise notice '% opinion inserted', (select count(*) from opinion_on_article);
raise notice 'opinions fixtures done'; raise notice 'opinions fixtures done';
end; end;
$$; $$;

View File

@@ -18,4 +18,4 @@ begin
end; end;
$$; $$;
-- drop function if exists find_article_by_id(uuid, out json);

View File

@@ -60,6 +60,3 @@ begin
) as t; ) as t;
end; end;
$$; $$;
-- drop function if exists find_articles(text, json, text, text, int, int);
-- select find_article_by_id('d91aa0cd-61d6-83cc-41bb-8d5656e130f7');

View File

@@ -15,4 +15,4 @@ begin
end; end;
$$; $$;
-- drop function if exists find_articles_versions_by_id(uuid, int, int, out json);

View File

@@ -25,4 +25,4 @@ begin
end; end;
$$; $$;
-- drop function if exists find_articles_versions_by_version_id(uuid, int, int, out json);

View File

@@ -21,4 +21,3 @@ begin
end; end;
$$; $$;
-- drop function if exists find_last_article_by_version_id(uuid, inout json);

View File

@@ -64,4 +64,3 @@ begin
end; end;
$$; $$;
-- drop procedure if exists upsert_article(inout json);

View File

@@ -12,4 +12,3 @@ begin
end; end;
$$; $$;
-- drop function if exists find_citizen_by_email(text, out json);

View File

@@ -14,4 +14,3 @@ begin
end; end;
$$; $$;
-- drop function if exists find_citizen_by_id(uuid, inout json);

View File

@@ -14,4 +14,3 @@ begin
end; end;
$$; $$;
-- drop function if exists find_citizen_by_id_with_user(uuid, inout json);

View File

@@ -14,4 +14,3 @@ begin
end; end;
$$; $$;
-- drop function if exists find_citizen_by_user_id(uuid, inout json);

View File

@@ -15,4 +15,3 @@ begin
end; end;
$$; $$;
-- drop function if exists find_citizen_by_username(text, out json);

View File

@@ -41,4 +41,4 @@ begin
end; end;
$$; $$;
-- drop function if exists find_citizens(text, text, text, int, int);

View File

@@ -30,4 +30,3 @@ begin
end; end;
$$; $$;
-- drop function if exists create_citizen_with_user(inout json);

View File

@@ -27,4 +27,3 @@ begin
end; end;
$$; $$;
-- drop function if exists upsert_citizen(inout json);

View File

@@ -21,4 +21,3 @@ begin
end; end;
$$; $$;
-- drop function if exists comment(regclass, uuid, uuid, text, uuid);

View File

@@ -7,7 +7,3 @@ begin
where c.id = _id; where c.id = _id;
end; end;
$$; $$;
-- drop function if exists edit_comment(uuid, text);
-- select edit_comment('b0422e48-687f-bea7-b45f-b6b301246e97', 'plop4')

View File

@@ -18,4 +18,4 @@ begin
end; end;
$$; $$;
-- drop function if exists find_comment_by_id(uuid, out json);

View File

@@ -37,5 +37,3 @@ begin
) as t; ) as t;
end; end;
$$; $$;
-- drop function if exists find_comments_by_citizen(uuid, regclass, int, int);

View File

@@ -24,5 +24,3 @@ begin
) as t; ) as t;
end; end;
$$; $$;
-- drop function if exists find_comments_by_parent(uuid, int, int);

View File

@@ -34,4 +34,4 @@ begin
end; end;
$$; $$;
-- drop function if exists find_comments_by_target(uuid, int, int);

View File

@@ -29,4 +29,3 @@ begin
end; end;
$$; $$;
-- drop function if exists create_title_in_constitution(out json);

View File

@@ -16,4 +16,3 @@ begin
end; end;
$$; $$;
-- drop function if exists find_constitution_by_id(uuid, out json);

View File

@@ -21,4 +21,3 @@ begin
end; end;
$$; $$;
-- drop function if exists find_constitution_title_by_id(uuid, out json);

View File

@@ -16,5 +16,3 @@ begin
) as t; ) as t;
end; end;
$$; $$;
-- drop function if exists find_constitution_titles_by_id(uuid, out json);

View File

@@ -39,5 +39,3 @@ begin
) as t; ) as t;
end; end;
$$; $$;
-- drop function if exists find_constitutions(text, text, text, int, int);

View File

@@ -52,5 +52,3 @@ begin
select find_constitution_by_id(new_id) into resource; select find_constitution_by_id(new_id) into resource;
end; end;
$$; $$;
-- drop function if exists upsert_constitution(inout json);

View File

@@ -21,5 +21,3 @@ begin
select resource is not null into following; select resource is not null into following;
end; end;
$$; $$;
-- drop function if exists find_follow(uuid, uuid);

View File

@@ -22,5 +22,3 @@ begin
) as t; ) as t;
end; end;
$$; $$;
-- drop function if exists find_follows_article_by_citizen(uuid, int, int);

View File

@@ -30,8 +30,3 @@ begin
) as t; ) as t;
end end
$$; $$;
-- drop function if exists find_follows_article_by_target(uuid, int, int);
-- select * from find_follows_article_by_target('32518c76-5c58-3cd1-00cd-7f9d0bb872cd', 20, 0);
-- select * from find_follows_article_by_target('24a373f4-c321-4006-8d05-3c50f95a561b', 100, 0);
-- SELECT * FROM find_follows_article_by_target ("_target_id" := '24a373f4-c321-4006-8d05-3c50f95a561b'::uuid, "offset" := 0::int, "limit" := 300::int)

View File

@@ -23,4 +23,3 @@ begin
end; end;
$$; $$;
-- drop function if exists find_follows_by_citizen(uuid, int, int);

View File

@@ -23,4 +23,4 @@ begin
end; end;
$$; $$;
-- drop function if exists find_follows_constitution_by_citizen(uuid, int, int);

View File

@@ -20,4 +20,3 @@ begin
end; end;
$$; $$;
-- drop function if exists follow(regclass, uuid, uuid);

View File

@@ -37,4 +37,3 @@ begin
end; end;
$$; $$;
-- drop function if exists unfollow(regclass, uuid, uuid);

View File

@@ -23,7 +23,3 @@ begin
resource = resource::jsonb || jsonb_build_object('reference', _reference); resource = resource::jsonb || jsonb_build_object('reference', _reference);
end end
$$; $$;
-- drop function if exists find_reference_by_id(uuid, regclass, out json);
-- select find_reference_by_id('8944221c-3766-f952-7064-9f229c288049'::uuid, 'constitution'::regclass)

View File

@@ -21,7 +21,3 @@ begin
resource = coalesce(agg, empty); resource = coalesce(agg, empty);
end; end;
$$; $$;
-- drop function if exists count_opinion(uuid);
-- select * from count_opinion('d91aa0cd-61d6-83cc-41bb-8d5656e130f7');

View File

@@ -44,5 +44,3 @@ begin
) t; ) t;
end end
$$; $$;
-- select * from find_citizen_opinions('6434f4f9-f570-f22a-c134-8668350651ff', null, null, 2, 2);

View File

@@ -27,4 +27,4 @@ begin
end; end;
$$; $$;
-- drop function if exists find_citizen_votes_by_target_ids(uuid, uuid[], regclass);

View File

@@ -24,7 +24,3 @@ begin
) t; ) t;
end; end;
$$; $$;
-- drop function if exists find_citizen_votes_by_target_ids(uuid, uuid[], regclass);
-- select * from find_citizen_opinions_by_target_ids('045b6e9e-5a9e-d9b0-75d4-e51f0bc6cd21', '{32a18b25-507d-49d8-5168-7675fb6a7b8c, 429bfd8c-ebc2-09ac-227f-28bcdaa91d84, 550f4543-35a3-9910-e493-70d26b931473}')

View File

@@ -19,4 +19,4 @@ begin
end; end;
$$; $$;
-- drop function if exists find_opinion_by_id(uuid, out json);

View File

@@ -24,4 +24,4 @@ begin
end; end;
$$; $$;
-- drop function if exists find_opinion_by_opinion(json);

View File

@@ -9,7 +9,3 @@ begin
and (ol.id = _id); and (ol.id = _id);
end; end;
$$; $$;
-- drop function if exists find_opinion_choice_by_id();
-- select find_opinion_choice_by_id('8c6cb3cc-cac5-93ad-312e-6bd87d9916d9');

View File

@@ -18,7 +18,3 @@ begin
) t; ) t;
end; end;
$$; $$;
-- drop function if exists find_opinions();
-- select find_opinion_choices('{}');

View File

@@ -20,4 +20,3 @@ begin
end; end;
$$; $$;
-- drop function if exists upsert_opinion(json);

View File

@@ -17,4 +17,3 @@ begin
end; end;
$$; $$;
-- drop function if exists upsert_opinion_choice(json);

View File

@@ -9,4 +9,3 @@ begin
end; end;
$$; $$;
-- drop function if exists change_user_password(json);

View File

@@ -15,4 +15,3 @@ begin
end; end;
$$; $$;
-- drop function if exists check_user(text, text, out json);

View File

@@ -9,4 +9,3 @@ begin
end; end;
$$; $$;
-- drop function if exists find_user_by_id(uuid, out json);

View File

@@ -9,4 +9,3 @@ begin
end; end;
$$; $$;
-- drop function if exists find_user_by_username(text, out json);

View File

@@ -17,4 +17,3 @@ begin
end; end;
$$; $$;
-- drop function if exists insert_user(inout json);

View File

@@ -36,7 +36,3 @@ begin
jsonb_build_object('percent', percent); jsonb_build_object('percent', percent);
end; end;
$$; $$;
-- drop function if exists count_vote(uuid);
-- select * from count_vote('ced1563f-ecf5-4f11-8518-8aeceff3c13a');

View File

@@ -29,4 +29,4 @@ begin
end; end;
$$; $$;
-- drop function if exists find_citizen_votes_by_target_ids(uuid, uuid[], regclass);

View File

@@ -37,4 +37,4 @@ begin
end; end;
$$; $$;
-- drop function if exists find_votes_by_citizen(uuid, regclass, int, int);

View File

@@ -38,4 +38,3 @@ begin
end; end;
$$; $$;
-- drop function if exists vote(regclass,uuid,uuid,integer,boolean);

View File

@@ -14,4 +14,4 @@ begin
end; end;
$$; $$;
-- drop procedure if exists update_workgroup_members(in uuid, inout json);

View File

@@ -18,5 +18,5 @@ begin
end; end;
$$; $$;
-- drop function if exists find_workgroup_by_id(uuid, out json);
-- select * from find_workgroup_by_id('d011ad4c-fa1b-40a3-593b-7816479ff33b') -- select * from find_workgroup_by_id('d011ad4c-fa1b-40a3-593b-7816479ff33b')

View File

@@ -13,4 +13,4 @@ begin
end; end;
$$; $$;
-- drop function if exists find_workgroup_members(uuid, out json);

View File

@@ -54,6 +54,3 @@ begin
) as t; ) as t;
end; end;
$$; $$;
-- drop function if exists find_workgroups(text, json, text, text, int, int);
-- select * from find_workgroups('49', "limit" := 2)

View File

@@ -14,4 +14,3 @@ begin
end end
$$; $$;
-- drop procedure if exists remove_workgroup_members(in uuid, inout json);

View File

@@ -23,4 +23,3 @@ begin
end; end;
$$; $$;
-- drop procedure if exists update_workgroup_members(in uuid, inout json);

View File

@@ -31,4 +31,3 @@ begin
end; end;
$$; $$;
-- drop procedure if exists upsert_workgroup(inout json);

View File

@@ -30,6 +30,3 @@ begin
raise notice 'constitution test pass'; raise notice 'constitution test pass';
end end
$$; $$;
-- select uuid_generate_v4();

View File

@@ -24,4 +24,4 @@ begin
select (a->>'id')::uuid into _article_id from upsert_article(created_article) a; select (a->>'id')::uuid into _article_id from upsert_article(created_article) a;
end if; end if;
end; end;
$$ $$;

View File

@@ -21,4 +21,4 @@ begin
select upsert_citizen(created_citizen) into created_citizen; select upsert_citizen(created_citizen) into created_citizen;
_citizen_id := created_citizen->>'id'; _citizen_id := created_citizen->>'id';
end end
$$ $$;

View File

@@ -15,4 +15,4 @@ begin
select insert_user(created_user) into created_user; select insert_user(created_user) into created_user;
user_id := created_user->>'id'; user_id := created_user->>'id';
end end
$$ $$;

View File

@@ -26,4 +26,4 @@ begin
select upsert_workgroup(created_workgroup) into created_workgroup; select upsert_workgroup(created_workgroup) into created_workgroup;
assert created_workgroup->>'description' is not null, 'description should not be null'; assert created_workgroup->>'description' is not null, 'description should not be null';
end; end;
$$ $$;

View File

@@ -83,7 +83,6 @@ begin
assert(select (a#>>'{opinions, Opinion1}')::int = 1 assert(select (a#>>'{opinions, Opinion1}')::int = 1
from find_article_by_id((created_article->>'id')::uuid) a), 'the article must be have a opinion'; from find_article_by_id((created_article->>'id')::uuid) a), 'the article must be have a opinion';
raise notice '%', opinion2;
assert(select (opinion2#>>'{choice, id}')::uuid = opinion_choice2_id), 'opinion2 is not inserted'; assert(select (opinion2#>>'{choice, id}')::uuid = opinion_choice2_id), 'opinion2 is not inserted';
assert(select (opinion2#>>'{choice, name}') = 'Opinion2'), 'no name for opinion2'; assert(select (opinion2#>>'{choice, name}') = 'Opinion2'), 'no name for opinion2';

6
src/test/test.sh Normal file
View File

@@ -0,0 +1,6 @@
#bin/bash
echo "Start tests"
cat ../main/resources/sql/functions/*/*.sql ../main/resources/sql/migrations/*.sql ./sql/fixtures/*.sql ./sql/*.sql > ./allSQL.sql
docker exec -i postgresql_dc-project psql test test -q -b -v "ON_ERROR_STOP=1" < ./allSQL.sql
rm ./allSQL.sql
#sleep 20