Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
clean-coder committed Oct 24, 2024
1 parent 023bb8b commit 388cd68
Showing 1 changed file with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,20 @@ class AuthorizationRegistrationServiceIT {

private static final String EMAIL_WUNDERLAND = "[email protected]";

private final User userWithNoOkrChampionInfo = User.Builder.builder() //
.withFirstname("Alice") //
.withLastname("Wunderland") //
.withEmail(EMAIL_WUNDERLAND) // user.champion.emails from application-integration-test.properties
.build();

@BeforeEach
void setUp() {
TenantContext.setCurrentTenant(tenant);
}

@AfterEach
void tearDown() {
resetOkrChampionStatus(userWithNoOkrChampionInfo.getEmail());
resetOkrChampionStatus();
clearCache();
TenantContext.setCurrentTenant(null);
}

private void resetOkrChampionStatus(String email) {
Optional<User> userFromDb = userPersistenceService.findByEmail(email);
private void resetOkrChampionStatus() {
Optional<User> userFromDb = userPersistenceService.findByEmail(EMAIL_WUNDERLAND);
assertTrue(userFromDb.isPresent());

userFromDb.get().setOkrChampion(false);
Expand Down Expand Up @@ -116,23 +110,27 @@ void registerAuthorizationUser_shouldSetOkrChampionsToFalse() {

/*
* Special test setup. <pre> - the user [email protected] is an existing user in the H2 db (created via
* X_TestData.sql) - the user [email protected] is also defined in application-integration-test.properties as
* user champion - with this combination we can test, that the user in the db (which has initial isOkrChampion ==
* false) is after calling updateOrAddAuthorizationUser() a user champion. - because the user [email protected]
* exists before the test, we make no clean in db (we don't remove it) </pre>
* V100_0_0__TestData.sql) - the user [email protected] is also defined in
* application-integration-test.properties as user champion - with this combination we can test, that the user in
* the db (which has initial isOkrChampion == false) is after calling updateOrAddAuthorizationUser() a user
* champion. - the OkrChampion status must manually be reset (in the tearDown method) </pre>
*/
@Test
@DisplayName("registerAuthorizationUser for a user with an email defined in the application-integration-test.properties should set OkrChampions to true")
void registerAuthorizationUserShouldSetOkrChampionsToTrue() {
// arrange
assertOkrChampionStatusInDb(userWithNoOkrChampionInfo.getEmail(), false); // pre-condition
assertOkrChampionStatusInDb(EMAIL_WUNDERLAND, false); // pre-condition

// act
// load user from db (by email) and set OkrChampion status based on property
// "okr.tenants.pitc.user.champion.emails"
// from application-integration-test.properties file
// "okr.tenants.pitc.user.champion.emails" from application-integration-test.properties file
AuthorizationUser processedUser = authorizationRegistrationService
.updateOrAddAuthorizationUser(userWithNoOkrChampionInfo);
.updateOrAddAuthorizationUser(User.Builder.builder() //
.withFirstname("Alice") //
.withLastname("Wunderland") //
.withEmail(EMAIL_WUNDERLAND) // user.champion.emails from
// application-integration-test.properties
.build());

// assert
assertTrue(processedUser.user().isOkrChampion());
Expand Down

0 comments on commit 388cd68

Please sign in to comment.