add some e2e test
This commit is contained in:
parent
02a9518b2c
commit
ba4d3d2b01
2
go.mod
2
go.mod
@ -27,6 +27,7 @@ require (
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
github.com/google/uuid v1.4.0 // indirect
|
||||
github.com/klauspost/compress v1.16.7 // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
@ -50,5 +51,6 @@ require (
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20240102182953-50ed04b92917 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
9
go.sum
9
go.sum
@ -31,6 +31,12 @@ github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwA
|
||||
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
|
||||
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
@ -144,8 +150,9 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
|
||||
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
|
64
tests/e2e/recover_test.go
Normal file
64
tests/e2e/recover_test.go
Normal file
@ -0,0 +1,64 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"codeword/internal/models"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRecoveryHandler(t *testing.T) {
|
||||
client := fiber.AcquireClient()
|
||||
|
||||
t.Run("HandleRecoveryRequest", func(t *testing.T) {
|
||||
reqBody := models.RecoveryRequest{
|
||||
Email: "test@example.com",
|
||||
RedirectionURL: "http://redirect.com",
|
||||
}
|
||||
reqJSON, _ := json.Marshal(reqBody)
|
||||
|
||||
req := client.Post("/recover").Set("Content-Type", "application/json").Body(reqJSON)
|
||||
|
||||
statusCode, resBody, errs := req.Bytes()
|
||||
assert.NoError(t, errs[0])
|
||||
|
||||
assert.Equal(t, fiber.StatusOK, statusCode)
|
||||
|
||||
var responseMap map[string]interface{}
|
||||
err := json.Unmarshal(resBody, &responseMap)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "Recovery email sent successfully", responseMap["message"])
|
||||
})
|
||||
|
||||
t.Run("HandleRecoveryRequest_MissingEmail", func(t *testing.T) {
|
||||
reqBody := models.RecoveryRequest{
|
||||
RedirectionURL: "http://redirect.com",
|
||||
}
|
||||
reqJSON, _ := json.Marshal(reqBody)
|
||||
|
||||
req := client.Post("/recover").Set("Content-Type", "application/json").Body(reqJSON)
|
||||
|
||||
statusCode, _, errs := req.Bytes()
|
||||
assert.NoError(t, errs[0])
|
||||
|
||||
assert.Equal(t, fiber.StatusBadRequest, statusCode)
|
||||
})
|
||||
|
||||
t.Run("HandleRecoveryRequest_UserNotFound", func(t *testing.T) {
|
||||
reqBody := models.RecoveryRequest{
|
||||
Email: "nonexistent@example.com",
|
||||
RedirectionURL: "http://redirect.com",
|
||||
}
|
||||
reqJSON, _ := json.Marshal(reqBody)
|
||||
|
||||
req := client.Post("/recover").Set("Content-Type", "application/json").Body(reqJSON)
|
||||
|
||||
statusCode, _, errs := req.Bytes()
|
||||
assert.NoError(t, errs[0])
|
||||
|
||||
assert.Equal(t, fiber.StatusNotFound, statusCode)
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user