// Test for role-based access control middleware
const { requireRole } = require('../backend/middleware/role.middleware.cjs');

// Mock the middleware function directly for testing
console.log('Testing role middleware...');

// Test that the middleware exists and is a function
console.log('requireRole should be a function:', typeof requireRole === 'function');

// Test that middleware denies access to users without required role
const mockReq = {
  user: { role: 'user' }
};

const mockRes = {
  status: (code) => {
    console.log('Status code:', code);
    return {
      json: (data) => {
        console.log('Response data:', data);
      }
    };
  }
};

const mockNext = () => {
  console.log('Next function called');
};

const middleware = requireRole(['admin']);
middleware(mockReq, mockRes, mockNext);

console.log('Test completed');