From c2ad4cd3a2c08dc975b7cb4d6dea4c5ea7c5a369 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 25 Jan 2024 19:20:41 +0300 Subject: [PATCH] add some recover tests --- tests/e2e/promo_test.go | 1 + tests/e2e/recover_test.go | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/e2e/promo_test.go diff --git a/tests/e2e/promo_test.go b/tests/e2e/promo_test.go new file mode 100644 index 0000000..df8caf7 --- /dev/null +++ b/tests/e2e/promo_test.go @@ -0,0 +1 @@ +package e2e diff --git a/tests/e2e/recover_test.go b/tests/e2e/recover_test.go index aadeff7..1d23f39 100644 --- a/tests/e2e/recover_test.go +++ b/tests/e2e/recover_test.go @@ -7,9 +7,13 @@ import ( "github.com/gofiber/fiber/v2" "github.com/stretchr/testify/assert" "testing" + "time" ) -const BaseUrl = "http://localhost:8080" +const ( + BaseUrl = "http://localhost:8080" + ValidSign = "GSiyv5zBITGshqnvYLHKtXE3e4yZjKGvruOVFWuUuj9Nvaps28-Zt6RDq9n47eaNUlay1-nUVld61I3xoAAgCA==65b286c2f13095d96792079d" +) // post handler func TestRecoveryHandler(t *testing.T) { @@ -89,3 +93,28 @@ func TestRecoveryHandler(t *testing.T) { } // 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") + }) +}