import { describe, expect, it } from 'vitest';
import {
  TIMESTAMP_DEFAULT,
  Timestamp,
  formatSecondsToTimestamp,
  timestampToSeconds,
} from './Timestamp';

const timeStamp: Timestamp = '00:02:00.000';

describe('formatSecondsToTimestamp', () => {
  it.each([
    [120, timeStamp],
    [120.123, '00:02:00.123'],
    [120.12345, '00:02:00.123'],
    [undefined, TIMESTAMP_DEFAULT],
    [null, TIMESTAMP_DEFAULT],
    [0, TIMESTAMP_DEFAULT],
  ])('converts %p to a valid timestamp', (value, expected) => {
    const result = formatSecondsToTimestamp(value as number);
    expect(result).toBe(expected);
  });
});

describe('timestampToSeconds', () => {
  it('converts a Timestamp to seconds', () => {
    const seconds = 120;

    const convertedTimestamp = timestampToSeconds(timeStamp);
    expect(convertedTimestamp).toBe(seconds);
  });
});
