feat(agents): align duplicate create errors

This commit is contained in:
2026-06-06 02:31:02 +08:00
parent dd2bdee470
commit 8b30cc78a0
3 changed files with 16 additions and 7 deletions
@@ -190,10 +190,14 @@ func (s *AgentHandlerTestSuite) TestCreateAgentDuplicate() {
s.handler.Create(c)
assert.Equal(s.T(), http.StatusOK, w.Code)
// Try creating again — should conflict
// Try creating again — Chatwoot renders ActiveRecord::RecordInvalid as 422.
w2, c2 := s.makeRequest("POST", "/api/v1/accounts/1/agents", req, s.account.ID, s.user.ID)
s.handler.Create(c2)
assert.Equal(s.T(), http.StatusConflict, w2.Code)
assert.Equal(s.T(), http.StatusUnprocessableEntity, w2.Code)
var data map[string]interface{}
json.Unmarshal(w2.Body.Bytes(), &data)
assert.Equal(s.T(), "User has already been taken", data["message"])
assert.Equal(s.T(), []interface{}{"user_id"}, data["attributes"])
}
func (s *AgentHandlerTestSuite) TestCreateAgentValidation() {