import { GUARDS_METADATA } from '@nestjs/common/constants';
import { RoleEnum } from '../roles/roles.enum';
import { RolesGuard } from '../roles/roles.guard';
import { TeamsController } from './teams.controller';

describe('TeamsController', () => {
  const service = { createNewTeam: jest.fn() };
  const publicAccess = {};
  const teamMembers = {};
  const teamPermissions = {};
  const controller = new TeamsController(
    service as any,
    publicAccess as any,
    teamMembers as any,
    teamPermissions as any,
  );

  beforeEach(() => jest.clearAllMocks());

  it('allows any logged-in user (not just admins) to create a team', () => {
    expect(Reflect.getMetadata('roles', TeamsController.prototype.create)).toEqual([
      RoleEnum.user,
      RoleEnum.admin,
    ]);
    expect(
      Reflect.getMetadata(GUARDS_METADATA, TeamsController.prototype.create),
    ).toContain(RolesGuard);
  });

  it('passes the authenticated user and the DTO to the service', () => {
    const req = { user: { id: 42 } };
    const dto = { name: '1. Herren' };

    void controller.create(req as any, dto as any);

    expect(service.createNewTeam).toHaveBeenCalledWith(dto, 42);
  });
});
