fix: stabilize development config and account settings

This commit is contained in:
2026-07-11 17:15:38 +08:00
parent d2cb6bbbc6
commit 7f2d5579ff
19 changed files with 607 additions and 392 deletions
@@ -454,7 +454,7 @@ func serializeAccountSettings(account *model.Account) map[string]any {
"auto_resolve_duration": account.AutoResolveDuration,
"auto_resolve_message": "",
"auto_resolve_ignore_waiting": false,
"audio_transcriptions": false,
"audio_transcriptions": account.AudioTranscriptions,
"auto_resolve_label": "",
"reporting_timezone": account.ReportingTimezone,
}
@@ -82,6 +82,7 @@ func (s *AccountHandlerTestSuite) SetupSuite() {
accountsGroup.GET("", s.handler.List)
accountsGroup.GET("/:account_id", s.handler.Get)
accountsGroup.POST("", s.handler.Create)
accountsGroup.PATCH("/:account_id", s.handler.Update)
accountsGroup.PUT("/:account_id", s.handler.Update)
accountsGroup.PATCH("/:account_id/onboarding", s.handler.UpdateOnboarding)
accountsGroup.DELETE("/:account_id", s.handler.Delete)
@@ -313,6 +314,55 @@ func (s *AccountHandlerTestSuite) TestUpdate_Success() {
assert.Equal(s.T(), "After Update", resp["name"])
}
func (s *AccountHandlerTestSuite) TestPatchUpdate_AudioTranscriptions() {
acc := s.seedAccount("Audio Transcription Account")
body := `{"audio_transcriptions":true}`
w := httptest.NewRecorder()
req, _ := http.NewRequest("PATCH", "/api/v1/accounts/"+strconv.FormatUint(uint64(acc.ID), 10), bytes.NewBufferString(body))
req.Header.Set("Content-Type", "application/json")
s.router.ServeHTTP(w, req)
assert.Equal(s.T(), http.StatusOK, w.Code)
resp := s.unmarshalResponse(w)
settings := resp["settings"].(map[string]interface{})
assert.Equal(s.T(), true, settings["audio_transcriptions"])
var stored model.Account
require.NoError(s.T(), s.db.First(&stored, acc.ID).Error)
assert.True(s.T(), stored.AudioTranscriptions)
body = `{"audio_transcriptions":false}`
w = httptest.NewRecorder()
req, _ = http.NewRequest("PATCH", "/api/v1/accounts/"+strconv.FormatUint(uint64(acc.ID), 10), bytes.NewBufferString(body))
req.Header.Set("Content-Type", "application/json")
s.router.ServeHTTP(w, req)
assert.Equal(s.T(), http.StatusOK, w.Code)
require.NoError(s.T(), s.db.First(&stored, acc.ID).Error)
assert.False(s.T(), stored.AudioTranscriptions)
}
func (s *AccountHandlerTestSuite) TestPatchUpdate_ChatwootGeneralSettingsPayload() {
acc := s.seedAccount("Test Account")
body := `{"locale":"zh_CN","name":"Test Account11","domain":"","support_email":null}`
w := httptest.NewRecorder()
req, _ := http.NewRequest("PATCH", "/api/v1/accounts/"+strconv.FormatUint(uint64(acc.ID), 10), bytes.NewBufferString(body))
req.Header.Set("Content-Type", "application/json")
s.router.ServeHTTP(w, req)
assert.Equal(s.T(), http.StatusOK, w.Code)
resp := s.unmarshalResponse(w)
assert.Equal(s.T(), "zh_CN", resp["locale"])
assert.Equal(s.T(), "Test Account11", resp["name"])
var stored model.Account
require.NoError(s.T(), s.db.First(&stored, acc.ID).Error)
assert.Equal(s.T(), "zh_CN", stored.Locale)
assert.Equal(s.T(), "Test Account11", stored.Name)
}
func (s *AccountHandlerTestSuite) TestUpdateOnboarding_FinalizesAccountDetails() {
acc := &model.Account{Name: "Before Onboarding", Active: true, Status: "active", OnboardingStep: "account_details"}
s.Require().NoError(acc.SetCustomAttributesMap(map[string]any{