add some recover tests

This commit is contained in:
Pavel 2024-01-25 19:20:41 +03:00
parent 2508b0fc5e
commit c2ad4cd3a2
2 changed files with 31 additions and 1 deletions

1
tests/e2e/promo_test.go Normal file

@ -0,0 +1 @@
package e2e

@ -7,9 +7,13 @@ import (
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing" "testing"
"time"
) )
const BaseUrl = "http://localhost:8080" const (
BaseUrl = "http://localhost:8080"
ValidSign = "GSiyv5zBITGshqnvYLHKtXE3e4yZjKGvruOVFWuUuj9Nvaps28-Zt6RDq9n47eaNUlay1-nUVld61I3xoAAgCA==65b286c2f13095d96792079d"
)
// post handler // post handler
func TestRecoveryHandler(t *testing.T) { func TestRecoveryHandler(t *testing.T) {
@ -89,3 +93,28 @@ func TestRecoveryHandler(t *testing.T) {
} }
// get handler // get handler
func TestRecoveryLinkHandler(t *testing.T) {
client := fiber.AcquireClient()
t.Run("HandleRecoveryLink_ValidSign", func(t *testing.T) {
req := client.Get(BaseUrl + "/recover/" + ValidSign)
statusCode, _, errs := req.Bytes()
if len(errs) != 0 {
assert.NoError(t, errs[0])
}
assert.Equal(t, fiber.StatusOK, statusCode)
fmt.Println("Recovery link handled successfully")
})
time.Sleep(15 * time.Minute)
t.Run("HandleRecoveryLink_ExpiredSign", func(t *testing.T) {
req := client.Get(BaseUrl + "/recover/" + ValidSign)
statusCode, _, errs := req.Bytes()
if len(errs) != 0 {
assert.NoError(t, errs[0])
}
assert.Equal(t, fiber.StatusNotAcceptable, statusCode)
fmt.Println("Recovery link with expired sign handled correctly")
})
}