#57 I can filter articles by workgroup
update lib "postgres-json:1.2.1"
This commit is contained in:
@@ -31,6 +31,10 @@ class ArticleSteps : En, KoinTest {
|
||||
createArticle(id = UUID.fromString(id))
|
||||
}
|
||||
|
||||
Given("I have article created by workgroup ID {string}") { id: String ->
|
||||
createArticle(workgroup = WorkgroupRef(UUID.fromString(id)))
|
||||
}
|
||||
|
||||
Given("I have comment created by {word} {word} on article {string}:") { firstName: String, lastName: String, articleId: String, extraData: DataTable? ->
|
||||
commentArticle(articleId, firstName, lastName, extraData)
|
||||
}
|
||||
@@ -39,7 +43,7 @@ class ArticleSteps : En, KoinTest {
|
||||
}
|
||||
}
|
||||
|
||||
private fun createArticle(extraData: DataTable? = null, id: UUID? = null) {
|
||||
private fun createArticle(extraData: DataTable? = null, id: UUID? = null, workgroup: WorkgroupRef? = null) {
|
||||
val params = extraData?.asMap<String, String>(String::class.java, String::class.java)
|
||||
val createdByUsername = params?.get("createdBy")
|
||||
val username = (createdByUsername ?: "username" + UUID.randomUUID().toString())
|
||||
@@ -63,12 +67,13 @@ class ArticleSteps : En, KoinTest {
|
||||
}
|
||||
}
|
||||
|
||||
val article = ArticleEntity(
|
||||
id = id ?: params?.get("id")?.toUUID() ?: UUID.randomUUID(),
|
||||
val article = ArticleForUpdate(
|
||||
id = id ?: params?.get("id")?.toUUID(),
|
||||
title = "hello",
|
||||
content = "bla bla bla",
|
||||
description = "A super article",
|
||||
createdBy = createdBy
|
||||
createdBy = createdBy,
|
||||
workgroup = workgroup
|
||||
)
|
||||
get<ArticleRepository>().upsert(article)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,18 @@ Feature: articles routes
|
||||
When I send a GET request to "/articles"
|
||||
Then the response status code should be 200
|
||||
|
||||
Scenario: Can get articles filtered by workgroup
|
||||
Given I have 3 article
|
||||
And I have workgroup:
|
||||
| id | 2bccd5a7-9082-4b31-88f8-e25d70b22b12 |
|
||||
| name | Les papy |
|
||||
And I have article created by workgroup ID "2bccd5a7-9082-4b31-88f8-e25d70b22b12"
|
||||
When I send a GET request to "/articles?workgroup=2bccd5a7-9082-4b31-88f8-e25d70b22b12"
|
||||
Then the response status code should be 200
|
||||
And the JSON should contain:
|
||||
| total | 1 |
|
||||
| result[0]workgroup.name | Les papy |
|
||||
|
||||
Scenario: Can get versions of article by the id
|
||||
Given I have article
|
||||
| id | 13e6091c-8fed-4600-b079-a97a6b7a9800 |
|
||||
|
||||
@@ -2,7 +2,9 @@ do
|
||||
$$
|
||||
declare
|
||||
_citizen_id uuid := fixture_citizen();
|
||||
_workgroup_id uuid := fixture_workgroup(_citizen_id => _citizen_id);
|
||||
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}';
|
||||
created_article_grouped json := '{"version_id":"35f5c4c3-0629-4405-9956-12557020c9f5", "title": "Love my group", "anonymous": false, "content": "groupy groupy", "tags": ["love", "group"], "draft":false}';
|
||||
created_article_v2 json;
|
||||
first_article_id uuid;
|
||||
second_article_id uuid;
|
||||
@@ -25,12 +27,21 @@ begin
|
||||
assert (created_article_v2->>'last_version')::bool = true, 'The second insert must be set to the last version';
|
||||
second_article_id = (created_article_v2->>'id')::uuid;
|
||||
|
||||
created_article_grouped := jsonb_set(created_article_grouped::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
|
||||
created_article_grouped := jsonb_set(created_article_grouped::jsonb, '{workgroup}'::text[], jsonb_build_object('id', _workgroup_id::text), true)::json;
|
||||
select upsert_article(created_article_grouped) into created_article_grouped;
|
||||
|
||||
-- get articles versions by version_id
|
||||
select resource, total into selected_article, selected_total from find_articles_versions_by_version_id((created_article->>'version_id')::uuid);
|
||||
assert selected_article#>>'{0,title}' = 'Love the world', format('title must be "Love the world", %s', selected_article#>>'{0,title}');
|
||||
assert (selected_article#>>'{0,version_number}')::int = 2, format('version_id must be 2, %s instead', selected_article#>>'{0,version_number}');
|
||||
assert selected_total = 2, format('the total must be 2, %s instead', selected_total);
|
||||
|
||||
-- get articles by workgroup id
|
||||
select resource, total into selected_article, selected_total from find_articles(_filter => json_build_object('workgroup_id', _workgroup_id));
|
||||
assert selected_article#>>'{0,title}' = 'Love my group', format('title must be "Love my group", %s', selected_article#>>'{0,title}');
|
||||
assert selected_total = 1, format('the total must be 1, %s instead', selected_total);
|
||||
|
||||
-- get articles versions by id
|
||||
select resource, total into selected_article, selected_total from find_articles_versions_by_id((created_article->>'id')::uuid);
|
||||
assert selected_article#>>'{0,title}' = 'Love the world', format('title must be "Love the world", %s', selected_article#>>'{0,title}');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
create or replace function fixture_workgroup(in name text default 'vert', _citizen_id uuid default fixture_citizen(), out _article_id uuid)
|
||||
create or replace function fixture_workgroup(in name text default 'vert', _citizen_id uuid default fixture_citizen(), out _workgroup_id uuid)
|
||||
language plpgsql as
|
||||
$$
|
||||
declare
|
||||
@@ -23,6 +23,7 @@ begin
|
||||
|
||||
-- upsert workgroup
|
||||
select upsert_workgroup(created_workgroup) into created_workgroup;
|
||||
select (created_workgroup->>'id')::uuid into _workgroup_id;
|
||||
assert created_workgroup->>'description' is not null, 'description should not be null';
|
||||
end;
|
||||
$$;
|
||||
|
||||
Reference in New Issue
Block a user