const axios = require('axios');

async function test() {
  const login = await axios.post('http://localhost:3000/api/auth/login', {
    email: 'admin@contentgen.ai',
    password: 'Admin123!',
  });
  const token = login.data.data.accessToken;

  // Simulate interceptor
  let responseData = await axios.get('http://localhost:3000/api/projects', {
    headers: { Authorization: `Bearer ${token}` }
  }).then(r => {
      let data = r.data;
      if (data && typeof data === 'object' && 'success' in data && 'data' in data) {
          data = data.data;
      }
      return data;
  });

  console.log("Interceptor Output:", JSON.stringify(responseData, null, 2).substring(0, 500));
  
  const raw = responseData;
  const rawProjects = raw?.data ?? raw ?? [];
  const projects = Array.isArray(rawProjects) ? rawProjects : [];
  
  console.log("Is array?", Array.isArray(rawProjects));
  console.log("Projects length:", projects.length);
}

test();
