#55 Can be assign a role to members of my Workgroup

Remove Owner on Workgroup (use role MASTER instead)
"find_citizen_by_id" not return user anymore, use "find_citizen_by_id_with_user" instead
This commit is contained in:
2020-06-01 13:44:25 +02:00
parent 8ff6fcc970
commit 7874f5cec4
49 changed files with 331 additions and 217 deletions

View File

@@ -1,6 +1,7 @@
package feature
import fr.dcproject.entity.*
import fr.dcproject.entity.WorkgroupWithMembersI.Member
import fr.dcproject.utils.toUUID
import io.cucumber.datatable.DataTable
import io.cucumber.java8.En
@@ -16,7 +17,10 @@ class WorkgroupSteps : En, KoinTest {
init {
When("I have members in workgroup {string}:") { workgroupId: String, members: DataTable ->
val membersRefs = members.asList()
.map { CitizenRef(it.toUUID()) }
.map { Member(
citizen = CitizenRef(it.toUUID()),
roles = listOf(Member.Role.MASTER)
) }
get<WorkgroupRepository>().addMembers(WorkgroupRef(workgroupId.toUUID()), membersRefs)
}
@@ -42,16 +46,11 @@ class WorkgroupSteps : En, KoinTest {
}
}
val owner = data["owner"]?.let {
get<CitizenRepository>().findByUsername(it.toLowerCase().replace(' ', '-'))
} ?: creator
val workgroup = WorkgroupSimple<CitizenRef>(
id = UUID.fromString(data["id"] ?: UUID.randomUUID().toString()),
name = data["name"] ?: "Les Incoruptible",
description = data["description"] ?: "La vie est notre jeux",
createdBy = creator,
owner = owner,
anonymous = (data["anonymous"] ?: false) == true
)

View File

@@ -55,15 +55,15 @@ internal class WorkgroupVoterTest {
createdBy = tesla,
description = "Super desc",
name = "super name",
owner = tesla,
anonymous = false
anonymous = false,
members = listOf(WorkgroupWithMembersI.Member(tesla, listOf(WorkgroupWithMembersI.Member.Role.MASTER)))
)
private val workgroupAnon = WorkgroupEntity(
createdBy = tesla,
description = "Super desc",
name = "super name",
owner = tesla,
members = listOf(WorkgroupWithMembersI.Member(tesla, listOf(WorkgroupWithMembersI.Member.Role.MASTER))),
anonymous = true
)

View File

@@ -3,15 +3,21 @@ Feature: Workgroup
Scenario: Can get one workgroup
Given I have citizen Stephen Hawking
And I have citizen Sadi Carnot with ID "be3b0926-8628-4426-804a-75188a6eb315"
And I have citizen Joseph Fourier with ID "d9671eca-abaf-4b67-9230-3ece700c1ddb"
And I am authenticated as Stephen Hawking
And I have workgroup:
| id | ab469134-bf14-4856-b093-ae1aa990f977 |
| name | Les Mousquets |
And I have members in workgroup "ab469134-bf14-4856-b093-ae1aa990f977":
| be3b0926-8628-4426-804a-75188a6eb315 |
| d9671eca-abaf-4b67-9230-3ece700c1ddb |
When I send a GET request to "/workgroups/ab469134-bf14-4856-b093-ae1aa990f977"
Then the response status code should be 200
And the JSON should contain:
| id | ab469134-bf14-4856-b093-ae1aa990f977 |
| name | Les Mousquets |
And the response should contain object:
| $.id | ab469134-bf14-4856-b093-ae1aa990f977 |
| $.name | Les Mousquets |
| $.members[0].first_name | Sadi |
Scenario: Can create a workgroup
Given I have citizen Werner Heisenberg
@@ -58,14 +64,19 @@ Feature: Workgroup
And I have citizen Alessandro Volta with ID "b5bac515-45d4-4aeb-9b6d-2627a0bbc419"
And I am authenticated as Blaise Pascal
And I have workgroup:
| id | b0ea1922-3bc6-44e2-aa7c-40158998cfbb |
| name | Les bonobos |
| owner | Blaise Pascal |
| id | b0ea1922-3bc6-44e2-aa7c-40158998cfbb |
| name | Les bonobos |
When I send a POST request to "/workgroups/b0ea1922-3bc6-44e2-aa7c-40158998cfbb/members" with body:
"""
[
{"id":"6d883fe7-5fc0-4a50-8858-72230673eba4"},
{"id":"b5bac515-45d4-4aeb-9b6d-2627a0bbc419"}
{
"id":"6d883fe7-5fc0-4a50-8858-72230673eba4",
"roles": ["MASTER"]
},
{
"id":"b5bac515-45d4-4aeb-9b6d-2627a0bbc419",
"roles": ["MASTER"]
}
]
"""
Then the response status code should be 201
@@ -76,21 +87,23 @@ Feature: Workgroup
And I have citizen Paul Dirac with ID "1baf48bb-02bc-4d8f-ac86-33335354f5e7"
And I am authenticated as Heinrich Hertz
And I have workgroup:
| id | b6c975df-dd44-4e99-adc1-f605746b0e11 |
| name | Les Tacos |
| owner | Heinrich Hertz |
| id | b6c975df-dd44-4e99-adc1-f605746b0e11 |
| name | Les Tacos |
And I have members in workgroup "b6c975df-dd44-4e99-adc1-f605746b0e11":
| 87909ba3-2069-431c-9924-219fd8411cf2 |
| 1baf48bb-02bc-4d8f-ac86-33335354f5e7 |
When I send a DELETE request to "/workgroups/b6c975df-dd44-4e99-adc1-f605746b0e11/members" with body:
"""
[
{"id":"87909ba3-2069-431c-9924-219fd8411cf2"}
{
"id":"87909ba3-2069-431c-9924-219fd8411cf2",
"roles": ["MASTER"]
}
]
"""
Then the response status code should be 200
And the response should contain object:
| $.[0]id | 1baf48bb-02bc-4d8f-ac86-33335354f5e7 |
| $.[0]citizen.id | 1baf48bb-02bc-4d8f-ac86-33335354f5e7 |
And the JSON should have 1 items
Scenario: Can update members on workgroup
@@ -100,21 +113,26 @@ Feature: Workgroup
And I have citizen Georg Ohm with ID "b49e20c1-8393-45d6-a6a0-3fa5c71cbdc1"
And I am authenticated as Leon Foucault
And I have workgroup:
| id | 784fe6bc-7635-4ae2-b080-3a4743b998bf |
| name | Les Tacos |
| owner | Leon Foucault |
| id | 784fe6bc-7635-4ae2-b080-3a4743b998bf |
| name | Les Tacos |
And I have members in workgroup "784fe6bc-7635-4ae2-b080-3a4743b998bf":
| be3b0926-8628-4426-804a-75188a6eb315 |
| d9671eca-abaf-4b67-9230-3ece700c1ddb |
When I send a PUT request to "/workgroups/784fe6bc-7635-4ae2-b080-3a4743b998bf/members" with body:
"""
[
{"id":"be3b0926-8628-4426-804a-75188a6eb315"},
{"id":"b49e20c1-8393-45d6-a6a0-3fa5c71cbdc1"}
{
"id":"be3b0926-8628-4426-804a-75188a6eb315",
"roles": ["MASTER"]
},
{
"id":"b49e20c1-8393-45d6-a6a0-3fa5c71cbdc1",
"roles": ["MASTER"]
}
]
"""
Then the response status code should be 200
And the response should contain object:
| $.[0]id | be3b0926-8628-4426-804a-75188a6eb315 |
| $.[1]id | b49e20c1-8393-45d6-a6a0-3fa5c71cbdc1 |
| $.[0]citizen.id | be3b0926-8628-4426-804a-75188a6eb315 |
| $.[1]citizen.id | b49e20c1-8393-45d6-a6a0-3fa5c71cbdc1 |
And the JSON should have 2 items

View File

@@ -19,7 +19,6 @@ begin
end if;
created_workgroup := jsonb_set(created_workgroup::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
created_workgroup := jsonb_set(created_workgroup::jsonb, '{owner}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
assert created_workgroup#>>'{created_by, id}' = _citizen_id::text, format('citizenId in workgroup must be the same as citizen, %s != %s', created_workgroup#>>'{created_by, id}', _citizen_id::text);
-- upsert workgroup

View File

@@ -16,9 +16,9 @@ declare
}';
selected_workgroup json;
members json;
selected_citizen json;
begin
created_workgroup := jsonb_set(created_workgroup::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
created_workgroup := jsonb_set(created_workgroup::jsonb, '{owner}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
assert created_workgroup#>>'{created_by, id}' = _citizen_id::text, format('citizenId in workgroup must be the same as citizen, %s != %s', created_workgroup#>>'{created_by, id}', _citizen_id::text);
-- upsert workgroup
@@ -28,7 +28,6 @@ begin
-- insert another workgroup
created_workgroup_2 := jsonb_set(created_workgroup_2::jsonb, '{created_by}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
created_workgroup_2 := jsonb_set(created_workgroup_2::jsonb, '{owner}'::text[], jsonb_build_object('id', _citizen_id::text), true)::json;
assert created_workgroup_2#>>'{created_by, id}' = _citizen_id::text, format('citizenId in workgroup must be the same as citizen, %s != %s', created_workgroup_2#>>'{created_by, id}', _citizen_id::text);
select upsert_workgroup(created_workgroup_2) into created_workgroup_2;
@@ -47,44 +46,61 @@ begin
-- add
select m into members from add_workgroup_members((created_workgroup->>'id')::uuid, json_build_array(
json_build_object('id', _citizen_id2),
json_build_object('id', _citizen_id3)
json_build_object('citizen', json_build_object('id', _citizen_id2), 'roles', '{MASTER}'::text[]),
json_build_object('citizen', json_build_object('id', _citizen_id3), 'roles', '{MASTER}'::text[])
)) m;
assert json_array_length(members) = 2, 'The members count must be equal to 2';
assert members::jsonb @> jsonb_build_array(jsonb_build_object('id', _citizen_id3)),
assert (members::jsonb) @> jsonb_build_array(jsonb_build_object(
'id', (created_workgroup->>'id'),
'citizen', jsonb_build_object('id', _citizen_id3),
'roles', jsonb_build_array('MASTER')
)),
'Members must contain citizen3';
-- Check if "find_citizen_by_id" retrun workgroups of citizen
assert (select find_citizen_by_id(_citizen_id2)#>>'{workgroups, 0, id}') = (created_workgroup->>'id'), 'find_citizen_by_id must return workgroups';
-- Check if "find_citizen_by_id" retrun citizen
assert (select find_citizen_by_id(_citizen_id2)#>>'{id}')::uuid = _citizen_id2, 'find_citizen_by_id must return citizen';
-- Check if "find_citizen_by_id_with_user_and_workgroups" retrun workgroups of citizen
select find_citizen_by_id_with_user_and_workgroups(_citizen_id3) into selected_citizen;
assert selected_citizen#>>'{workgroups, 0, roles, 0}' = 'MASTER', format('workgroup must have MASTER role, %s', selected_citizen#>>'{workgroups, 0, roles, 0}');
-- update
select m into members from update_workgroup_members((created_workgroup->>'id')::uuid, json_build_array(
json_build_object('id', _citizen_id2),
json_build_object('id', _citizen_id)
json_build_object('citizen', json_build_object('id', _citizen_id2), 'roles', '{MASTER}'::text[]),
json_build_object('citizen', json_build_object('id', _citizen_id), 'roles', '{MASTER}'::text[])
)) m;
assert json_array_length(members) = 2, 'The members count must be equal to 2';
assert members::jsonb @> jsonb_build_array(jsonb_build_object('id', _citizen_id)),
'Members must contain citizen2';
assert not members::jsonb @> jsonb_build_array(jsonb_build_object('id', _citizen_id3)),
'Members must NOT contain citizen3';
assert (members::jsonb) @> jsonb_build_array(jsonb_build_object(
'id', (created_workgroup->>'id'),
'citizen', jsonb_build_object('id', _citizen_id),
'roles', jsonb_build_array('MASTER')
)), 'Members must contain citizen1';
assert not (members::jsonb) @> jsonb_build_array(jsonb_build_object(
'citizen', jsonb_build_object('id', _citizen_id3)
)), 'Members must NOT contain citizen3';
-- remove
select m into members from remove_workgroup_members((created_workgroup->>'id')::uuid, json_build_array(
json_build_object('id', _citizen_id2)
)) m;
select m into members from remove_workgroup_members((created_workgroup->>'id')::uuid, json_build_array(jsonb_build_object(
'citizen', json_build_object('id', _citizen_id2)
))) m;
assert json_array_length(members) = 1, 'The members count must be equal to 1';
assert members::jsonb @> jsonb_build_array(jsonb_build_object('id', _citizen_id)),
'Members must contain citizen1';
assert not members::jsonb @> jsonb_build_array(jsonb_build_object('id', _citizen_id2)),
'Members must NOT contain citizen2';
assert (members::jsonb) @> jsonb_build_array(jsonb_build_object(
'citizen', jsonb_build_object('id', _citizen_id)
)), 'Members must contain citizen1';
assert not (members::jsonb) @> jsonb_build_array(jsonb_build_object(
'citizen', jsonb_build_object('id', _citizen_id2)
)), 'Members must NOT contain citizen2';
select m into members from find_workgroup_members((created_workgroup->>'id')::uuid) m;
assert json_array_length(members) = 1, 'The members count must be equal to 1';
assert members::jsonb @> jsonb_build_array(jsonb_build_object('id', _citizen_id)),
'Members must contain citizen1';
assert not members::jsonb @> jsonb_build_array(jsonb_build_object('id', _citizen_id2)),
'Members must NOT contain citizen2';
assert (members::jsonb) @> jsonb_build_array(jsonb_build_object(
'citizen', jsonb_build_object('id', _citizen_id)
)), 'Members must contain citizen1';
assert not (members::jsonb) @> jsonb_build_array(jsonb_build_object(
'citizen', jsonb_build_object('id', _citizen_id2)
)), 'Members must NOT contain citizen2';
-- Check if find_workgroup_by_id return members
select find_workgroup_by_id((created_workgroup->>'id')::uuid) into selected_workgroup;
assert json_array_length(selected_workgroup->'members') = 1, 'Workgroup must have members';