From b4caa6c2d34a1b36c6ab8d5d55fc1604090135ae Mon Sep 17 00:00:00 2001 From: ggmaleva Date: Tue, 13 Apr 2021 15:02:14 +0300 Subject: [PATCH] add default true for active flag in role while create invitation --- .../converter/MemberRoleConverter.java | 1 + .../orgmanager/TestObjectFactory.java | 13 +++++---- .../OrganizationServiceIntegrationTest.java | 29 +++++++++++++++++-- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/rbkmoney/orgmanager/converter/MemberRoleConverter.java b/src/main/java/com/rbkmoney/orgmanager/converter/MemberRoleConverter.java index b0e80f7..fc95925 100644 --- a/src/main/java/com/rbkmoney/orgmanager/converter/MemberRoleConverter.java +++ b/src/main/java/com/rbkmoney/orgmanager/converter/MemberRoleConverter.java @@ -23,6 +23,7 @@ public class MemberRoleConverter { .resourceId(Objects.nonNull(scope) ? scope.getResourceId() : null) .roleId(role.getRoleId().toString()) .scopeId(Objects.nonNull(scope) ? scope.getId().toString() : null) + .active(Boolean.TRUE) .build(); } diff --git a/src/test/java/com/rbkmoney/orgmanager/TestObjectFactory.java b/src/test/java/com/rbkmoney/orgmanager/TestObjectFactory.java index 7501f4f..d1d5d77 100644 --- a/src/test/java/com/rbkmoney/orgmanager/TestObjectFactory.java +++ b/src/test/java/com/rbkmoney/orgmanager/TestObjectFactory.java @@ -98,12 +98,12 @@ public abstract class TestObjectFactory { } public static OrganizationEntity buildOrganization() { - return OrganizationEntity.builder() - .id(randomString()) - .createdAt(LocalDateTime.now()) - .name(randomString()) - .owner(randomString()) - .build(); + OrganizationEntity entity = new OrganizationEntity(); + entity.setId(randomString()); + entity.setCreatedAt(LocalDateTime.now()); + entity.setName(randomString()); + entity.setOwner(randomString()); + return entity; } public static OrganizationEntity buildOrganization(MemberEntity memberEntity) { @@ -156,6 +156,7 @@ public abstract class TestObjectFactory { .resourceId(randomString()) .scopeId(ResourceScopeId.SHOP.getValue()) .organizationId(orgId) + .active(true) .build(); } diff --git a/src/test/java/com/rbkmoney/orgmanager/service/OrganizationServiceIntegrationTest.java b/src/test/java/com/rbkmoney/orgmanager/service/OrganizationServiceIntegrationTest.java index 16d8d34..455a5f8 100644 --- a/src/test/java/com/rbkmoney/orgmanager/service/OrganizationServiceIntegrationTest.java +++ b/src/test/java/com/rbkmoney/orgmanager/service/OrganizationServiceIntegrationTest.java @@ -17,8 +17,7 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import static com.rbkmoney.orgmanager.TestObjectFactory.buildInvitation; -import static com.rbkmoney.orgmanager.TestObjectFactory.buildMemberRole; +import static com.rbkmoney.orgmanager.TestObjectFactory.*; import static java.util.stream.Collectors.toList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; @@ -92,6 +91,32 @@ public class OrganizationServiceIntegrationTest extends AbstractRepositoryTest { assertEquals(invitationEntity.getStatus(), InvitationStatusName.ACCEPTED.getValue()); } + @Test + @Transactional + void shouldJoinNewMember() { + String userId = TestObjectFactory.randomString(); + String email = TestObjectFactory.randomString(); + OrganizationEntity savedOrg = organizationRepository.save(buildOrganization()); + InvitationEntity savedInvitation = invitationRepository.save(buildInvitation(savedOrg.getId())); + + OrganizationMembership organizationMembership = organizationService + .joinOrganization(savedInvitation.getAcceptToken(), userId, email); + + assertEquals(savedOrg.getId(), organizationMembership.getOrg().getId()); + assertEquals(userId, organizationMembership.getMember().getId()); + List actualRoles = organizationMembership.getMember().getRoles().stream() + .map(MemberRole::getRoleId) + .map(RoleId::getValue) + .collect(Collectors.toList()); + List expectedRoles = savedInvitation.getInviteeRoles().stream() + .map(MemberRoleEntity::getRoleId) + .collect(Collectors.toList()); + assertIterableEquals(expectedRoles, actualRoles); + InvitationEntity invitationEntity = invitationRepository.findById(savedInvitation.getId()).get(); + assertEquals(invitationEntity.getStatus(), InvitationStatusName.ACCEPTED.getValue()); + assertTrue(memberRoleRepository.findAll().stream().allMatch(MemberRoleEntity::isActive)); + } + @Test @Transactional void shouldExpelOrgMember() {