import convertTimeFormat from '../utils/ConvertHHMMSStoHHMM';


describe('convertTimeFormat', () => {
  it('should convert time in HH:mm:ss format to HH:mm format', async () => {
    const time = '14:30:45';
    const result = await convertTimeFormat(time);
    expect(result).toBe('14:30');
  });

  it('should handle midnight time correctly', async () => {
    const time = '00:00:00';
    const result = await convertTimeFormat(time);
    expect(result).toBe('00:00');
  });

  it('should handle times with seconds not equal to 00', async () => {
    const time = '23:45:30';
    const result = await convertTimeFormat(time);
    expect(result).toBe('23:45');
  });

  it('should handle invalid time strings gracefully', async () => {
    const time = 'invalid-time';
    // Since `parse` will return an invalid date, we'll use try-catch to handle this
    await expect(convertTimeFormat(time)).rejects.toThrow();
  });

  it('should handle empty string input', async () => {
    const time = '';
    await expect(convertTimeFormat(time)).rejects.toThrow();
  });

  it('should handle incorrect time format input', async () => {
    const time = '14:30'; // Missing seconds
    await expect(convertTimeFormat(time)).rejects.toThrow();
  });
});

