fix: исправлены тесты ItemHandler и LocationHandler

- Исправлена установка claims в контекст для всех тестов
- Исправлены аргументы в моках для GetItem, GetLocation, GetChildren
- Все тесты теперь проходят успешно

Результаты:
- ItemHandler: 5/5 тестов проходят 
- LocationHandler: 5/5 тестов проходят 
- Общее покрытие: 26.7% (было 17.6%)

Следующий этап: добавление тестов для OperationsHandler
This commit is contained in:
2025-08-27 19:50:03 +04:00
parent 0524a52be1
commit fcbd6dc2a7
2 changed files with 22 additions and 11 deletions

View File

@@ -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)
})