feat(custom-roles): align update route semantics
This commit is contained in:
@@ -206,6 +206,7 @@ func RegisterCustomRoleRoutes(rg *gin.RouterGroup, h *CustomRoleHandler) {
|
||||
customRoles.GET("/", h.List)
|
||||
customRoles.POST("/", h.Create)
|
||||
customRoles.GET("/:id", h.Get)
|
||||
customRoles.PATCH("/:id", h.Update)
|
||||
customRoles.PUT("/:id", h.Update)
|
||||
customRoles.DELETE("/:id", h.Delete)
|
||||
}
|
||||
|
||||
@@ -167,19 +167,19 @@ func (s *CustomRoleHandlerTestSuite) TestGet_Success() {
|
||||
}
|
||||
|
||||
func (s *CustomRoleHandlerTestSuite) TestUpdate_Success() {
|
||||
role := &model.CustomRole{AccountID: s.account.ID, Name: "update-test-role", Permissions: `["report_manage"]`}
|
||||
role := &model.CustomRole{AccountID: s.account.ID, Name: "update-test-role", Description: "old description", Permissions: `["report_manage"]`}
|
||||
s.Require().NoError(s.db.Create(role).Error)
|
||||
|
||||
r := gin.New()
|
||||
r.PUT("/api/v1/accounts/:account_id/custom_roles/:id", func(c *gin.Context) {
|
||||
r.PATCH("/api/v1/accounts/:account_id/custom_roles/:id", func(c *gin.Context) {
|
||||
c.Set("account_id", uint(s.account.ID))
|
||||
c.Set("role", "administrator")
|
||||
s.handler.Update(c)
|
||||
})
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
body := `{"custom_role":{"name":"updated-role","permissions":["knowledge_base_manage"]}}`
|
||||
req, _ := http.NewRequest("PUT", fmt.Sprintf("/api/v1/accounts/%d/custom_roles/%d", s.account.ID, role.ID), bytes.NewBufferString(body))
|
||||
body := `{"custom_role":{"name":"updated-role","description":"","permissions":["knowledge_base_manage"]}}`
|
||||
req, _ := http.NewRequest("PATCH", fmt.Sprintf("/api/v1/accounts/%d/custom_roles/%d", s.account.ID, role.ID), bytes.NewBufferString(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
@@ -187,6 +187,7 @@ func (s *CustomRoleHandlerTestSuite) TestUpdate_Success() {
|
||||
var payload map[string]interface{}
|
||||
s.Require().NoError(json.Unmarshal(w.Body.Bytes(), &payload))
|
||||
s.Equal("updated-role", payload["name"])
|
||||
s.Equal("", payload["description"])
|
||||
s.Equal([]interface{}{"knowledge_base_manage"}, payload["permissions"])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user