Commit 4a274961 authored by Raigo Ukkivi's avatar Raigo Ukkivi
Browse files

TEIS-365. Integration tests.

parent e149b8ba
package ee.sm.ti.teis.officials.group.listener;
import ee.sm.ti.teis.OfficialsAppTestBase;
import ee.sm.ti.teis.officegateway.official.AddOfficialsGroupMembersRequest;
import ee.sm.ti.teis.officegateway.official.AddOfficialsGroupMembersResponse;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserDto;
import ee.sm.ti.teis.officegateway.official.dto.OfficialsGroupDto;
import ee.sm.ti.teis.officegateway.official.request.CreateOfficialsGroupRequest;
......@@ -23,13 +25,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import javax.transaction.Transactional;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
import static ee.sm.ti.teis.types.enums.ObjectStatus.DELETED;
import static java.util.Set.of;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.HttpStatus.NOT_FOUND;
@SuppressWarnings("squid:S00100")
@Transactional
......@@ -39,6 +41,8 @@ class OfficialsGroupGwListenerTest extends OfficialsAppTestBase {
private static final UUID ADMIN_GROUP_ID = UUID.fromString("68b5b265-9427-457f-8f16-0bd5cf608714");
private static final UUID ADMIN_USER_ID = UUID.fromString("b5d59f3b-57af-4971-8110-51019e5e827d");
private static final UUID TEST_GROUP_ID = UUID.fromString("751f8528-64a5-4e0e-862a-549356014861");
private static final UUID TEST_USER1_ID = UUID.fromString("06fe678a-90a8-49a7-8362-1041d244ef90");
private static final UUID TEST_USER2_ID = UUID.fromString("f0cafdc3-ff43-4c73-8319-93f07a7d5a3c");
@Autowired
OfficialsGroupGwListener groupListener;
......@@ -124,8 +128,7 @@ class OfficialsGroupGwListenerTest extends OfficialsAppTestBase {
OfficialsGroupResponse response = groupListener.findOfficialsGroup(request);
assertThat(response.getError().getCode()).isEqualTo("404");
assertThat(response.getError().getHttpResponse()).isEqualTo(NOT_FOUND);
assertThat(response.getError().getHttpResponse()).isEqualTo(HttpStatus.NOT_FOUND);
}
@Test
......@@ -255,6 +258,30 @@ class OfficialsGroupGwListenerTest extends OfficialsAppTestBase {
assertThat(groupRepo.findById(ADMIN_GROUP_ID).get().getOfficialsGroupManagerId()).isNull();
}
@Test
void addOfficialsGroupMembers_test() {
assertThat(usersRepo.findById(TEST_USER1_ID).get().getOfficialsGroup().getId()).isNotEqualTo(TEST_GROUP_ID);
assertThat(usersRepo.findById(TEST_USER2_ID).get().getOfficialsGroup().getId()).isNotEqualTo(TEST_GROUP_ID);
groupListener.addOfficialsGroupMembers(composeAddMemberRequest(TEST_GROUP_ID.toString(), List.of(TEST_USER1_ID.toString(), TEST_USER2_ID.toString())));
assertThat(usersRepo.findById(TEST_USER1_ID).get().getOfficialsGroup().getId()).isEqualTo(TEST_GROUP_ID);
assertThat(usersRepo.findById(TEST_USER2_ID).get().getOfficialsGroup().getId()).isEqualTo(TEST_GROUP_ID);
}
@Test
void addOfficialsGroupMembers_validates_members() {
AddOfficialsGroupMembersResponse response = groupListener
.addOfficialsGroupMembers(composeAddMemberRequest(TEST_GROUP_ID.toString(), null));
assertThat(response.getError().getHttpResponse()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(response.getError().getViolations().get(0).getFieldName()).isEqualTo("memberIds");
response = groupListener.addOfficialsGroupMembers(composeAddMemberRequest(TEST_GROUP_ID.toString(), List.of(UUID.randomUUID().toString())));
assertThat(response.getError().getHttpResponse()).isEqualTo(HttpStatus.NOT_FOUND);
}
@NotNull
private OfficialsGroupsRequest composeOfficialsGroupsRequest(String status) {
OfficialsGroupsRequest request = new OfficialsGroupsRequest();
......@@ -262,6 +289,13 @@ class OfficialsGroupGwListenerTest extends OfficialsAppTestBase {
return request;
}
@NotNull
private AddOfficialsGroupMembersRequest composeAddMemberRequest(String groupId, List<String> members) {
AddOfficialsGroupMembersRequest request = new AddOfficialsGroupMembersRequest();
request.setPayload(new AddOfficialsGroupMembersRequest.Parameters(groupId, members), REQUEST_META_DTO);
return request;
}
@NotNull
private CreateOfficialsGroupRequest composeCreateOfficialsGroupRequest(String name, UUID groupManagerId) {
CreateOfficialsGroupRequest request = new CreateOfficialsGroupRequest();
......
......@@ -87,7 +87,7 @@ public class OfficialsGroupGwListener {
@RabbitListener(queues = {GW_ADD_OFFICIALS_GROUP_MEMBERS_QUEUE})
@PreAuthorize("@accessController.hasOfficialPrivilege({T(ee.sm.ti.teis.types.enums.RolePrivilegeCode).TI_MANAGE_OFFICIALS_GROUPS})")
public AddOfficialsGroupMembersResponse createOfficialsGroup(AddOfficialsGroupMembersRequest request) {
public AddOfficialsGroupMembersResponse addOfficialsGroupMembers(AddOfficialsGroupMembersRequest request) {
final List<OfficialUserDto> groupMembers = service.addMembersToGroup(
request.getPayload().getGroupId(), request.getPayload().getMemberIds(), request.getRequestMetaDTO());
AddOfficialsGroupMembersResponse response = new AddOfficialsGroupMembersResponse();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment