feature #4: add "article in title" on contitution creation

This commit is contained in:
2019-07-28 22:42:49 +02:00
parent a15847ab9e
commit ef740734b2
5 changed files with 108 additions and 12 deletions

View File

@@ -4,9 +4,42 @@ declare
created_user json := '{"username": "george", "plain_password": "azerty"}';
_user_id uuid;
_citizen_id uuid;
created_citizen json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01"}';
created_article json := '{"version_id":"933b6a1b-50c9-42b6-989f-c02a57814ef9", "title": "Love the world", "annonymous": false, "content": "bla bal bla", "tags": ["love", "test"]}';
created_constitution json := '{"version_id":"18ff6dd6-3bc1-4c59-82f0-5e2a8d54ae3e", "title": "Love the world", "annonymous": false, "titles": [{"name":"titleOne"},{"name":"titleTwo"}]}';
created_citizen json := $json$
{
"name": {
"first_name": "George",
"last_name": "MICHEL"
},
"birthday": "2001-01-01"
}
$json$;
created_article json := $json$
{
"version_id": "933b6a1b-50c9-42b6-989f-c02a57814ef9",
"title": "Love the world",
"annonymous": false,
"content": "bla bal bla",
"tags": [
"love",
"test"
]
}
$json$;
created_constitution json := $json$
{
"version_id": "18ff6dd6-3bc1-4c59-82f0-5e2a8d54ae3e",
"title": "Love the world",
"annonymous": false,
"titles": [
{
"name": "titleOne"
},
{
"name": "titleTwo"
}
]
}
$json$;
begin
-- insert user for context
call insert_user(created_user);
@@ -27,11 +60,13 @@ begin
-- 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, '{titles, 0, articles}'::text[], jsonb_build_array(jsonb_build_object('id', created_article->>'id')), true)::json;
call upsert_constitution(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#>>'{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}');
-- delete article and context
delete from article_in_title;
delete from title;
delete from constitution;
delete from article;