Skip to content

Commit

Permalink
testing: auth testing (#113)
Browse files Browse the repository at this point in the history
testing: auth testing
  • Loading branch information
masnann authored Dec 19, 2023
2 parents 1a25ca6 + e30bfef commit c90aaf2
Show file tree
Hide file tree
Showing 6 changed files with 326 additions and 39 deletions.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"github.com/capstone-kelompok-7/backend-disappear/utils/email"
"github.com/capstone-kelompok-7/backend-disappear/utils/sendnotif"

"github.com/capstone-kelompok-7/backend-disappear/config"
Expand Down Expand Up @@ -79,13 +80,14 @@ func main() {
generatorID := utils.NewGeneratorUUID(db)
fcm := sendnotif.NewFcmService()
coreApi := payment.InitSnapMidtrans(*initConfig)
emailSender := email.NewEmailService()

userRepo := rUser.NewUserRepository(db)
userService := sUser.NewUserService(userRepo, hash)
userHandler := hUser.NewUserHandler(userService)

authRepo := rAuth.NewAuthRepository(db)
authService := sAuth.NewAuthService(authRepo, jwtService, userService, hash, rdb)
authService := sAuth.NewAuthService(authRepo, jwtService, userService, hash, rdb, emailSender)
authHandler := hAuth.NewAuthHandler(authService, userService)

voucherRepo := rVoucher.NewVoucherRepository(db)
Expand Down
6 changes: 4 additions & 2 deletions module/feature/auth/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ func (h *AuthHandler) ResendOTP() echo.HandlerFunc {
return response.SendStatusInternalServerResponse(c, "Gagal mengirim ulang OTP: "+err.Error())
}

err = email.EmailService(emailRequest.Email, newOTP.OTP)
emailSender := email.NewEmailService()
err = emailSender.EmailService(emailRequest.Email, newOTP.OTP)
if err != nil {
return response.SendStatusInternalServerResponse(c, "Gagal mengirim ulang OTP ke email: "+err.Error())
}
Expand All @@ -142,7 +143,8 @@ func (h *AuthHandler) ForgotPassword() echo.HandlerFunc {
return response.SendStatusInternalServerResponse(c, "Gagal mengirim ulang OTP: "+err.Error())
}

err = email.EmailService(forgotPasswordRequest.Email, newOTP.OTP)
emailSender := email.NewEmailService()
err = emailSender.EmailService(forgotPasswordRequest.Email, newOTP.OTP)
if err != nil {
return response.SendStatusInternalServerResponse(c, "Gagal mengirim ulang OTP ke email: "+err.Error())

Expand Down
6 changes: 4 additions & 2 deletions module/feature/auth/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ type AuthService struct {
jwt utils.JWTInterface
hash utils.HashInterface
cache caching.CacheRepository
email email.EmailSenderInterface
}

func NewAuthService(repo auth.RepositoryAuthInterface, jwt utils.JWTInterface, userService users.ServiceUserInterface, hash utils.HashInterface, cache caching.CacheRepository) auth.ServiceAuthInterface {
func NewAuthService(repo auth.RepositoryAuthInterface, jwt utils.JWTInterface, userService users.ServiceUserInterface, hash utils.HashInterface, cache caching.CacheRepository, email email.EmailSenderInterface) auth.ServiceAuthInterface {
return &AuthService{
repo: repo,
jwt: jwt,
userService: userService,
hash: hash,
cache: cache,
email: email,
}
}

Expand Down Expand Up @@ -73,7 +75,7 @@ func (s *AuthService) Register(newData *entities.UserModels) (*entities.UserMode
if errOtp != nil {
return nil, errOtp
}
err = email.EmailService(result.Email, generateOTP)
err = s.email.EmailService(result.Email, generateOTP)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit c90aaf2

Please sign in to comment.