feat(conversations): align transcript responses
This commit is contained in:
@@ -687,12 +687,16 @@ func (h *ConversationHandler) Transcript(c *gin.Context) {
|
||||
}
|
||||
|
||||
var req struct {
|
||||
Email string `json:"email" binding:"required,email"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.AbortWithStatusError(c, http.StatusBadRequest, response.ErrValidation, err.Error())
|
||||
return
|
||||
}
|
||||
if strings.TrimSpace(req.Email) == "" {
|
||||
c.JSON(http.StatusUnprocessableEntity, gin.H{"error": "email param missing"})
|
||||
return
|
||||
}
|
||||
|
||||
conversation, ok := h.resolveConversationRoute(c, accountID, conversationID)
|
||||
if !ok {
|
||||
@@ -703,7 +707,7 @@ func (h *ConversationHandler) Transcript(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
response.OK(c, nil)
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
// UpdateCustomAttributes updates the custom attributes of a conversation.
|
||||
|
||||
@@ -255,14 +255,7 @@ func (s *ConversationHandlerTestSuite) TestTranscript_Success() {
|
||||
s.router.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
|
||||
var resp struct {
|
||||
Success bool `json:"success"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
err := json.Unmarshal(w.Body.Bytes(), &resp)
|
||||
assert.NoError(s.T(), err)
|
||||
assert.True(s.T(), resp.Success)
|
||||
assert.Empty(s.T(), w.Body.String())
|
||||
}
|
||||
|
||||
func (s *ConversationHandlerTestSuite) TestTranscript_InvalidAccountID() {
|
||||
@@ -286,8 +279,11 @@ func (s *ConversationHandlerTestSuite) TestTranscript_MissingEmail() {
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
s.router.ServeHTTP(w, req)
|
||||
|
||||
// ShouldBindJSON fails when required field is missing
|
||||
assert.Equal(s.T(), http.StatusBadRequest, w.Code)
|
||||
assert.Equal(s.T(), http.StatusUnprocessableEntity, w.Code)
|
||||
var resp map[string]interface{}
|
||||
err := json.Unmarshal(w.Body.Bytes(), &resp)
|
||||
assert.NoError(s.T(), err)
|
||||
assert.Equal(s.T(), "email param missing", resp["error"])
|
||||
}
|
||||
|
||||
func (s *ConversationHandlerTestSuite) TestTranscript_InvalidEmail() {
|
||||
@@ -299,8 +295,8 @@ func (s *ConversationHandlerTestSuite) TestTranscript_InvalidEmail() {
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
s.router.ServeHTTP(w, req)
|
||||
|
||||
// email validation fails via binding:"required,email"
|
||||
assert.Equal(s.T(), http.StatusBadRequest, w.Code)
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
assert.Empty(s.T(), w.Body.String())
|
||||
}
|
||||
|
||||
func (s *ConversationHandlerTestSuite) TestTranscript_ConversationNotFound() {
|
||||
|
||||
Reference in New Issue
Block a user