From 942696e27ddd2128b3a91cb20708f536b9dfef2a Mon Sep 17 00:00:00 2001 From: kayra1 Date: Fri, 26 Jul 2024 11:30:57 +0300 Subject: [PATCH] update tests and fix 1 bug --- internal/api/handlers.go | 8 +++++--- internal/api/handlers_test.go | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/api/handlers.go b/internal/api/handlers.go index a9749ee..4a68329 100644 --- a/internal/api/handlers.go +++ b/internal/api/handlers.go @@ -415,11 +415,13 @@ func DeleteUserAccount(env *Environment) http.HandlerFunc { id := r.PathValue("id") user, err := env.DB.RetrieveUser(id) if err != nil { - logErrorAndWriteResponse("error occured while processing request", http.StatusInternalServerError, w) - return + if !errors.Is(err, certdb.ErrIdNotFound) { + logErrorAndWriteResponse(err.Error(), http.StatusInternalServerError, w) + return + } } if user.Permissions == 1 { - logErrorAndWriteResponse("Deleting an Admin account is not allowed.", http.StatusBadRequest, w) + logErrorAndWriteResponse("deleting an Admin account is not allowed.", http.StatusBadRequest, w) return } insertId, err := env.DB.DeleteUser(id) diff --git a/internal/api/handlers_test.go b/internal/api/handlers_test.go index 8e0eb33..7635abe 100644 --- a/internal/api/handlers_test.go +++ b/internal/api/handlers_test.go @@ -761,8 +761,8 @@ func TestAuthorization(t *testing.T) { path: "/api/v1/accounts/1", data: "", auth: adminToken, - response: "error: can't delete admin account", - status: http.StatusConflict, + response: "error: deleting an Admin account is not allowed.", + status: http.StatusBadRequest, }, { desc: "admin can delete nonuser",