Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
isaqueveras committed Oct 17, 2023
1 parent 25b0196 commit eb4c982
Showing 1 changed file with 10 additions and 34 deletions.
44 changes: 10 additions & 34 deletions delivery/http/auth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ package auth
import (
"bytes"
"context"
"database/sql"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"

"bou.ke/monkey"
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt/v4"
"github.com/google/uuid"
"github.com/stretchr/testify/suite"

Expand All @@ -39,7 +39,15 @@ type testSuite struct {

func (a *testSuite) SetupSuite() {
var handleUserLog = func() gin.HandlerFunc {
return func(ctx *gin.Context) { ctx.Set("UID", sucessUserID) }
return func(ctx *gin.Context) {
ctx.Set("UID", sucessUserID)
ctx.Set("SESSION", jwt.MapClaims{
"SessionID": "",
"UserID": sucessUserID,
"UserLevel": string(domain.AdminLevel),
"FirstName": "Janekin",
})
}
}

a.router = gin.New()
Expand Down Expand Up @@ -70,38 +78,6 @@ func (a *testSuite) TestShouldCreateUser() {
a.Assert().Equal(http.StatusCreated, w.Code)
}

func (t *testSuite) TestLoginSteps() {
t.Run("UserFound", func() {
monkey.Patch(auth.LoginSteps, func(ctx context.Context, email *string) (res *domain.Steps, err error) {
return nil, nil
})
defer monkey.Unpatch(auth.LoginSteps)

var (
req = httptest.NewRequest(http.MethodGet, "/v1/auth/login/[email protected]", nil)
w = httptest.NewRecorder()
)

t.router.ServeHTTP(w, req)
t.Assert().Equal(http.StatusOK, w.Code)
})

t.Run("UserNotFound", func() {
monkey.Patch(auth.LoginSteps, func(ctx context.Context, email *string) (*domain.Steps, error) {
return nil, sql.ErrNoRows
})
defer monkey.Unpatch(auth.LoginSteps)

var (
req = httptest.NewRequest(http.MethodGet, "/v1/auth/login/steps", nil)
w = httptest.NewRecorder()
)

t.router.ServeHTTP(w, req)
t.Assert().Equal(http.StatusNotFound, w.Code)
})
}

func (t *testSuite) TestShouldGetUrlQrCode() {
t.Run("Success", func() {
monkey.Patch(auth.GetQRCode2FA, func(_ context.Context, _ *uuid.UUID) (*string, error) {
Expand Down

0 comments on commit eb4c982

Please sign in to comment.