From a792f6fc5d26d112756df21dbe287cb6eb01f2fa Mon Sep 17 00:00:00 2001 From: NitiwatOwen Date: Sun, 14 Jan 2024 10:31:21 +0700 Subject: [PATCH] feat: update reset password ttl --- internal/service/token/token.service.go | 2 +- internal/service/token/token.service_test.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/service/token/token.service.go b/internal/service/token/token.service.go index 943f40a..fc69d28 100644 --- a/internal/service/token/token.service.go +++ b/internal/service/token/token.service.go @@ -175,7 +175,7 @@ func (s *serviceImpl) CreateResetPasswordToken(userId string) (string, error) { tokenCache := &tokenDto.ResetPasswordTokenCache{ UserID: userId, } - err := s.resetPasswordTokenCache.SetValue(resetPasswordToken, tokenCache, 900) + err := s.resetPasswordTokenCache.SetValue(resetPasswordToken, tokenCache, s.jwtService.GetConfig().ResetTokenTTL) if err != nil { return "", err } diff --git a/internal/service/token/token.service_test.go b/internal/service/token/token.service_test.go index fde9823..bbb273e 100644 --- a/internal/service/token/token.service_test.go +++ b/internal/service/token/token.service_test.go @@ -48,6 +48,7 @@ func (t *TokenServiceTest) SetupTest() { ExpiresIn: 3600, RefreshTokenTTL: 604800, Issuer: "testIssuer", + ResetTokenTTL: 900, } validateToken := "" @@ -592,7 +593,8 @@ func (t *TokenServiceTest) TestCreateResetPasswordTokenSuccess() { uuidUtil := utils.UuidUtilMock{} uuidUtil.On("GetNewUUID").Return(t.refreshToken) - resetPasswordTokenRepo.EXPECT().SetValue(t.refreshToken.String(), tokenCache, 900).Return(nil) + jwtService.On("GetConfig").Return(t.jwtConfig) + resetPasswordTokenRepo.EXPECT().SetValue(t.refreshToken.String(), tokenCache, t.jwtConfig.ResetTokenTTL).Return(nil) tokenSvc := NewService(&jwtService, accessTokenRepo, refreshTokenRepo, resetPasswordTokenRepo, &uuidUtil) actual, err := tokenSvc.CreateResetPasswordToken(t.userId) @@ -618,7 +620,8 @@ func (t *TokenServiceTest) TestCreateResetPasswordTokenFailed() { uuidUtil := utils.UuidUtilMock{} uuidUtil.On("GetNewUUID").Return(t.refreshToken) - resetPasswordTokenRepo.EXPECT().SetValue(t.refreshToken.String(), tokenCache, 900).Return(cacheErr) + jwtService.On("GetConfig").Return(t.jwtConfig) + resetPasswordTokenRepo.EXPECT().SetValue(t.refreshToken.String(), tokenCache, t.jwtConfig.ResetTokenTTL).Return(cacheErr) tokenSvc := NewService(&jwtService, accessTokenRepo, refreshTokenRepo, resetPasswordTokenRepo, &uuidUtil) actual, err := tokenSvc.CreateResetPasswordToken(t.userId)