import { UsersController } from './users.controller';

describe('UsersController artist dashboard', () => {
  it('uses the authenticated user id for the private dashboard endpoint', async () => {
    const usersService = {
      getMyDashboard: jest.fn().mockResolvedValue({ profile: { _id: 'user-1' } }),
    };
    const controller = new UsersController(usersService as any);

    const result = await controller.getMyDashboard({ sub: 'user-1' } as any);

    expect(usersService.getMyDashboard).toHaveBeenCalledWith('user-1');
    expect(result).toEqual({ profile: { _id: 'user-1' } });
  });
});

describe('UsersController profile lookup', () => {
  it('uses the authenticated user id when loading profile overview by username', async () => {
    const usersService = {
      getProfileOverviewByUsername: jest.fn().mockResolvedValue({
        profileShareUrl: 'https://oudelaa.com/u/artist',
      }),
    };
    const controller = new UsersController(usersService as any);

    const result = await controller.getProfileOverviewByUsername(
      { sub: 'viewer-1' } as any,
      'artist',
    );

    expect(usersService.getProfileOverviewByUsername).toHaveBeenCalledWith('artist', 'viewer-1');
    expect(result).toEqual({ profileShareUrl: 'https://oudelaa.com/u/artist' });
  });
});

describe('UsersController follow counts', () => {
  it('uses the authenticated user id when loading follow counts', async () => {
    const usersService = {
      getFollowCounts: jest.fn().mockResolvedValue({
        userId: 'target-1',
        followersCount: 1,
        followingCount: 2,
      }),
    };
    const controller = new UsersController(usersService as any);

    const result = await controller.getFollowCounts({ sub: 'viewer-1' } as any, 'target-1');

    expect(usersService.getFollowCounts).toHaveBeenCalledWith('target-1', 'viewer-1');
    expect(result).toEqual({
      userId: 'target-1',
      followersCount: 1,
      followingCount: 2,
    });
  });
});
