feat(accounts): serialize enabled features
This commit is contained in:
@@ -199,6 +199,46 @@ func (s *AccountHandlerTestSuite) TestGet_Success() {
|
||||
assert.Contains(s.T(), resp, "cache_keys")
|
||||
}
|
||||
|
||||
func (s *AccountHandlerTestSuite) TestGet_FeaturesUseChatwootEnabledFeatures() {
|
||||
acc := &model.Account{
|
||||
Name: "Feature Account",
|
||||
Active: true,
|
||||
Status: "active",
|
||||
FeatureFlags: `{"crm_v2":true,"sla":false,"crm":false}`,
|
||||
}
|
||||
s.Require().NoError(s.db.Create(acc).Error)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/api/v1/accounts/"+strconv.FormatUint(uint64(acc.ID), 10), nil)
|
||||
s.router.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
resp := s.unmarshalResponse(w)
|
||||
features := resp["features"].(map[string]interface{})
|
||||
assert.Equal(s.T(), true, features["crm_v2"])
|
||||
assert.Equal(s.T(), true, features["channel_email"])
|
||||
assert.Equal(s.T(), true, features["assignment_v2"])
|
||||
assert.NotContains(s.T(), features, "sla")
|
||||
assert.NotContains(s.T(), features, "crm")
|
||||
}
|
||||
|
||||
func (s *AccountHandlerTestSuite) TestGet_DefaultFeaturesMatchChatwootDefaults() {
|
||||
acc := s.seedAccount("Default Feature Account")
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/api/v1/accounts/"+strconv.FormatUint(uint64(acc.ID), 10), nil)
|
||||
s.router.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(s.T(), http.StatusOK, w.Code)
|
||||
resp := s.unmarshalResponse(w)
|
||||
features := resp["features"].(map[string]interface{})
|
||||
assert.Equal(s.T(), true, features["crm"])
|
||||
assert.Equal(s.T(), true, features["macros"])
|
||||
assert.Equal(s.T(), true, features["captain_tasks"])
|
||||
assert.NotContains(s.T(), features, "crm_v2")
|
||||
assert.NotContains(s.T(), features, "sla")
|
||||
}
|
||||
|
||||
func (s *AccountHandlerTestSuite) TestGet_NotFound() {
|
||||
w := httptest.NewRecorder()
|
||||
req, _ := http.NewRequest("GET", "/api/v1/accounts/99999", nil)
|
||||
|
||||
Reference in New Issue
Block a user