Align GoChat with Chatwoot frontend contracts
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user