Skip to content

Commit

Permalink
Merge pull request #77 from SelimHorri/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
SelimHorri authored Mar 11, 2022
2 parents f430a7b + d0179f6 commit 00dd16a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 25 deletions.
3 changes: 1 addition & 2 deletions src/main/java/tn/cita/app/constant/AppConstant.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tn.cita.app.constant;

import java.time.Duration;
import java.time.LocalDateTime;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -46,7 +45,7 @@ public final class AppConstant {
/**
* Verification Token expires after specified minutes from localdatetime.now
*/
public static final LocalDateTime EXPIRES_AT_FROM_NOW = LocalDateTime.now().plusMinutes(Duration.ofMinutes(30).toMinutes());
public static final long EXPIRES_AT_FROM_NOW = Duration.ofMinutes(30).toMinutes();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private RegisterResponse registerCustomer(final RegisterRequest registerRequest)
log.info("** Customer saved successfully! *");

final var verificationToken = new VerificationToken(UUID.randomUUID().toString(),
AppConstant.EXPIRES_AT_FROM_NOW,
LocalDateTime.now().plusMinutes(AppConstant.EXPIRES_AT_FROM_NOW),
savedCustomer.getCredential());
final var savedVerificationToken = this.verificationTokenRepository.save(verificationToken);
log.info("** Verification token saved successfully! *");
Expand All @@ -121,8 +121,9 @@ private RegisterResponse registerCustomer(final RegisterRequest registerRequest)
return new RegisterResponse(String
.format("User with username %s has been saved successfully. "
+ "Check your email to enbale your account. "
+ "Please consider that link will expire after 30min from registration",
savedCustomer.getCredential().getUsername()));
+ "Please consider that link will expire after %dmin from registration",
savedCustomer.getCredential().getUsername(),
AppConstant.EXPIRES_AT_FROM_NOW));
}

private RegisterResponse registerEmployee(final RegisterRequest registerRequest) {
Expand All @@ -133,7 +134,8 @@ private RegisterResponse registerEmployee(final RegisterRequest registerRequest)
log.info("** Employee saved successfully! *");

final var verificationToken = new VerificationToken(UUID.randomUUID().toString(),
AppConstant.EXPIRES_AT_FROM_NOW,
LocalDateTime.now().plusMinutes(AppConstant.EXPIRES_AT_FROM_NOW),
// AppConstant.EXPIRES_AT_FROM_NOW,
savedEmployee.getCredential());
final var savedVerificationToken = this.verificationTokenRepository.save(verificationToken);
log.info("** Verification token saved successfully! *");
Expand All @@ -150,8 +152,9 @@ private RegisterResponse registerEmployee(final RegisterRequest registerRequest)
return new RegisterResponse(String
.format("User with username %s has been saved successfully. "
+ "Check your email to enbale your account. "
+ "Please consider that link will expire after 30min from registration",
savedEmployee.getCredential().getUsername()));
+ "Please consider that link will expire after %dmin from registration",
savedEmployee.getCredential().getUsername(),
AppConstant.EXPIRES_AT_FROM_NOW));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.testcontainers.containers.MySQLContainer;

