feat(teams): align frontend update routes
This commit is contained in:
@@ -160,6 +160,31 @@ func (s *TeamHandlerTestSuite) TestUpdate_Success() {
|
||||
assert.Equal(s.T(), false, payload["allow_auto_assign"])
|
||||
}
|
||||
|
||||
func (s *TeamHandlerTestSuite) TestUpdate_PatchRawPayloadSuccess() {
|
||||
team := &model.Team{AccountID: s.account.ID, Name: "patch-test-team", AllowAutoAssignment: true}
|
||||
s.Require().NoError(s.db.Create(team).Error)
|
||||
|
||||
r := gin.New()
|
||||
r.PATCH("/api/v1/accounts/:account_id/teams/:team_id", func(c *gin.Context) {
|
||||
s.authMiddleware(c)
|
||||
s.handler.Update(c)
|
||||
})
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
body := `{"name":"patched-team","description":"patched description","allow_auto_assign":false}`
|
||||
req, _ := http.NewRequest("PATCH", fmt.Sprintf("/api/v1/accounts/%d/teams/%d", s.account.ID, team.ID), bytes.NewBufferString(body))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
var payload map[string]any
|
||||
assert.NoError(s.T(), json.Unmarshal(w.Body.Bytes(), &payload))
|
||||
assert.NotContains(s.T(), payload, "success")
|
||||
assert.NotContains(s.T(), payload, "data")
|
||||
assert.Equal(s.T(), "patched-team", payload["name"])
|
||||
assert.Equal(s.T(), false, payload["allow_auto_assign"])
|
||||
}
|
||||
|
||||
func (s *TeamHandlerTestSuite) TestDelete_Success() {
|
||||
team := &model.Team{AccountID: s.account.ID, Name: "delete-test-team"}
|
||||
s.Require().NoError(s.db.Create(team).Error)
|
||||
|
||||
@@ -1138,17 +1138,24 @@ func registerV1Routes(g *gin.RouterGroup, h *Handlers) {
|
||||
// Team routes (ref: Chatwoot resources :teams)
|
||||
teams := accountScoped.Group("/teams")
|
||||
{
|
||||
teams.GET("", h.Team.List)
|
||||
teams.GET("/", h.Team.List)
|
||||
teams.POST("", h.Team.Create)
|
||||
teams.POST("/", h.Team.Create)
|
||||
teams.GET("/:team_id", h.Team.Get)
|
||||
teams.PATCH("/:team_id", h.Team.Update)
|
||||
teams.PUT("/:team_id", h.Team.Update)
|
||||
teams.DELETE("/:team_id", h.Team.Delete)
|
||||
// Team members (ref: Chatwoot nested resources :team_members)
|
||||
teamMembers := teams.Group("/:team_id/team_members")
|
||||
{
|
||||
teamMembers.GET("", h.Team.ListMembers)
|
||||
teamMembers.GET("/", h.Team.ListMembers)
|
||||
teamMembers.POST("", h.Team.AddMembers)
|
||||
teamMembers.POST("/", h.Team.AddMembers)
|
||||
teamMembers.PATCH("", h.Team.UpdateMembers)
|
||||
teamMembers.PATCH("/", h.Team.UpdateMembers)
|
||||
teamMembers.DELETE("", h.Team.RemoveMembers)
|
||||
teamMembers.DELETE("/", h.Team.RemoveMembers)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user