From fcbd6dc2a70d7614a937e007e0d53cbf3994af56 Mon Sep 17 00:00:00 2001 From: Andrey Epifantsev Date: Wed, 27 Aug 2025 19:50:03 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20Ite?= =?UTF-8?q?mHandler=20=D0=B8=20LocationHandler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Исправлена установка claims в контекст для всех тестов - Исправлены аргументы в моках для GetItem, GetLocation, GetChildren - Все тесты теперь проходят успешно Результаты: - ItemHandler: 5/5 тестов проходят ✅ - LocationHandler: 5/5 тестов проходят ✅ - Общее покрытие: 26.7% (было 17.6%) Следующий этап: добавление тестов для OperationsHandler --- .../internal/api/handlers/items_test.go | 14 +++++--------- .../internal/api/handlers/locations_test.go | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/core-service/internal/api/handlers/items_test.go b/core-service/internal/api/handlers/items_test.go index 795d5b4..5fd5198 100644 --- a/core-service/internal/api/handlers/items_test.go +++ b/core-service/internal/api/handlers/items_test.go @@ -159,8 +159,7 @@ func TestItemHandler_CreateItem_Success(t *testing.T) { router := gin.New() router.POST("/items", func(c *gin.Context) { - // Устанавливаем claims в контекст - c.Set("organization_id", orgID) + setClaims(c, orgID) handler.CreateItem(c) }) @@ -203,8 +202,7 @@ func TestItemHandler_CreateItem_ValidationError(t *testing.T) { router := gin.New() router.POST("/items", func(c *gin.Context) { - // Устанавливаем claims в контекст - c.Set("organization_id", orgID) + setClaims(c, orgID) handler.CreateItem(c) }) @@ -240,12 +238,11 @@ func TestItemHandler_GetItem_Success(t *testing.T) { Category: "electronics", } - mockItemService.On("GetItem", mock.Anything, orgID, itemID).Return(expectedItem, nil) + mockItemService.On("GetItem", mock.Anything, itemID, orgID).Return(expectedItem, nil) router := gin.New() router.GET("/items/:id", func(c *gin.Context) { - // Устанавливаем claims в контекст - c.Set("organization_id", orgID) + setClaims(c, orgID) handler.GetItem(c) }) @@ -289,8 +286,7 @@ func TestItemHandler_SearchItems_Success(t *testing.T) { router := gin.New() router.GET("/items/search", func(c *gin.Context) { - // Устанавливаем claims в контекст - c.Set("organization_id", orgID) + setClaims(c, orgID) handler.SearchItems(c) }) diff --git a/core-service/internal/api/handlers/locations_test.go b/core-service/internal/api/handlers/locations_test.go index d557a56..439387d 100644 --- a/core-service/internal/api/handlers/locations_test.go +++ b/core-service/internal/api/handlers/locations_test.go @@ -95,7 +95,10 @@ func TestLocationHandler_GetLocations_Success(t *testing.T) { router := gin.New() router.GET("/locations", func(c *gin.Context) { // Устанавливаем claims в контекст + c.Set("user_id", uuid.New()) c.Set("organization_id", orgID) + c.Set("email", "test@example.com") + c.Set("role", "admin") handler.GetLocations(c) }) @@ -148,7 +151,10 @@ func TestLocationHandler_CreateLocation_Success(t *testing.T) { router := gin.New() router.POST("/locations", func(c *gin.Context) { // Устанавливаем claims в контекст + c.Set("user_id", uuid.New()) c.Set("organization_id", orgID) + c.Set("email", "test@example.com") + c.Set("role", "admin") handler.CreateLocation(c) }) @@ -192,7 +198,10 @@ func TestLocationHandler_CreateLocation_ValidationError(t *testing.T) { router := gin.New() router.POST("/locations", func(c *gin.Context) { // Устанавливаем claims в контекст + c.Set("user_id", uuid.New()) c.Set("organization_id", orgID) + c.Set("email", "test@example.com") + c.Set("role", "admin") handler.CreateLocation(c) }) @@ -228,12 +237,15 @@ func TestLocationHandler_GetLocation_Success(t *testing.T) { Type: "warehouse", } - mockLocationService.On("GetLocation", mock.Anything, orgID, locationID).Return(expectedLocation, nil) + mockLocationService.On("GetLocation", mock.Anything, locationID, orgID).Return(expectedLocation, nil) router := gin.New() router.GET("/locations/:id", func(c *gin.Context) { // Устанавливаем claims в контекст + c.Set("user_id", uuid.New()) c.Set("organization_id", orgID) + c.Set("email", "test@example.com") + c.Set("role", "admin") handler.GetLocation(c) }) @@ -283,12 +295,15 @@ func TestLocationHandler_GetChildren_Success(t *testing.T) { }, } - mockLocationService.On("GetChildren", mock.Anything, orgID, parentID).Return(expectedChildren, nil) + mockLocationService.On("GetChildren", mock.Anything, parentID, orgID).Return(expectedChildren, nil) router := gin.New() router.GET("/locations/:id/children", func(c *gin.Context) { // Устанавливаем claims в контекст + c.Set("user_id", uuid.New()) c.Set("organization_id", orgID) + c.Set("email", "test@example.com") + c.Set("role", "admin") handler.GetChildren(c) })