test: update conflicts and device test signatures
- Remove handler parameter from test function calls - Update test signatures to match new setupTestServer return values - Fix compilation errors after test helper refactoring - Ensure test consistency across all test files
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
|||||||
// TestConflictsBulkOperations tests bulk conflict resolution operations
|
// TestConflictsBulkOperations tests bulk conflict resolution operations
|
||||||
func TestConflictsBulkOperations(t *testing.T) {
|
func TestConflictsBulkOperations(t *testing.T) {
|
||||||
t.Run("BulkResolveConflicts_WithoutAuth", func(t *testing.T) {
|
t.Run("BulkResolveConflicts_WithoutAuth", func(t *testing.T) {
|
||||||
ts, _, _, _ := setupTestServer(t)
|
ts, _, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
req := map[string]interface{}{
|
req := map[string]interface{}{
|
||||||
@@ -35,7 +35,7 @@ func TestConflictsBulkOperations(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BulkResolveConflicts_EmptyConflictIDs", func(t *testing.T) {
|
t.Run("BulkResolveConflicts_EmptyConflictIDs", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -59,7 +59,7 @@ func TestConflictsBulkOperations(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BulkResolveConflicts_InvalidConflictID", func(t *testing.T) {
|
t.Run("BulkResolveConflicts_InvalidConflictID", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -95,7 +95,7 @@ func TestConflictsBulkOperations(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BulkResolveConflicts_InvalidStrategy", func(t *testing.T) {
|
t.Run("BulkResolveConflicts_InvalidStrategy", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -119,7 +119,7 @@ func TestConflictsBulkOperations(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BulkResolveConflicts_MostRecentStrategy", func(t *testing.T) {
|
t.Run("BulkResolveConflicts_MostRecentStrategy", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -149,7 +149,7 @@ func TestConflictsBulkOperations(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BulkResolveConflicts_HighestProgressStrategy", func(t *testing.T) {
|
t.Run("BulkResolveConflicts_HighestProgressStrategy", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -179,7 +179,7 @@ func TestConflictsBulkOperations(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BulkResolveConflicts_ManualStrategy_WithoutWinner", func(t *testing.T) {
|
t.Run("BulkResolveConflicts_ManualStrategy_WithoutWinner", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -208,7 +208,7 @@ func TestConflictsBulkOperations(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BulkResolveConflicts_ManualStrategy_WithWinner", func(t *testing.T) {
|
t.Run("BulkResolveConflicts_ManualStrategy_WithWinner", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -233,7 +233,7 @@ func TestConflictsBulkOperations(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BulkResolveConflicts_InvalidRequestBody", func(t *testing.T) {
|
t.Run("BulkResolveConflicts_InvalidRequestBody", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -255,7 +255,7 @@ func TestConflictsBulkOperations(t *testing.T) {
|
|||||||
// TestConflictsBulkDismiss tests bulk dismiss operations
|
// TestConflictsBulkDismiss tests bulk dismiss operations
|
||||||
func TestConflictsBulkDismiss(t *testing.T) {
|
func TestConflictsBulkDismiss(t *testing.T) {
|
||||||
t.Run("BulkDismissConflicts_WithoutAuth", func(t *testing.T) {
|
t.Run("BulkDismissConflicts_WithoutAuth", func(t *testing.T) {
|
||||||
ts, _, _, _ := setupTestServer(t)
|
ts, _, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
req := map[string]interface{}{
|
req := map[string]interface{}{
|
||||||
@@ -275,7 +275,7 @@ func TestConflictsBulkDismiss(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BulkDismissConflicts_EmptyConflictIDs", func(t *testing.T) {
|
t.Run("BulkDismissConflicts_EmptyConflictIDs", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -298,7 +298,7 @@ func TestConflictsBulkDismiss(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BulkDismissConflicts_InvalidConflictID", func(t *testing.T) {
|
t.Run("BulkDismissConflicts_InvalidConflictID", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -333,7 +333,7 @@ func TestConflictsBulkDismiss(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BulkDismissConflicts_MultipleConflicts", func(t *testing.T) {
|
t.Run("BulkDismissConflicts_MultipleConflicts", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -366,7 +366,7 @@ func TestConflictsBulkDismiss(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BulkDismissConflicts_InvalidRequestBody", func(t *testing.T) {
|
t.Run("BulkDismissConflicts_InvalidRequestBody", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -388,7 +388,7 @@ func TestConflictsBulkDismiss(t *testing.T) {
|
|||||||
// TestConflictsBulkEdgeCases tests edge cases for bulk operations
|
// TestConflictsBulkEdgeCases tests edge cases for bulk operations
|
||||||
func TestConflictsBulkEdgeCases(t *testing.T) {
|
func TestConflictsBulkEdgeCases(t *testing.T) {
|
||||||
t.Run("BulkResolve_NonExistentConflicts", func(t *testing.T) {
|
t.Run("BulkResolve_NonExistentConflicts", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -423,7 +423,7 @@ func TestConflictsBulkEdgeCases(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("BulkDismiss_MixedValidInvalid", func(t *testing.T) {
|
t.Run("BulkDismiss_MixedValidInvalid", func(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
// TestUpdateUserMaxDevices tests the admin endpoint for updating user device cap
|
// TestUpdateUserMaxDevices tests the admin endpoint for updating user device cap
|
||||||
func TestUpdateUserMaxDevices(t *testing.T) {
|
func TestUpdateUserMaxDevices(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
// Create test user with admin role
|
// Create test user with admin role
|
||||||
@@ -87,7 +87,7 @@ func TestUpdateUserMaxDevices(t *testing.T) {
|
|||||||
|
|
||||||
// TestUpdateUserMaxDevicesValidation tests validation of max_devices parameter
|
// TestUpdateUserMaxDevicesValidation tests validation of max_devices parameter
|
||||||
func TestUpdateUserMaxDevicesValidation(t *testing.T) {
|
func TestUpdateUserMaxDevicesValidation(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
// Create admin user and get token
|
// Create admin user and get token
|
||||||
@@ -149,7 +149,7 @@ func TestUpdateUserMaxDevicesValidation(t *testing.T) {
|
|||||||
|
|
||||||
// TestUpdateUserMaxDevicesAuth tests authentication requirements
|
// TestUpdateUserMaxDevicesAuth tests authentication requirements
|
||||||
func TestUpdateUserMaxDevicesAuth(t *testing.T) {
|
func TestUpdateUserMaxDevicesAuth(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
// Create admin user
|
// Create admin user
|
||||||
@@ -203,7 +203,7 @@ func TestUpdateUserMaxDevicesAuth(t *testing.T) {
|
|||||||
|
|
||||||
// TestUpdateUserMaxDevicesNonExistentUser tests with non-existent user ID
|
// TestUpdateUserMaxDevicesNonExistentUser tests with non-existent user ID
|
||||||
func TestUpdateUserMaxDevicesNonExistentUser(t *testing.T) {
|
func TestUpdateUserMaxDevicesNonExistentUser(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
// Create admin user
|
// Create admin user
|
||||||
@@ -235,7 +235,7 @@ func TestUpdateUserMaxDevicesNonExistentUser(t *testing.T) {
|
|||||||
|
|
||||||
// TestUpdateUserMaxDevicesMissingUserID tests with missing user ID in URL
|
// TestUpdateUserMaxDevicesMissingUserID tests with missing user ID in URL
|
||||||
func TestUpdateUserMaxDevicesMissingUserID(t *testing.T) {
|
func TestUpdateUserMaxDevicesMissingUserID(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
// Create admin user
|
// Create admin user
|
||||||
@@ -264,7 +264,7 @@ func TestUpdateUserMaxDevicesMissingUserID(t *testing.T) {
|
|||||||
|
|
||||||
// TestListUsersIncludesMaxDevices tests that List Users returns max_devices field
|
// TestListUsersIncludesMaxDevices tests that List Users returns max_devices field
|
||||||
func TestListUsersIncludesMaxDevices(t *testing.T) {
|
func TestListUsersIncludesMaxDevices(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
// Create admin user
|
// Create admin user
|
||||||
@@ -363,8 +363,13 @@ func getAdminToken(t *testing.T, ts *httptest.Server, userID uuid.UUID) string {
|
|||||||
var result map[string]interface{}
|
var result map[string]interface{}
|
||||||
json.NewDecoder(resp.Body).Decode(&result)
|
json.NewDecoder(resp.Body).Decode(&result)
|
||||||
|
|
||||||
token := result["access_token"].(string)
|
// Safe type assertion with check
|
||||||
return token
|
if accessToken, ok := result["access_token"].(string); ok {
|
||||||
|
return accessToken
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle error case - if login failed, return empty string
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to login user by credentials
|
// Helper function to login user by credentials
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestDeviceRegistrationFlow(t *testing.T) {
|
func TestDeviceRegistrationFlow(t *testing.T) {
|
||||||
ts, _, _, _ := setupTestServer(t)
|
ts, _, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
// Step 1: Initiate device registration
|
// Step 1: Initiate device registration
|
||||||
@@ -115,7 +115,7 @@ func TestDeviceRegistrationFlow(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestListDevices(t *testing.T) {
|
func TestListDevices(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
// Login to get token
|
// Login to get token
|
||||||
@@ -160,7 +160,7 @@ func TestListDevices(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateDevice(t *testing.T) {
|
func TestUpdateDevice(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
// Login to get token
|
// Login to get token
|
||||||
@@ -216,7 +216,7 @@ func TestUpdateDevice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteDevice(t *testing.T) {
|
func TestDeleteDevice(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
// Login to get token
|
// Login to get token
|
||||||
@@ -258,7 +258,7 @@ func TestDeleteDevice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDeviceAuthentication(t *testing.T) {
|
func TestDeviceAuthentication(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
// Create a device directly in the database
|
// Create a device directly in the database
|
||||||
@@ -290,7 +290,7 @@ func TestDeviceAuthentication(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestListPendingRegistrations(t *testing.T) {
|
func TestListPendingRegistrations(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -311,7 +311,7 @@ func TestListPendingRegistrations(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestApproveDeviceRegistration(t *testing.T) {
|
func TestApproveDeviceRegistration(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
@@ -350,7 +350,7 @@ func TestApproveDeviceRegistration(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRejectDeviceRegistration(t *testing.T) {
|
func TestRejectDeviceRegistration(t *testing.T) {
|
||||||
ts, db, _, _ := setupTestServer(t)
|
ts, db, _ := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
|
|
||||||
token := loginTestUser(t, ts, db)
|
token := loginTestUser(t, ts, db)
|
||||||
|
|||||||
Reference in New Issue
Block a user