Align GoChat with Chatwoot frontend contracts
This commit is contained in:
@@ -135,6 +135,53 @@ func (s *IntegrationHookHandlerSuite) TestListApps_Empty() {
|
||||
s.Len(data, 0)
|
||||
}
|
||||
|
||||
func (s *IntegrationHookHandlerSuite) TestChatwootFrontendAppsAndHooksNoTrailingSlashPayloads() {
|
||||
s.createApp("Webhook App", model.HookTypeWebhook)
|
||||
|
||||
appsRecorder := httptest.NewRecorder()
|
||||
appsReq, _ := http.NewRequest(http.MethodGet, "/api/v1/accounts/1/integrations/apps", nil)
|
||||
s.router.ServeHTTP(appsRecorder, appsReq)
|
||||
s.Equal(http.StatusOK, appsRecorder.Code)
|
||||
|
||||
var appsBody map[string]interface{}
|
||||
s.Require().NoError(json.Unmarshal(appsRecorder.Body.Bytes(), &appsBody))
|
||||
apps := appsBody["payload"].([]interface{})
|
||||
s.Require().Len(apps, 1)
|
||||
app := apps[0].(map[string]interface{})
|
||||
s.Equal("webhook", app["id"])
|
||||
s.Equal("Webhook App", app["name"])
|
||||
s.Equal("account", app["hook_type"])
|
||||
s.Contains(app, "hooks")
|
||||
|
||||
createBody, _ := json.Marshal(map[string]interface{}{
|
||||
"app_id": "webhook",
|
||||
"settings": map[string]interface{}{
|
||||
"project_id": "chatwoot-front-end",
|
||||
},
|
||||
})
|
||||
createRecorder := httptest.NewRecorder()
|
||||
createReq, _ := http.NewRequest(http.MethodPost, "/api/v1/accounts/1/integrations/hooks", bytes.NewBuffer(createBody))
|
||||
createReq.Header.Set("Content-Type", "application/json")
|
||||
s.router.ServeHTTP(createRecorder, createReq)
|
||||
s.Equal(http.StatusOK, createRecorder.Code)
|
||||
|
||||
var created map[string]interface{}
|
||||
s.Require().NoError(json.Unmarshal(createRecorder.Body.Bytes(), &created))
|
||||
s.Equal("webhook", created["app_id"])
|
||||
s.Equal("account", created["hook_type"])
|
||||
s.Equal(true, created["status"])
|
||||
settings := created["settings"].(map[string]interface{})
|
||||
s.Equal("chatwoot-front-end", settings["project_id"])
|
||||
s.NotContains(created, "success")
|
||||
|
||||
hookID := strconv.FormatUint(uint64(created["id"].(float64)), 10)
|
||||
deleteRecorder := httptest.NewRecorder()
|
||||
deleteReq, _ := http.NewRequest(http.MethodDelete, "/api/v1/accounts/1/integrations/hooks/"+hookID, nil)
|
||||
s.router.ServeHTTP(deleteRecorder, deleteReq)
|
||||
s.Equal(http.StatusOK, deleteRecorder.Code)
|
||||
s.Empty(deleteRecorder.Body.String())
|
||||
}
|
||||
|
||||
// =====================
|
||||
// GetApp tests
|
||||
// =====================
|
||||
|
||||
Reference in New Issue
Block a user