mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
Remove extra argument
This commit is contained in:
@@ -35,7 +35,7 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
t.Run("user management", func(t *testing.T) {
|
||||
t.Run("list users", func(t *testing.T) {
|
||||
// Test with admin session
|
||||
rr := h.makeRequest(t, http.MethodGet, "/api/v1/admin/users", nil, h.AdminSession, nil)
|
||||
rr := h.makeRequest(t, http.MethodGet, "/api/v1/admin/users", nil, h.AdminSession)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
var users []*models.User
|
||||
@@ -48,11 +48,11 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
assert.True(t, containsUser(users, h.RegularUser), "Regular user not found in users list")
|
||||
|
||||
// Test with non-admin session
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/users", nil, h.RegularSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/users", nil, h.RegularSession)
|
||||
assert.Equal(t, http.StatusForbidden, rr.Code)
|
||||
|
||||
// Test without session
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/users", nil, nil, nil)
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/users", nil, nil)
|
||||
assert.Equal(t, http.StatusUnauthorized, rr.Code)
|
||||
})
|
||||
|
||||
@@ -65,7 +65,7 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test with admin session
|
||||
rr := h.makeRequest(t, http.MethodPost, "/api/v1/admin/users", createReq, h.AdminSession, nil)
|
||||
rr := h.makeRequest(t, http.MethodPost, "/api/v1/admin/users", createReq, h.AdminSession)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
var createdUser models.User
|
||||
@@ -77,7 +77,7 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
assert.NotZero(t, createdUser.LastWorkspaceID)
|
||||
|
||||
// Test duplicate email
|
||||
rr = h.makeRequest(t, http.MethodPost, "/api/v1/admin/users", createReq, h.AdminSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodPost, "/api/v1/admin/users", createReq, h.AdminSession)
|
||||
assert.Equal(t, http.StatusConflict, rr.Code)
|
||||
|
||||
// Test invalid request (missing required fields)
|
||||
@@ -85,11 +85,11 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
Email: "invalid@test.com",
|
||||
// Missing password and role
|
||||
}
|
||||
rr = h.makeRequest(t, http.MethodPost, "/api/v1/admin/users", invalidReq, h.AdminSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodPost, "/api/v1/admin/users", invalidReq, h.AdminSession)
|
||||
assert.Equal(t, http.StatusBadRequest, rr.Code)
|
||||
|
||||
// Test with non-admin session
|
||||
rr = h.makeRequest(t, http.MethodPost, "/api/v1/admin/users", createReq, h.RegularSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodPost, "/api/v1/admin/users", createReq, h.RegularSession)
|
||||
assert.Equal(t, http.StatusForbidden, rr.Code)
|
||||
})
|
||||
|
||||
@@ -97,7 +97,7 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
path := fmt.Sprintf("/api/v1/admin/users/%d", h.RegularUser.ID)
|
||||
|
||||
// Test with admin session
|
||||
rr := h.makeRequest(t, http.MethodGet, path, nil, h.AdminSession, nil)
|
||||
rr := h.makeRequest(t, http.MethodGet, path, nil, h.AdminSession)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
var user models.User
|
||||
@@ -106,11 +106,11 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
assert.Equal(t, h.RegularUser.ID, user.ID)
|
||||
|
||||
// Test non-existent user
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/users/999999", nil, h.AdminSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/users/999999", nil, h.AdminSession)
|
||||
assert.Equal(t, http.StatusNotFound, rr.Code)
|
||||
|
||||
// Test with non-admin session
|
||||
rr = h.makeRequest(t, http.MethodGet, path, nil, h.RegularSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodGet, path, nil, h.RegularSession)
|
||||
assert.Equal(t, http.StatusForbidden, rr.Code)
|
||||
})
|
||||
|
||||
@@ -122,7 +122,7 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test with admin session
|
||||
rr := h.makeRequest(t, http.MethodPut, path, updateReq, h.AdminSession, nil)
|
||||
rr := h.makeRequest(t, http.MethodPut, path, updateReq, h.AdminSession)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
var updatedUser models.User
|
||||
@@ -132,7 +132,7 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
assert.Equal(t, updateReq.Role, updatedUser.Role)
|
||||
|
||||
// Test with non-admin session
|
||||
rr = h.makeRequest(t, http.MethodPut, path, updateReq, h.RegularSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodPut, path, updateReq, h.RegularSession)
|
||||
assert.Equal(t, http.StatusForbidden, rr.Code)
|
||||
})
|
||||
|
||||
@@ -145,7 +145,7 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
Role: models.RoleEditor,
|
||||
}
|
||||
|
||||
rr := h.makeRequest(t, http.MethodPost, "/api/v1/admin/users", createReq, h.AdminSession, nil)
|
||||
rr := h.makeRequest(t, http.MethodPost, "/api/v1/admin/users", createReq, h.AdminSession)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
var createdUser models.User
|
||||
@@ -156,19 +156,19 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
|
||||
// Test deleting own account (should fail)
|
||||
adminPath := fmt.Sprintf("/api/v1/admin/users/%d", h.AdminUser.ID)
|
||||
rr = h.makeRequest(t, http.MethodDelete, adminPath, nil, h.AdminSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodDelete, adminPath, nil, h.AdminSession)
|
||||
assert.Equal(t, http.StatusBadRequest, rr.Code)
|
||||
|
||||
// Test with admin session
|
||||
rr = h.makeRequest(t, http.MethodDelete, path, nil, h.AdminSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodDelete, path, nil, h.AdminSession)
|
||||
assert.Equal(t, http.StatusNoContent, rr.Code)
|
||||
|
||||
// Verify user is deleted
|
||||
rr = h.makeRequest(t, http.MethodGet, path, nil, h.AdminSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodGet, path, nil, h.AdminSession)
|
||||
assert.Equal(t, http.StatusNotFound, rr.Code)
|
||||
|
||||
// Test with non-admin session
|
||||
rr = h.makeRequest(t, http.MethodDelete, path, nil, h.RegularSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodDelete, path, nil, h.RegularSession)
|
||||
assert.Equal(t, http.StatusForbidden, rr.Code)
|
||||
})
|
||||
})
|
||||
@@ -181,11 +181,11 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
Name: "Test Workspace",
|
||||
}
|
||||
|
||||
rr := h.makeRequest(t, http.MethodPost, "/api/v1/workspaces", workspace, h.RegularSession, nil)
|
||||
rr := h.makeRequest(t, http.MethodPost, "/api/v1/workspaces", workspace, h.RegularSession)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
// Test with admin session
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/workspaces", nil, h.AdminSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/workspaces", nil, h.AdminSession)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
var workspaces []*handlers.WorkspaceStats
|
||||
@@ -207,7 +207,7 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test with non-admin session
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/workspaces", nil, h.RegularSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/workspaces", nil, h.RegularSession)
|
||||
assert.Equal(t, http.StatusForbidden, rr.Code)
|
||||
})
|
||||
})
|
||||
@@ -218,11 +218,11 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
UserID: h.RegularUser.ID,
|
||||
Name: "Stats Test Workspace",
|
||||
}
|
||||
rr := h.makeRequest(t, http.MethodPost, "/api/v1/workspaces", workspace, h.RegularSession, nil)
|
||||
rr := h.makeRequest(t, http.MethodPost, "/api/v1/workspaces", workspace, h.RegularSession)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
// Test with admin session
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/stats", nil, h.AdminSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/stats", nil, h.AdminSession)
|
||||
require.Equal(t, http.StatusOK, rr.Code)
|
||||
|
||||
var stats handlers.SystemStats
|
||||
@@ -237,7 +237,7 @@ func TestAdminHandlers_Integration(t *testing.T) {
|
||||
assert.GreaterOrEqual(t, stats.TotalSize, int64(0))
|
||||
|
||||
// Test with non-admin session
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/stats", nil, h.RegularSession, nil)
|
||||
rr = h.makeRequest(t, http.MethodGet, "/api/v1/admin/stats", nil, h.RegularSession)
|
||||
assert.Equal(t, http.StatusForbidden, rr.Code)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user