fix review

This commit is contained in:
ggmaleva 2021-04-29 15:13:33 +03:00
parent 99163e5d65
commit 7ff8a0275b
No known key found for this signature in database
GPG Key ID: 0E412B78565B108F
2 changed files with 12 additions and 10 deletions

View File

@ -25,23 +25,23 @@ public class BouncerContextConverter {
.collect(Collectors.toSet()));
}
public Organization toOrganization(OrganizationEntity e,
public Organization toOrganization(OrganizationEntity entity,
Set<MemberRoleEntity> roles) {
return new Organization()
.setId(e.getId())
.setOwner(new Entity().setId(e.getOwner()))
.setId(entity.getId())
.setOwner(new Entity().setId(entity.getOwner()))
.setRoles(CollectionUtils.isEmpty(roles) ? null :
roles.stream()
.filter(memberRoleEntity -> memberRoleEntity.getOrganizationId().equals(e.getId()))
.filter(memberRoleEntity -> memberRoleEntity.getOrganizationId().equals(entity.getId()))
.map(this::toOrgRole)
.collect(Collectors.toSet()));
}
public OrgRole toOrgRole(MemberRoleEntity e) {
public OrgRole toOrgRole(MemberRoleEntity entity) {
return new OrgRole()
.setId(e.getRoleId())
.setId(entity.getRoleId())
.setScope(new OrgRoleScope()
.setShop(new Entity().setId(e.getResourceId())));
.setShop(new Entity().setId(entity.getResourceId())));
}
}

View File

@ -29,7 +29,6 @@ class BouncerContextConverterTest {
@Test
void shouldConvertToOrgRole() {
// Given
MemberRoleEntity entity = MemberRoleEntity.builder()
.id("id")
.roleId("Administrator")
@ -38,10 +37,8 @@ class BouncerContextConverterTest {
.organizationId("org")
.build();
// When
OrgRole role = converter.toOrgRole(entity);
// Then
OrgRole expected = new OrgRole()
.setId(RoleId.ADMINISTRATOR.getValue())
.setScope(new OrgRoleScope()
@ -55,7 +52,9 @@ class BouncerContextConverterTest {
OrganizationEntity organizationEntity = TestObjectFactory.buildOrganization();
MemberEntity memberEntity = TestObjectFactory.testMemberEntity(TestObjectFactory.randomString());
memberEntity.setOrganizations(Set.of(organizationEntity));
User user = converter.toUser(memberEntity);
assertEquals(memberEntity.getId(), user.getId());
assertEquals(memberEntity.getEmail(), user.getEmail());
assertEquals(memberEntity.getOrganizations().size(), user.getOrgs().size());
@ -66,6 +65,7 @@ class BouncerContextConverterTest {
OrganizationEntity organizationEntity = TestObjectFactory.buildOrganization();
var organization = converter.toOrganization(organizationEntity, Collections.emptySet());
assertEquals(organizationEntity.getId(), organization.getId());
assertEquals(organizationEntity.getOwner(), organization.getOwner().getId());
assertNull(organization.getRoles());
@ -78,6 +78,7 @@ class BouncerContextConverterTest {
TestObjectFactory.buildMemberRole(RoleId.ADMINISTRATOR, TestObjectFactory.randomString());
var organization = converter.toOrganization(organizationEntity, Set.of(memberRoleEntity));
assertEquals(organizationEntity.getId(), organization.getId());
assertEquals(organizationEntity.getOwner(), organization.getOwner().getId());
assertTrue(organization.getRoles().isEmpty());
@ -90,6 +91,7 @@ class BouncerContextConverterTest {
TestObjectFactory.buildMemberRole(RoleId.ADMINISTRATOR, organizationEntity.getId());
var organization = converter.toOrganization(organizationEntity, Set.of(memberRoleEntity));
assertEquals(organizationEntity.getId(), organization.getId());
assertEquals(organizationEntity.getOwner(), organization.getOwner().getId());
assertEquals(memberRoleEntity.getRoleId(), organization.getRoles().iterator().next().getId());