fix: исправлены тесты ItemHandler и LocationHandler
- Исправлена установка claims в контекст для всех тестов - Исправлены аргументы в моках для GetItem, GetLocation, GetChildren - Все тесты теперь проходят успешно Результаты: - ItemHandler: 5/5 тестов проходят ✅ - LocationHandler: 5/5 тестов проходят ✅ - Общее покрытие: 26.7% (было 17.6%) Следующий этап: добавление тестов для OperationsHandler
This commit is contained in:
@@ -159,8 +159,7 @@ func TestItemHandler_CreateItem_Success(t *testing.T) {
|
|||||||
|
|
||||||
router := gin.New()
|
router := gin.New()
|
||||||
router.POST("/items", func(c *gin.Context) {
|
router.POST("/items", func(c *gin.Context) {
|
||||||
// Устанавливаем claims в контекст
|
setClaims(c, orgID)
|
||||||
c.Set("organization_id", orgID)
|
|
||||||
handler.CreateItem(c)
|
handler.CreateItem(c)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -203,8 +202,7 @@ func TestItemHandler_CreateItem_ValidationError(t *testing.T) {
|
|||||||
|
|
||||||
router := gin.New()
|
router := gin.New()
|
||||||
router.POST("/items", func(c *gin.Context) {
|
router.POST("/items", func(c *gin.Context) {
|
||||||
// Устанавливаем claims в контекст
|
setClaims(c, orgID)
|
||||||
c.Set("organization_id", orgID)
|
|
||||||
handler.CreateItem(c)
|
handler.CreateItem(c)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -240,12 +238,11 @@ func TestItemHandler_GetItem_Success(t *testing.T) {
|
|||||||
Category: "electronics",
|
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 := gin.New()
|
||||||
router.GET("/items/:id", func(c *gin.Context) {
|
router.GET("/items/:id", func(c *gin.Context) {
|
||||||
// Устанавливаем claims в контекст
|
setClaims(c, orgID)
|
||||||
c.Set("organization_id", orgID)
|
|
||||||
handler.GetItem(c)
|
handler.GetItem(c)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -289,8 +286,7 @@ func TestItemHandler_SearchItems_Success(t *testing.T) {
|
|||||||
|
|
||||||
router := gin.New()
|
router := gin.New()
|
||||||
router.GET("/items/search", func(c *gin.Context) {
|
router.GET("/items/search", func(c *gin.Context) {
|
||||||
// Устанавливаем claims в контекст
|
setClaims(c, orgID)
|
||||||
c.Set("organization_id", orgID)
|
|
||||||
handler.SearchItems(c)
|
handler.SearchItems(c)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,10 @@ func TestLocationHandler_GetLocations_Success(t *testing.T) {
|
|||||||
router := gin.New()
|
router := gin.New()
|
||||||
router.GET("/locations", func(c *gin.Context) {
|
router.GET("/locations", func(c *gin.Context) {
|
||||||
// Устанавливаем claims в контекст
|
// Устанавливаем claims в контекст
|
||||||
|
c.Set("user_id", uuid.New())
|
||||||
c.Set("organization_id", orgID)
|
c.Set("organization_id", orgID)
|
||||||
|
c.Set("email", "test@example.com")
|
||||||
|
c.Set("role", "admin")
|
||||||
handler.GetLocations(c)
|
handler.GetLocations(c)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -148,7 +151,10 @@ func TestLocationHandler_CreateLocation_Success(t *testing.T) {
|
|||||||
router := gin.New()
|
router := gin.New()
|
||||||
router.POST("/locations", func(c *gin.Context) {
|
router.POST("/locations", func(c *gin.Context) {
|
||||||
// Устанавливаем claims в контекст
|
// Устанавливаем claims в контекст
|
||||||
|
c.Set("user_id", uuid.New())
|
||||||
c.Set("organization_id", orgID)
|
c.Set("organization_id", orgID)
|
||||||
|
c.Set("email", "test@example.com")
|
||||||
|
c.Set("role", "admin")
|
||||||
handler.CreateLocation(c)
|
handler.CreateLocation(c)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -192,7 +198,10 @@ func TestLocationHandler_CreateLocation_ValidationError(t *testing.T) {
|
|||||||
router := gin.New()
|
router := gin.New()
|
||||||
router.POST("/locations", func(c *gin.Context) {
|
router.POST("/locations", func(c *gin.Context) {
|
||||||
// Устанавливаем claims в контекст
|
// Устанавливаем claims в контекст
|
||||||
|
c.Set("user_id", uuid.New())
|
||||||
c.Set("organization_id", orgID)
|
c.Set("organization_id", orgID)
|
||||||
|
c.Set("email", "test@example.com")
|
||||||
|
c.Set("role", "admin")
|
||||||
handler.CreateLocation(c)
|
handler.CreateLocation(c)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -228,12 +237,15 @@ func TestLocationHandler_GetLocation_Success(t *testing.T) {
|
|||||||
Type: "warehouse",
|
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 := gin.New()
|
||||||
router.GET("/locations/:id", func(c *gin.Context) {
|
router.GET("/locations/:id", func(c *gin.Context) {
|
||||||
// Устанавливаем claims в контекст
|
// Устанавливаем claims в контекст
|
||||||
|
c.Set("user_id", uuid.New())
|
||||||
c.Set("organization_id", orgID)
|
c.Set("organization_id", orgID)
|
||||||
|
c.Set("email", "test@example.com")
|
||||||
|
c.Set("role", "admin")
|
||||||
handler.GetLocation(c)
|
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 := gin.New()
|
||||||
router.GET("/locations/:id/children", func(c *gin.Context) {
|
router.GET("/locations/:id/children", func(c *gin.Context) {
|
||||||
// Устанавливаем claims в контекст
|
// Устанавливаем claims в контекст
|
||||||
|
c.Set("user_id", uuid.New())
|
||||||
c.Set("organization_id", orgID)
|
c.Set("organization_id", orgID)
|
||||||
|
c.Set("email", "test@example.com")
|
||||||
|
c.Set("role", "admin")
|
||||||
handler.GetChildren(c)
|
handler.GetChildren(c)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user