Align GoChat with Chatwoot frontend contracts

This commit is contained in:
2026-06-13 22:13:32 +08:00
parent 71abf58636
commit d884fdda0a
162 changed files with 9825 additions and 528 deletions
+21 -1
View File
@@ -98,6 +98,26 @@ func TestAuthMiddleware_ValidToken(t *testing.T) {
assert.Equal(t, 200, w.Code)
}
func TestAuthMiddleware_ChatwootAccessTokenHeader(t *testing.T) {
gin.SetMode(gin.TestMode)
cfg := makeJWTConfig()
r := gin.New()
r.Use(AuthMiddleware(cfg))
r.GET("/test", func(c *gin.Context) {
userID, _ := c.Get("user_id")
accountID, _ := c.Get("account_id")
c.JSON(200, gin.H{"user_id": userID, "account_id": accountID})
})
token := makeValidAccessToken(cfg)
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/test", nil)
req.Header.Set("access-token", token)
r.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
}
func TestAuthMiddleware_FallbackHeaders(t *testing.T) {
gin.SetMode(gin.TestMode)
cfg := makeJWTConfig()
@@ -155,4 +175,4 @@ func TestGenerateToken(t *testing.T) {
tokenString, err := GenerateToken(cfg, 1, 2, "agent")
assert.NoError(t, err)
assert.NotEmpty(t, tokenString)
}
}