feat(agents): align update route semantics
This commit is contained in:
@@ -196,9 +196,10 @@ func (s *AgentHandlerTestSuite) TestGetAgentNotFound() {
|
||||
func (s *AgentHandlerTestSuite) TestUpdateAgent() {
|
||||
// Create an agent
|
||||
req := service.CreateAgentRequest{
|
||||
Email: "agent4@test.com",
|
||||
Name: "Agent Four",
|
||||
Role: "agent",
|
||||
Email: "agent4@test.com",
|
||||
Name: "Agent Four",
|
||||
Role: "agent",
|
||||
AutoOffline: true,
|
||||
}
|
||||
w, c := s.makeRequest("POST", "/api/v1/accounts/1/agents", req, s.account.ID, s.user.ID)
|
||||
s.handler.Create(c)
|
||||
@@ -209,12 +210,14 @@ func (s *AgentHandlerTestSuite) TestUpdateAgent() {
|
||||
agentID := uint(data["id"].(float64))
|
||||
|
||||
// Update the agent
|
||||
updateReq := service.UpdateAgentRequest{
|
||||
Name: "Updated Name",
|
||||
Role: "administrator",
|
||||
Availability: "online",
|
||||
updateReq := map[string]any{
|
||||
"agent": map[string]any{
|
||||
"name": "Updated Name",
|
||||
"role": "administrator",
|
||||
"availability": "online",
|
||||
},
|
||||
}
|
||||
w2, c2 := s.makeRequest("PUT", fmt.Sprintf("/api/v1/accounts/1/agents/%d", agentID), updateReq, s.account.ID, s.user.ID)
|
||||
w2, c2 := s.makeRequest("PATCH", fmt.Sprintf("/api/v1/accounts/1/agents/%d", agentID), updateReq, s.account.ID, s.user.ID)
|
||||
c2.Params = append(c2.Params, gin.Param{Key: "id", Value: fmt.Sprintf("%d", agentID)})
|
||||
s.handler.Update(c2)
|
||||
|
||||
@@ -224,6 +227,21 @@ func (s *AgentHandlerTestSuite) TestUpdateAgent() {
|
||||
assert.Equal(s.T(), "Updated Name", updateData["name"])
|
||||
assert.Equal(s.T(), "administrator", updateData["role"])
|
||||
assert.Equal(s.T(), "online", updateData["availability_status"])
|
||||
assert.Equal(s.T(), true, updateData["auto_offline"])
|
||||
|
||||
// Explicit false should still update, matching Rails compact semantics.
|
||||
disableReq := map[string]any{
|
||||
"agent": map[string]any{
|
||||
"auto_offline": false,
|
||||
},
|
||||
}
|
||||
w3, c3 := s.makeRequest("PATCH", fmt.Sprintf("/api/v1/accounts/1/agents/%d", agentID), disableReq, s.account.ID, s.user.ID)
|
||||
s.handler.Update(c3)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w3.Code)
|
||||
var disableData map[string]interface{}
|
||||
json.Unmarshal(w3.Body.Bytes(), &disableData)
|
||||
assert.Equal(s.T(), false, disableData["auto_offline"])
|
||||
}
|
||||
|
||||
func (s *AgentHandlerTestSuite) TestDeleteAgent() {
|
||||
|
||||
Reference in New Issue
Block a user