Fix SQL tests

This commit is contained in:
2019-08-23 17:08:19 +02:00
parent 36be09eed2
commit d5499576ed
7 changed files with 27 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
do do
$$ $$
declare declare
created_user json := '{"username": "george", "plain_password": "azerty"}'; created_user json := '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
_user_id uuid; _user_id uuid;
_citizen_id uuid; _citizen_id uuid;
created_citizen json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01"}'; created_citizen json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01"}';
@@ -15,17 +15,17 @@ begin
assert created_citizen#>>'{user, id}' = _user_id::text, format('userId in citizen must be the same as user, %s = %s', created_citizen#>>'{user, id}', _user_id::text); assert created_citizen#>>'{user, id}' = _user_id::text, format('userId in citizen must be the same as user, %s = %s', created_citizen#>>'{user, id}', _user_id::text);
-- insert new citizen for context -- insert new citizen for context
call upsert_citizen(created_citizen); select upsert_citizen(created_citizen) into created_citizen;
_citizen_id := created_citizen->>'id'; _citizen_id := created_citizen->>'id';
created_article := jsonb_set(created_article::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json; created_article := jsonb_set(created_article::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
assert created_article#>>'{created_by, id}' = _citizen_id::text, format('citizenId in article must be the same as citizen, %s != %s', created_article#>>'{created_by, id}', _citizen_id::text); assert created_article#>>'{created_by, id}' = _citizen_id::text, format('citizenId in article must be the same as citizen, %s != %s', created_article#>>'{created_by, id}', _citizen_id::text);
-- upsert article -- upsert article
call upsert_article(created_article); select upsert_article(created_article) into created_article;
assert created_article->>'version_id' is not null, 'version_id should not be null'; assert created_article->>'version_id' is not null, 'version_id should not be null';
assert (created_article->>'version_number')::int = 1, format('version_number must be equal to 1, %s instead', created_article->>'version_number'); assert (created_article->>'version_number')::int = 1, format('version_number must be equal to 1, %s instead', created_article->>'version_number');
-- try tu create new version -- try tu create new version
call upsert_article(created_article); select upsert_article(created_article) into created_article;
assert (created_article->>'version_number')::int = 2, format('version_number must be equal to 2, %s instead', created_article->>'version_number'); assert (created_article->>'version_number')::int = 2, format('version_number must be equal to 2, %s instead', created_article->>'version_number');
-- get article by id and check the title -- get article by id and check the title
@@ -36,8 +36,8 @@ begin
select find_last_article_by_version_id((created_article->>'version_id')::uuid) into selected_article; select find_last_article_by_version_id((created_article->>'version_id')::uuid) into selected_article;
assert selected_article->>'title' = 'Love the world', format('title must be "Love the world", %s', selected_article->>'title'); assert selected_article->>'title' = 'Love the world', format('title must be "Love the world", %s', selected_article->>'title');
assert (selected_article->>'version_number')::int = 2, format('version_id must be 2, %s instead', selected_article->>'version_number'); assert (selected_article->>'version_number')::int = 2, format('version_id must be 2, %s instead', selected_article->>'version_number');
-- check if user id is returned -- -- check if user id is returned
assert (selected_article#>>'{created_by, user, id}')::uuid = _user_id, format('user_id must be %s instead of %s', _user_id, (selected_article#>>'{created_by, user, id}')::uuid); -- assert (selected_article#>>'{created_by, user, id}')::uuid = _user_id, format('user_id must be %s instead of %s', _user_id, (selected_article#>>'{created_by, user, id}')::uuid);
-- delete article and context -- delete article and context
delete from article; delete from article;

View File

@@ -2,7 +2,7 @@ do
$$ $$
declare declare
wrong_citizen json; wrong_citizen json;
created_user json := '{"username": "george", "plain_password": "azerty"}'; created_user json := '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
_user_id uuid; _user_id uuid;
created_citizen json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01"}'; created_citizen json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01"}';
selected_citizen json; selected_citizen json;
@@ -14,13 +14,13 @@ begin
assert created_citizen#>>'{user, id}' = _user_id::text, format('userId in citizen must be the same as user, %s = %s', created_citizen#>>'{user, id}', _user_id::text); assert created_citizen#>>'{user, id}' = _user_id::text, format('userId in citizen must be the same as user, %s = %s', created_citizen#>>'{user, id}', _user_id::text);
-- insert new citizen -- insert new citizen
call upsert_citizen(created_citizen); select upsert_citizen(created_citizen) into created_citizen;
assert created_citizen->>'birthday' = '2001-01-01'::text, format('birthday of inserted citizen must be the same of the original object, %s != %s', created_citizen->>'birthday', '2001-01-01'::text); assert created_citizen->>'birthday' = '2001-01-01'::text, format('birthday of inserted citizen must be the same of the original object, %s != %s', created_citizen->>'birthday', '2001-01-01'::text);
-- insert citizen without first name and test if throw exception -- insert citizen without first name and test if throw exception
wrong_citizen := (created_citizen::jsonb - '{name, first_name}'::text[])::json; wrong_citizen := (created_citizen::jsonb - '{name, first_name}'::text[])::json;
begin begin
call upsert_citizen(wrong_citizen); select upsert_citizen(wrong_citizen) into wrong_citizen;
assert false, 'upsert_citizen must be throw exception if first_name not exist'; assert false, 'upsert_citizen must be throw exception if first_name not exist';
exception when not_null_violation then exception when not_null_violation then
end; end;

View File

@@ -1,8 +1,8 @@
do do
$$ $$
declare declare
created_user json := '{"username": "george", "plain_password": "azerty"}'; created_user json := '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
created_user2 json := '{"username": "john", "plain_password": "qwerty"}'; created_user2 json := '{"username": "john", "plain_password": "qwerty", "roles": ["ROLE_USER"]}';
_citizen_id uuid; _citizen_id uuid;
created_citizen json := $json$ created_citizen json := $json$
{ {
@@ -33,12 +33,12 @@ begin
created_citizen := jsonb_set(created_citizen::jsonb, '{user}'::text[], jsonb_build_object('id', created_user->>'id'), true)::json; created_citizen := jsonb_set(created_citizen::jsonb, '{user}'::text[], jsonb_build_object('id', created_user->>'id'), true)::json;
-- insert new citizen for context -- insert new citizen for context
call upsert_citizen(created_citizen); select upsert_citizen(created_citizen) into created_citizen;
_citizen_id := created_citizen->>'id'; _citizen_id := created_citizen->>'id';
created_article := jsonb_set(created_article::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json; created_article := jsonb_set(created_article::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
assert created_article#>>'{created_by, id}' = _citizen_id::text, format('citizenId in article must be the same as citizen, %s != %s', created_article#>>'{created_by, id}', _citizen_id::text); assert created_article#>>'{created_by, id}' = _citizen_id::text, format('citizenId in article must be the same as citizen, %s != %s', created_article#>>'{created_by, id}', _citizen_id::text);
-- upsert article -- upsert article
call upsert_article(created_article); select upsert_article(created_article) into created_article;
select comment( select comment(

View File

@@ -1,7 +1,7 @@
do do
$$ $$
declare declare
created_user json := '{"username": "george", "plain_password": "azerty"}'; created_user json := '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
_user_id uuid; _user_id uuid;
_citizen_id uuid; _citizen_id uuid;
created_citizen json := $json$ created_citizen json := $json$
@@ -43,25 +43,27 @@ declare
begin begin
-- insert user for context -- insert user for context
select insert_user(created_user) into created_user; select insert_user(created_user) into created_user;
raise notice '%', created_user;
_user_id := created_user->>'id'; _user_id := created_user->>'id';
raise notice '%', _user_id;
created_citizen := jsonb_set(created_citizen::jsonb, '{user}'::text[], jsonb_build_object('id', _user_id::text), true)::json; created_citizen := jsonb_set(created_citizen::jsonb, '{user}'::text[], jsonb_build_object('id', _user_id::text), true)::json;
assert created_citizen#>>'{user, id}' = _user_id::text, format('userId in citizen must be the same as user, %s = %s', created_citizen#>>'{user, id}', _user_id::text); assert created_citizen#>>'{user, id}' = _user_id::text, format('userId in citizen must be the same as user, %s = %s', created_citizen#>>'{user, id}', _user_id::text);
-- insert new citizen for context -- insert new citizen for context
call upsert_citizen(created_citizen); select upsert_citizen(created_citizen) into created_citizen;
_citizen_id := created_citizen->>'id'; _citizen_id := created_citizen->>'id';
created_article := jsonb_set(created_article::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json; created_article := jsonb_set(created_article::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
assert created_article#>>'{created_by, id}' = _citizen_id::text, format('citizenId in article must be the same as citizen, %s != %s', created_article#>>'{created_by, id}', _citizen_id::text); assert created_article#>>'{created_by, id}' = _citizen_id::text, format('citizenId in article must be the same as citizen, %s != %s', created_article#>>'{created_by, id}', _citizen_id::text);
-- upsert article for context -- upsert article for context
call upsert_article(created_article); select upsert_article(created_article) into created_article;
assert created_article->>'version_id' is not null, 'version_id should not be null'; assert created_article->>'version_id' is not null, 'version_id should not be null';
-- create new constitution -- create new constitution
created_constitution := jsonb_set(created_constitution::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json; created_constitution := jsonb_set(created_constitution::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
created_constitution := jsonb_set(created_constitution::jsonb, '{titles, 0, articles}'::text[], jsonb_build_array(jsonb_build_object('id', created_article->>'id')), true)::json; created_constitution := jsonb_set(created_constitution::jsonb, '{titles, 0, articles}'::text[], jsonb_build_array(jsonb_build_object('id', created_article->>'id')), true)::json;
call upsert_constitution(created_constitution); select upsert_constitution(created_constitution) into created_constitution;
assert (created_constitution->>'version_number')::int = 1, format('version_number must be equal to 1, %s instead', created_constitution->>'version_number'); assert (created_constitution->>'version_number')::int = 1, format('version_number must be equal to 1, %s instead', created_constitution->>'version_number');
assert created_constitution#>>'{titles, 0, name}' = 'titleOne'::text, format('the name of the first title of contitution must be %s, not %s', 'titleOne', created_constitution#>>'{titles, 0, name}'); assert created_constitution#>>'{titles, 0, name}' = 'titleOne'::text, format('the name of the first title of contitution must be %s, not %s', 'titleOne', created_constitution#>>'{titles, 0, name}');

View File

@@ -1,8 +1,8 @@
do do
$$ $$
declare declare
created_user json := '{"username": "george", "plain_password": "azerty"}'; created_user json := '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
created_user2 json := '{"username": "john", "plain_password": "qwerty"}'; created_user2 json := '{"username": "john", "plain_password": "qwerty", "roles": ["ROLE_USER"]}';
_citizen_id uuid; _citizen_id uuid;
_citizen_id2 uuid; _citizen_id2 uuid;
created_citizen json := $json$ created_citizen json := $json$
@@ -31,10 +31,10 @@ begin
created_citizen2 := jsonb_set(created_citizen2::jsonb, '{user}'::text[], jsonb_build_object('id', created_user2->>'id'), true)::json; created_citizen2 := jsonb_set(created_citizen2::jsonb, '{user}'::text[], jsonb_build_object('id', created_user2->>'id'), true)::json;
-- insert new citizen for context -- insert new citizen for context
call upsert_citizen(created_citizen); select upsert_citizen(created_citizen) into created_citizen;
_citizen_id := created_citizen->>'id'; _citizen_id := created_citizen->>'id';
-- insert new citizen for context -- insert new citizen for context
call upsert_citizen(created_citizen2); select upsert_citizen(created_citizen2) into created_citizen2;
_citizen_id2 := created_citizen2->>'id'; _citizen_id2 := created_citizen2->>'id';

View File

@@ -1,7 +1,7 @@
do do
$$ $$
declare declare
created_user json := '{"username": "george", "plain_password": "azerty"}'; created_user json := '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
selected_user json; selected_user json;
exist_user json; exist_user json;
begin begin

View File

@@ -1,7 +1,7 @@
do do
$$ $$
declare declare
created_user json := '{"username": "george", "plain_password": "azerty"}'; created_user json := '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}';
_citizen_id uuid; _citizen_id uuid;
created_citizen json := $json$ created_citizen json := $json$
{ {
@@ -30,12 +30,12 @@ begin
created_citizen := jsonb_set(created_citizen::jsonb, '{user}'::text[], jsonb_build_object('id', created_user->>'id'), true)::json; created_citizen := jsonb_set(created_citizen::jsonb, '{user}'::text[], jsonb_build_object('id', created_user->>'id'), true)::json;
-- insert new citizen for context -- insert new citizen for context
call upsert_citizen(created_citizen); select upsert_citizen(created_citizen) into created_citizen;
_citizen_id := created_citizen->>'id'; _citizen_id := created_citizen->>'id';
created_article := jsonb_set(created_article::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json; created_article := jsonb_set(created_article::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
assert created_article#>>'{created_by, id}' = _citizen_id::text, format('citizenId in article must be the same as citizen, %s != %s', created_article#>>'{created_by, id}', _citizen_id::text); assert created_article#>>'{created_by, id}' = _citizen_id::text, format('citizenId in article must be the same as citizen, %s != %s', created_article#>>'{created_by, id}', _citizen_id::text);
-- upsert article -- upsert article
call upsert_article(created_article); select upsert_article(created_article) into created_article;
perform vote( perform vote(