test: update tests for system settings and user list enhancements

System Settings Tests (new file):
- Create system_settings_test.go with comprehensive test coverage
- Test admin-only access control
- Test validation (15-1440 minute range)
- Test error handling scenarios
- Test integration with scheduler

User Tests Cleanup:
- Remove old TestScanSettings from user_test.go
- Scan settings moved to system-wide (no longer per-user)

Device Cap Tests Enhancement:
- Update TestListUsersIncludesMaxDevices
- Add assertion for device_count field
- Verify both max_devices and device_count in response

All tests verify the migration from per-user to system-wide scan settings.
This commit is contained in:
2026-02-09 20:11:14 -05:00
parent bee6d588d6
commit fefb1bd33b
3 changed files with 325 additions and 77 deletions
-76
View File
@@ -485,79 +485,3 @@ func TestAdminOnlyEndpoints(t *testing.T) {
assert.Equal(t, http.StatusOK, rr.Code)
})
}
// TestScanSettings tests scan settings endpoints
func TestScanSettings(t *testing.T) {
t.Run("GET /api/library/scan-settings - Get settings without auth", func(t *testing.T) {
req := httptest.NewRequest("GET", "/api/library/scan-settings", nil)
rr := httptest.NewRecorder()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
authHeader := r.Header.Get("Authorization")
if authHeader == "" {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(`{"message":"missing or malformed jwt"}`))
return
}
w.WriteHeader(http.StatusOK)
})
handler.ServeHTTP(rr, req)
assert.Equal(t, http.StatusUnauthorized, rr.Code)
})
t.Run("PUT /api/library/scan-settings - Update with invalid frequency", func(t *testing.T) {
testCases := []struct {
name string
scanFrequencyMinutes int
}{
{"Frequency too low (14 minutes)", 14},
{"Frequency too high (1441 minutes)", 1441},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
payload := map[string]interface{}{
"scan_frequency_minutes": tc.scanFrequencyMinutes,
"auto_scan_enabled": true,
}
jsonData, _ := json.Marshal(payload)
req := httptest.NewRequest("PUT", "/api/library/scan-settings", bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer valid-token")
rr := httptest.NewRecorder()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte(`{"error":"scan_frequency_minutes must be between 15 and 1440"}`))
})
handler.ServeHTTP(rr, req)
assert.Equal(t, http.StatusBadRequest, rr.Code)
})
}
})
t.Run("PUT /api/library/scan-settings - Update with valid frequency", func(t *testing.T) {
payload := map[string]interface{}{
"scan_frequency_minutes": 60,
"auto_scan_enabled": true,
}
jsonData, _ := json.Marshal(payload)
req := httptest.NewRequest("PUT", "/api/library/scan-settings", bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer valid-token")
rr := httptest.NewRecorder()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"message":"scan settings updated successfully"}`))
})
handler.ServeHTTP(rr, req)
assert.Equal(t, http.StatusOK, rr.Code)
})
}