From 84fc14679b64884ee07fc3d0a575785ebc8c71a4 Mon Sep 17 00:00:00 2001 From: Geno Date: Wed, 23 Jun 2021 14:32:19 +0200 Subject: [PATCH] test(web/auth): improve password --- web/auth/api_password.go | 9 ++------- web/auth/api_password_test.go | 7 ++++++- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/web/auth/api_password.go b/web/auth/api_password.go index 5fea3b4..e849450 100644 --- a/web/auth/api_password.go +++ b/web/auth/api_password.go @@ -3,7 +3,6 @@ package auth import ( "net/http" - "github.com/bdlm/log" "github.com/gin-gonic/gin" "dev.sum7.eu/genofire/golang-lib/web" @@ -43,19 +42,15 @@ func init() { return } - result := ws.DB.Save(&d) - if err := result.Error; err != nil { + if err := ws.DB.Save(&d).Error; err != nil { c.JSON(http.StatusInternalServerError, web.HTTPError{ Message: web.APIErrorInternalDatabase, Error: err.Error(), }) return } - if result.RowsAffected > 1 { - log.Panicf("there should not be more then 1 user with the same email, it was %d session", result.RowsAffected) - } - c.JSON(http.StatusOK, result.RowsAffected == 1) + c.JSON(http.StatusOK, true) }) }) } diff --git a/web/auth/api_password_test.go b/web/auth/api_password_test.go index 759dd2e..4af6681 100644 --- a/web/auth/api_password_test.go +++ b/web/auth/api_password_test.go @@ -21,12 +21,17 @@ func TestAPIPassword(t *testing.T) { passwordNew := "test" hErr := web.HTTPError{} - // invalid + // no auth s.Request(http.MethodPost, "/api/v1/my/auth/password", &passwordNew, http.StatusUnauthorized, &hErr) assert.Equal(APIErrorNoSession, hErr.Message) s.TestLogin() + hErr = web.HTTPError{} + // invalid + s.Request(http.MethodPost, "/api/v1/my/auth/password", nil, http.StatusBadRequest, &hErr) + assert.Equal(web.APIErrorInvalidRequestFormat, hErr.Message) + res := false // set new password s.Request(http.MethodPost, "/api/v1/my/auth/password", &passwordNew, http.StatusOK, &res)