Skip to content

Commit d0179f6

Browse files
authored
Merge pull request #76 from SelimHorri/develop
refactor expiry date duration after mail sent
2 parents e0790f2 + d9d7294 commit d0179f6

File tree

7 files changed

+31
-25
lines changed

7 files changed

+31
-25
lines changed

src/main/java/tn/cita/app/constant/AppConstant.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package tn.cita.app.constant;
22

33
import java.time.Duration;
4-
import java.time.LocalDateTime;
54

65
import lombok.AccessLevel;
76
import lombok.NoArgsConstructor;
@@ -46,7 +45,7 @@ public final class AppConstant {
4645
/**
4746
* Verification Token expires after specified minutes from localdatetime.now
4847
*/
49-
public static final LocalDateTime EXPIRES_AT_FROM_NOW = LocalDateTime.now().plusMinutes(Duration.ofMinutes(30).toMinutes());
48+
public static final long EXPIRES_AT_FROM_NOW = Duration.ofMinutes(30).toMinutes();
5049

5150
}
5251

src/main/java/tn/cita/app/service/impl/RegistrationServiceImpl.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private RegisterResponse registerCustomer(final RegisterRequest registerRequest)
104104
log.info("** Customer saved successfully! *");
105105

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

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

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

157160
@Override

src/test/java/tn/cita/app/container/AbstractTestSharedMySQLContainer.java renamed to src/test/java/tn/cita/app/container/AbstractSharedMySQLTestContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import org.testcontainers.containers.MySQLContainer;
66

7-
public abstract class AbstractTestSharedMySQLContainer {
7+
public abstract class AbstractSharedMySQLTestContainer {
88

99
private static final MySQLContainer<?> MYSQL_CONTAINER;
1010

src/test/java/tn/cita/app/integration/AuthenticationResourceIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.springframework.test.web.reactive.server.WebTestClient;
2020

2121
import tn.cita.app.constant.AppConstant;
22-
import tn.cita.app.container.AbstractTestSharedMySQLContainer;
22+
import tn.cita.app.container.AbstractSharedMySQLTestContainer;
2323
import tn.cita.app.dto.request.LoginRequest;
2424
import tn.cita.app.dto.response.LoginResponse;
2525
import tn.cita.app.dto.response.api.ApiPayloadResponse;
@@ -29,7 +29,7 @@
2929

3030
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
3131
@AutoConfigureWebTestClient
32-
class AuthenticationResourceIntegrationTest extends AbstractTestSharedMySQLContainer {
32+
class AuthenticationResourceIntegrationTest extends AbstractSharedMySQLTestContainer {
3333

3434
@Autowired
3535
private AuthenticationService authenticationService;

src/test/java/tn/cita/app/integration/RegistrationResourceIntegrationTest.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.springframework.web.context.request.ServletRequestAttributes;
2323

2424
import tn.cita.app.constant.AppConstant;
25-
import tn.cita.app.container.AbstractTestSharedMySQLContainer;
25+
import tn.cita.app.container.AbstractSharedMySQLTestContainer;
2626
import tn.cita.app.domain.UserRoleBasedAuthority;
2727
import tn.cita.app.dto.request.RegisterRequest;
2828
import tn.cita.app.dto.response.RegisterResponse;
@@ -31,7 +31,7 @@
3131

3232
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
3333
@AutoConfigureWebTestClient
34-
class RegistrationResourceIntegrationTest extends AbstractTestSharedMySQLContainer {
34+
class RegistrationResourceIntegrationTest extends AbstractSharedMySQLTestContainer {
3535

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

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

107109
this.webTestClient
108110
.post()
@@ -141,8 +143,9 @@ void givenValidRegisterRequestForManager_whenRegister_thenRegisterResponseShould
141143
new RegisterResponse(String
142144
.format("User with username %s has been saved successfully. "
143145
+ "Check your email to enbale your account. "
144-
+ "Please consider that link will expire after 30min from registration",
145-
registerRequest.getUsername())));
146+
+ "Please consider that link will expire after %dmin from registration",
147+
registerRequest.getUsername(),
148+
AppConstant.EXPIRES_AT_FROM_NOW)));
146149

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

187191
this.webTestClient
188192
.post()

src/test/java/tn/cita/app/repository/CredentialRepositoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa;
88
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
99

10-
import tn.cita.app.container.AbstractTestSharedMySQLContainer;
10+
import tn.cita.app.container.AbstractSharedMySQLTestContainer;
1111
import tn.cita.app.domain.entity.Credential;
1212

1313
@DataJpaTest(showSql = true)
1414
@AutoConfigureDataJpa
15-
class CredentialRepositoryTest extends AbstractTestSharedMySQLContainer {
15+
class CredentialRepositoryTest extends AbstractSharedMySQLTestContainer {
1616

1717
@Autowired
1818
private CredentialRepository credentialRepository;

src/test/java/tn/cita/app/repository/VerificationTokenRepositoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureDataJpa;
88
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
99

10-
import tn.cita.app.container.AbstractTestSharedMySQLContainer;
10+
import tn.cita.app.container.AbstractSharedMySQLTestContainer;
1111
import tn.cita.app.domain.entity.VerificationToken;
1212

1313
@DataJpaTest(showSql = true)
1414
@AutoConfigureDataJpa
15-
class VerificationTokenRepositoryTest extends AbstractTestSharedMySQLContainer {
15+
class VerificationTokenRepositoryTest extends AbstractSharedMySQLTestContainer {
1616

1717
@Autowired
1818
private VerificationTokenRepository verificationTokenRepository;

0 commit comments

Comments
 (0)