feat(conversations): align toggle status fallback
This commit is contained in:
@@ -2,6 +2,7 @@ package v1
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -297,9 +298,11 @@ func (h *ConversationHandler) ToggleStatus(c *gin.Context) {
|
||||
}
|
||||
|
||||
var req service.ToggleStatusRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, err.Error())
|
||||
return
|
||||
if c.Request.Body != nil && c.Request.Body != http.NoBody {
|
||||
if err := c.ShouldBindJSON(&req); err != nil && !errors.Is(err, io.EOF) {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
conversation, ok := h.resolveConversationRoute(c, accountID, conversationID)
|
||||
|
||||
@@ -702,6 +702,45 @@ func (s *ConversationCrudTestSuite) TestToggleStatus_Success() {
|
||||
assert.Equal(s.T(), "resolved", resp.Payload.CurrentStatus)
|
||||
}
|
||||
|
||||
func (s *ConversationCrudTestSuite) TestToggleStatus_NoStatusTogglesLikeChatwoot() {
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("POST", s.convURL(s.testConv.ID)+"/toggle_status", nil)
|
||||
s.router.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
|
||||
var resp struct {
|
||||
Payload struct {
|
||||
Success bool `json:"success"`
|
||||
CurrentStatus string `json:"current_status"`
|
||||
} `json:"payload"`
|
||||
}
|
||||
err := json.Unmarshal(w.Body.Bytes(), &resp)
|
||||
assert.NoError(s.T(), err)
|
||||
assert.True(s.T(), resp.Payload.Success)
|
||||
assert.Equal(s.T(), "resolved", resp.Payload.CurrentStatus)
|
||||
}
|
||||
|
||||
func (s *ConversationCrudTestSuite) TestToggleStatus_NoStatusReopensPendingLikeChatwoot() {
|
||||
s.Require().NoError(s.db.Model(&model.Conversation{}).Where("id = ?", s.testConv.ID).Update("status", "pending").Error)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("POST", s.convURL(s.testConv.ID)+"/toggle_status", bytes.NewReader([]byte(`{}`)))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
s.router.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
|
||||
var resp struct {
|
||||
Payload struct {
|
||||
CurrentStatus string `json:"current_status"`
|
||||
} `json:"payload"`
|
||||
}
|
||||
err := json.Unmarshal(w.Body.Bytes(), &resp)
|
||||
assert.NoError(s.T(), err)
|
||||
assert.Equal(s.T(), "open", resp.Payload.CurrentStatus)
|
||||
}
|
||||
|
||||
func (s *ConversationCrudTestSuite) TestToggleStatus_InvalidAccountID() {
|
||||
body, _ := json.Marshal(map[string]interface{}{
|
||||
"status": "resolved",
|
||||
|
||||
Reference in New Issue
Block a user