-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix avatar initials for usernames with whitespace (#971)
closes #970
- Loading branch information
Showing
6 changed files
with
116 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
.../resources/db/changelog/changelog-2.14.0-remove-leading-trailing-whitespaces-username.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.1" encoding="UTF-8" standalone="no"?> | ||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.5.xsd"> | ||
|
||
<changeSet author="seber" id="remove-leading-trailing-whitespaces-given-name"> | ||
<preConditions> | ||
<tableExists tableName="tenant_user"/> | ||
<columnExists tableName="tenant_user" columnName="given_name"/> | ||
</preConditions> | ||
<update tableName="tenant_user"> | ||
<column name="given_name" value="TRIM(given_name)" /> | ||
<where> | ||
given_name LIKE ' %' OR given_name LIKE '% ' | ||
</where> | ||
</update> | ||
</changeSet> | ||
|
||
<changeSet author="seber" id="remove-leading-trailing-whitespaces-family-name"> | ||
<preConditions> | ||
<tableExists tableName="tenant_user"/> | ||
<columnExists tableName="tenant_user" columnName="family_name"/> | ||
</preConditions> | ||
<update tableName="tenant_user"> | ||
<column name="family_name" value="TRIM(family_name)" /> | ||
<where> | ||
family_name LIKE ' %' OR family_name LIKE '% ' | ||
</where> | ||
</update> | ||
</changeSet> | ||
|
||
</databaseChangeLog> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,28 +30,14 @@ | |
class TenantUserServiceImplTest { | ||
|
||
private final Clock clock = Clock.fixed(Instant.now(), ZoneId.systemDefault()); | ||
|
||
private TenantUserServiceImpl sut; | ||
|
||
@Mock | ||
private TenantUserRepository repository; | ||
@Mock | ||
private ApplicationEventPublisher publisher; | ||
|
||
private static TenantUser activeTenantUserOne(Instant now) { | ||
return new TenantUser("my-external-id-1", 1L, "batman", "batman", new EMailAddress("[email protected]"), now, Set.of(), now, now, null, null, UserStatus.ACTIVE); | ||
} | ||
|
||
private static TenantUserEntity activeUserEntityOne(Instant now) { | ||
return new TenantUserEntity(1L, "my-external-id-1", now, now, "batman", "batman", "[email protected]", Set.of(), now, now, null, null, UserStatus.ACTIVE); | ||
} | ||
|
||
private static TenantUser activeTenantUserTwo(Instant now) { | ||
return new TenantUser("my-external-id-2", 2L, "petra", "panter", new EMailAddress("[email protected]"), now, Set.of(), now, now, null, null, UserStatus.ACTIVE); | ||
} | ||
|
||
private static TenantUserEntity activeUserEntityTwo(Instant now) { | ||
return new TenantUserEntity(2L, "my-external-id-2", now, now, "petra", "panter", "[email protected]", Set.of(), now, now, null, null, UserStatus.ACTIVE); | ||
} | ||
|
||
@BeforeEach | ||
void setUp() { | ||
sut = new TenantUserServiceImpl(repository, publisher, clock); | ||
|
@@ -237,6 +223,30 @@ void newUserIsCreatedSuccessfully() { | |
|
||
verify(publisher).publishEvent(any(TenantUserCreatedEvent.class)); | ||
} | ||
|
||
@Test | ||
void ensureGivenNameAndFamilyNameIsStripped() { | ||
|
||
final String uuid = "my-external-id"; | ||
final String givenName = " Hans Joachim "; | ||
final String familyName = " Sonnencreme "; | ||
final EMailAddress eMailAddress = new EMailAddress("[email protected]"); | ||
|
||
when(repository.save(any(TenantUserEntity.class))).thenAnswer(returnsFirstArg()); | ||
|
||
final TenantUser result = sut.createNewUser(uuid, givenName, familyName, eMailAddress, Set.of()); | ||
|
||
final ArgumentCaptor<TenantUserEntity> entityArgumentCaptor = ArgumentCaptor.forClass(TenantUserEntity.class); | ||
verify(repository).save(entityArgumentCaptor.capture()); | ||
|
||
assertThat(entityArgumentCaptor.getValue()).satisfies(entity -> { | ||
assertThat(entity.getGivenName()).isEqualTo("Hans Joachim"); | ||
assertThat(entity.getFamilyName()).isEqualTo("Sonnencreme"); | ||
}); | ||
|
||
assertThat(result.givenName()).isEqualTo("Hans Joachim"); | ||
assertThat(result.familyName()).isEqualTo("Sonnencreme"); | ||
} | ||
} | ||
|
||
@Nested | ||
|
@@ -258,7 +268,6 @@ void updateUserSuccessfully() { | |
|
||
TenantUser result = sut.updateUser(update); | ||
|
||
|
||
ArgumentCaptor<TenantUserEntity> entityArgumentCaptor = ArgumentCaptor.forClass(TenantUserEntity.class); | ||
|
||
verify(repository).save(entityArgumentCaptor.capture()); | ||
|
@@ -288,6 +297,31 @@ void updateUserSuccessfully() { | |
}); | ||
} | ||
|
||
@Test | ||
void ensureGivenNameAndFamilyNameIsStripped() { | ||
|
||
final Instant now = clock.instant(); | ||
|
||
final TenantUserEntity currentEntity = activeUserEntityOne(now); | ||
final TenantUser update = updateFromEntity(currentEntity, " Hans Joachim ", " Sonnencreme ", "[email protected]"); | ||
|
||
when(repository.findById(any())).thenReturn(Optional.of(currentEntity)); | ||
when(repository.save(any(TenantUserEntity.class))).thenAnswer(returnsFirstArg()); | ||
|
||
final TenantUser result = sut.updateUser(update); | ||
|
||
final ArgumentCaptor<TenantUserEntity> entityArgumentCaptor = ArgumentCaptor.forClass(TenantUserEntity.class); | ||
verify(repository).save(entityArgumentCaptor.capture()); | ||
|
||
assertThat(entityArgumentCaptor.getValue()).satisfies(entity -> { | ||
assertThat(entity.getGivenName()).isEqualTo("Hans Joachim"); | ||
assertThat(entity.getFamilyName()).isEqualTo("Sonnencreme"); | ||
}); | ||
|
||
assertThat(result.givenName()).isEqualTo("Hans Joachim"); | ||
assertThat(result.familyName()).isEqualTo("Sonnencreme"); | ||
} | ||
|
||
@Test | ||
void updateUserThrowsExceptionWhenUserNotFound() { | ||
TenantUser user = activeTenantUserOne(Instant.now()); | ||
|
@@ -413,8 +447,22 @@ void deactivateUserThrowsExceptionWhenUserNotFound() { | |
|
||
verify(repository).findById(userId); | ||
} | ||
|
||
} | ||
} | ||
|
||
private static TenantUser activeTenantUserOne(Instant now) { | ||
return new TenantUser("my-external-id-1", 1L, "batman", "batman", new EMailAddress("[email protected]"), now, Set.of(), now, now, null, null, UserStatus.ACTIVE); | ||
} | ||
|
||
private static TenantUserEntity activeUserEntityOne(Instant now) { | ||
return new TenantUserEntity(1L, "my-external-id-1", now, now, "batman", "batman", "[email protected]", Set.of(), now, now, null, null, UserStatus.ACTIVE); | ||
} | ||
|
||
private static TenantUser activeTenantUserTwo(Instant now) { | ||
return new TenantUser("my-external-id-2", 2L, "petra", "panter", new EMailAddress("[email protected]"), now, Set.of(), now, now, null, null, UserStatus.ACTIVE); | ||
} | ||
|
||
private static TenantUserEntity activeUserEntityTwo(Instant now) { | ||
return new TenantUserEntity(2L, "my-external-id-2", now, now, "petra", "panter", "[email protected]", Set.of(), now, now, null, null, UserStatus.ACTIVE); | ||
} | ||
} |