import { test, expect } from '../fixtures';

test.describe('GET /auth/profile', () => {
  test('returns user profile for authenticated user', async ({ authedRequest, testUser }) => {
    const res = await authedRequest.get('auth/profile');

    expect(res.status()).toBe(200);
    const body = await res.json();
    expect(body).toHaveProperty('id');
    // API normalises phone to +84 format
    expect(body.phone).toContain(testUser.phone.slice(1));
    expect(body.fullName).toBe(testUser.fullName);
  });

  test('rejects unauthenticated requests', async ({ request }) => {
    const res = await request.get('auth/profile');

    expect(res.ok()).toBeFalsy();
    expect(res.status()).toBe(401);
  });

  test('rejects requests with invalid token', async ({ request }) => {
    const res = await request.get('auth/profile', {
      headers: { Authorization: 'Bearer invalid.jwt.token' },
    });

    expect(res.ok()).toBeFalsy();
    expect(res.status()).toBe(401);
  });
});
