add default true for active flag in role while create invitation

This commit is contained in:
ggmaleva 2021-04-13 15:02:14 +03:00
parent bb3b646e3d
commit b4caa6c2d3
No known key found for this signature in database
GPG Key ID: 0E412B78565B108F
3 changed files with 35 additions and 8 deletions

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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<String> actualRoles = organizationMembership.getMember().getRoles().stream()
.map(MemberRole::getRoleId)
.map(RoleId::getValue)
.collect(Collectors.toList());
List<String> 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() {