public abstract class AbstractTestSharedMySQLContainer {
public abstract class AbstractSharedMySQLTestContainer {

private static final MySQLContainer<?> MYSQL_CONTAINER;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.springframework.test.web.reactive.server.WebTestClient;

import tn.cita.app.constant.AppConstant;
import tn.cita.app.container.AbstractTestSharedMySQLContainer;
import tn.cita.app.container.AbstractSharedMySQLTestContainer;
import tn.cita.app.dto.request.LoginRequest;
import tn.cita.app.dto.response.LoginResponse;
import tn.cita.app.dto.response.api.ApiPayloadResponse;
Expand All @@ -29,7 +29,7 @@

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient
class AuthenticationResourceIntegrationTest extends AbstractTestSharedMySQLContainer {
class AuthenticationResourceIntegrationTest extends AbstractSharedMySQLTestContainer {

@Autowired
private AuthenticationService authenticationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.springframework.web.context.request.ServletRequestAttributes;

import tn.cita.app.constant.AppConstant;
import tn.cita.app.container.AbstractTestSharedMySQLContainer;
import tn.cita.app.container.AbstractSharedMySQLTestContainer;
import tn.cita.app.domain.UserRoleBasedAuthority;
import tn.cita.app.dto.request.RegisterRequest;
import tn.cita.app.dto.response.RegisterResponse;
Expand All @@ -31,7 +31,7 @@

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient
class RegistrationResourceIntegrationTest extends AbstractTestSharedMySQLContainer {
class RegistrationResourceIntegrationTest extends AbstractSharedMySQLTestContainer {

@Autowired
private WebTestClient webTestClient;
Expand Down Expand Up @@ -61,8 +61,9 @@ void givenValidRegisterRequestForCustomer_whenRegister_thenRegisterResponseShoul
new RegisterResponse(String
.format("User with username %s has been saved successfully. "
+ "Check your email to enbale your account. "
+ "Please consider that link will expire after 30min from registration",
registerRequest.getUsername())));
+ "Please consider that link will expire after %dmin from registration",
registerRequest.getUsername(),
AppConstant.EXPIRES_AT_FROM_NOW)));

this.webTestClient
.post()
Expand Down Expand Up @@ -101,8 +102,9 @@ void givenValidRegisterRequestForWorker_whenRegister_thenRegisterResponseShouldB
new RegisterResponse(String
.format("User with username %s has been saved successfully. "
+ "Check your email to enbale your account. "
+ "Please consider that link will expire after 30min from registration",
registerRequest.getUsername())));
+ "Please consider that link will expire after %dmin from registration",
registerRequest.getUsername(),
AppConstant.EXPIRES_AT_FROM_NOW)));

this.webTestClient
.post()
Expand Down Expand Up @@ -141,8 +143,9 @@ void givenValidRegisterRequestForManager_whenRegister_thenRegisterResponseShould
new RegisterResponse(String
.format("User with username %s has been saved successfully. "
+ "Check your email to enbale your account. "
+ "Please consider that link will expire after 30min from registration",
registerRequest.getUsername())));
+ "Please consider that link will expire after %dmin from registration",
registerRequest.getUsername(),
AppConstant.EXPIRES_AT_FROM_NOW)));

this.webTestClient
.post()
Expand Down Expand Up @@ -181,8 +184,9 @@ void givenValidRegisterRequestForOwner_whenRegister_thenRegisterResponseShouldBe
new RegisterResponse(String
.format("User with username %s has been saved successfully. "
+ "Check your email to enbale your account. "
+ "Please consider that link will expire after 30min from registration",
registerRequest.getUsername())));
+ "Please consider that link will expire after %dmin from registration",
registerRequest.getUsername(),
AppConstant.EXPIRES_AT_FROM_NOW)));

this.webTestClient
.post()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

import tn.cita.app.container.AbstractTestSharedMySQLContainer;
import tn.cita.app.container.AbstractSharedMySQLTestContainer;
import tn.cita.app.domain.entity.Credential;

@DataJpaTest(showSql = true)
@AutoConfigureDataJpa
class CredentialRepositoryTest extends AbstractTestSharedMySQLContainer {
class CredentialRepositoryTest extends AbstractSharedMySQLTestContainer {

@Autowired
private CredentialRepository credentialRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;

import tn.cita.app.container.AbstractTestSharedMySQLContainer;
import tn.cita.app.container.AbstractSharedMySQLTestContainer;
import tn.cita.app.domain.entity.VerificationToken;

@DataJpaTest(showSql = true)
@AutoConfigureDataJpa
class VerificationTokenRepositoryTest extends AbstractTestSharedMySQLContainer {
class VerificationTokenRepositoryTest extends AbstractSharedMySQLTestContainer {

@Autowired
private VerificationTokenRepository verificationTokenRepository;
Expand Down

0 comments on commit 00dd16a

Please sign in to comment.