import { TripMembersController } from './trip-members.controller';

describe('TripMembersController', () => {
  it('GET /trips/:tripId/members lists members', async () => {
    const members = [
      { id: 'm1', tripId: 't1', userId: 'u1', role: 'OWNER', status: 'ACTIVE' },
    ];
    const tripMembersService = {
      listMembers: jest.fn().mockResolvedValue(members),
    };
    const controller = new TripMembersController(tripMembersService as never);

    await expect(controller.list('t1')).resolves.toEqual(members);
    expect(tripMembersService.listMembers).toHaveBeenCalledWith('t1');
  });

  it('PATCH /trips/:tripId/members/:memberId updates the member', async () => {
    const updated = {
      id: 'm1',
      tripId: 't1',
      userId: 'u2',
      role: 'MEMBER',
      status: 'ACTIVE',
    };
    const tripMembersService = {
      updateMember: jest.fn().mockResolvedValue(updated),
    };
    const controller = new TripMembersController(tripMembersService as never);

    await expect(
      controller.update('t1', 'm1', { role: 'MEMBER' }),
    ).resolves.toEqual(updated);
    expect(tripMembersService.updateMember).toHaveBeenCalledWith('t1', 'm1', {
      role: 'MEMBER',
    });
  });

  it('DELETE /trips/:tripId/members/:memberId removes the member', async () => {
    const tripMembersService = {
      removeMember: jest.fn().mockResolvedValue(undefined),
    };
    const controller = new TripMembersController(tripMembersService as never);

    await controller.remove('t1', 'm1');
    expect(tripMembersService.removeMember).toHaveBeenCalledWith('t1', 'm1');
  });
});
