update
This commit is contained in:
@@ -698,6 +698,63 @@ func (s *ArticleHandlerTestSuite) TestPatch_RawPayloadClearsDescription() {
|
||||
assert.Equal(s.T(), "", payload["description"])
|
||||
}
|
||||
|
||||
func (s *ArticleHandlerTestSuite) TestPatch_AcceptsChatwootNumericStatus() {
|
||||
article := &model.Article{AccountID: s.account.ID, PortalID: s.portal.ID, Title: "numeric-status-article", Slug: "numeric-status-article", Status: "draft"}
|
||||
s.Require().NoError(s.db.Create(article).Error)
|
||||
|
||||
r := gin.New()
|
||||
r.PATCH("/api/v1/accounts/:account_id/portals/:portal_id/articles/:article_id", s.handler.Update)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("PATCH", fmt.Sprintf("/api/v1/accounts/%d/portals/test-portal/articles/%d", s.account.ID, article.ID), bytes.NewBufferString(`{"status":1}`))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
var resp map[string]interface{}
|
||||
s.Require().NoError(json.Unmarshal(w.Body.Bytes(), &resp))
|
||||
payload := resp["payload"].(map[string]interface{})
|
||||
assert.Equal(s.T(), "published", payload["status"])
|
||||
|
||||
var updated model.Article
|
||||
s.Require().NoError(s.db.First(&updated, article.ID).Error)
|
||||
assert.Equal(s.T(), "published", updated.Status)
|
||||
}
|
||||
|
||||
func (s *ArticleHandlerTestSuite) TestList_AcceptsChatwootNumericStatusFilters() {
|
||||
for index, status := range []model.ArticleStatus{
|
||||
model.ArticleStatusDraft,
|
||||
model.ArticleStatusPublished,
|
||||
model.ArticleStatusArchived,
|
||||
} {
|
||||
article := &model.Article{
|
||||
AccountID: s.account.ID,
|
||||
PortalID: s.portal.ID,
|
||||
Title: fmt.Sprintf("numeric-filter-%d", index),
|
||||
Slug: fmt.Sprintf("numeric-filter-%d", index),
|
||||
Status: string(status),
|
||||
Locale: "en",
|
||||
}
|
||||
s.Require().NoError(s.db.Create(article).Error)
|
||||
}
|
||||
|
||||
r := gin.New()
|
||||
r.GET("/api/v1/accounts/:account_id/portals/:portal_id/articles", s.handler.List)
|
||||
|
||||
for statusCode, expectedStatus := range []string{"draft", "published", "archived"} {
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", fmt.Sprintf("/api/v1/accounts/%d/portals/test-portal/articles?locale=en&status=%d", s.account.ID, statusCode), nil)
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
var resp map[string]interface{}
|
||||
s.Require().NoError(json.Unmarshal(w.Body.Bytes(), &resp))
|
||||
payload := resp["payload"].([]interface{})
|
||||
s.Require().Len(payload, 1)
|
||||
assert.Equal(s.T(), expectedStatus, payload[0].(map[string]interface{})["status"])
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ArticleHandlerTestSuite) TestDelete_ReturnsEmptyOK() {
|
||||
article := &model.Article{AccountID: s.account.ID, PortalID: s.portal.ID, Title: "delete-article", Slug: "delete-article", Status: "draft"}
|
||||
s.Require().NoError(s.db.Create(article).Error)
|
||||
|
||||
Reference in New Issue
Block a user