feat(platform): align account user membership
This commit is contained in:
@@ -97,6 +97,7 @@ func setupPlatformTokenTestE2E(t *testing.T) (*gin.Engine, *repository.Permissib
|
||||
// Gin wildcard constraint: nested routes under accounts/:id must reuse :id.
|
||||
platformGroup.GET("/accounts/:id/account_users", platformAccountUser.Index)
|
||||
platformGroup.POST("/accounts/:id/account_users", platformAccountUser.Create)
|
||||
platformGroup.DELETE("/accounts/:id/account_users/destroy", platformAccountUser.Destroy)
|
||||
platformGroup.DELETE("/accounts/:id/account_users/:user_id", platformAccountUser.Destroy)
|
||||
|
||||
return engine, permissibleRepo, userRepo, accountRepo
|
||||
@@ -403,7 +404,22 @@ func TestPlatformAccountUserE2E_Create(t *testing.T) {
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
engine.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(t, http.StatusCreated, w.Code)
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
var accountUser map[string]interface{}
|
||||
require.NoError(t, json.Unmarshal(w.Body.Bytes(), &accountUser))
|
||||
assert.Equal(t, "agent", accountUser["role"])
|
||||
assert.NotContains(t, accountUser, "success")
|
||||
|
||||
// Chatwoot find_or_initialize_by updates existing memberships instead of failing duplicates.
|
||||
acctUserBody = fmt.Sprintf(`{"user_id": %s, "role": "administrator"}`, userID)
|
||||
w = httptest.NewRecorder()
|
||||
req, _ = http.NewRequest("POST", "/platform/api/v1/accounts/"+accountID+"/account_users", bytes.NewBufferString(acctUserBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
engine.ServeHTTP(w, req)
|
||||
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
require.NoError(t, json.Unmarshal(w.Body.Bytes(), &accountUser))
|
||||
assert.Equal(t, "administrator", accountUser["role"])
|
||||
}
|
||||
|
||||
func TestPlatformAccountUserE2E_Index(t *testing.T) {
|
||||
@@ -435,12 +451,23 @@ func TestPlatformAccountUserE2E_Index(t *testing.T) {
|
||||
req, _ = http.NewRequest("POST", "/platform/api/v1/accounts/"+accountID+"/account_users", bytes.NewBufferString(acctUserBody))
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
engine.ServeHTTP(w, req)
|
||||
require.Equal(t, http.StatusCreated, w.Code)
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
|
||||
// Index account_users
|
||||
w = httptest.NewRecorder()
|
||||
req, _ = http.NewRequest("GET", "/platform/api/v1/accounts/"+accountID+"/account_users", nil)
|
||||
engine.ServeHTTP(w, req)
|
||||
|
||||
require.Equal(t, http.StatusOK, w.Code)
|
||||
var accountUsers []map[string]interface{}
|
||||
require.NoError(t, json.Unmarshal(w.Body.Bytes(), &accountUsers))
|
||||
require.Len(t, accountUsers, 1)
|
||||
assert.Equal(t, "agent", accountUsers[0]["role"])
|
||||
assert.NotContains(t, accountUsers[0], "success")
|
||||
|
||||
// Chatwoot destroy is a collection route: DELETE /account_users/destroy with user_id param.
|
||||
w = httptest.NewRecorder()
|
||||
req, _ = http.NewRequest("DELETE", "/platform/api/v1/accounts/"+accountID+"/account_users/destroy?user_id="+userID, nil)
|
||||
engine.ServeHTTP(w, req)
|
||||
assert.Equal(t, http.StatusOK, w.Code)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user