import { PostType } from '../enums/post-type.enum';
import { buildPostMediaResponse } from './post-media-response.util';

describe('post media response util', () => {
  it('returns display-safe waveformPeaks for audio media', () => {
    const media = buildPostMediaResponse({
      postType: PostType.AUDIO,
      audioUrl: '/uploads/posts/audios/audio.mp3',
      durationSeconds: 42,
      waveformPeaks: [1, 12, 30, 45, 20, 6],
    });

    expect(media.mediaType).toBe(PostType.AUDIO);
    expect(media.durationSeconds).toBe(42);
    expect(media.waveformPeaks).toHaveLength(100);
    expect(media.waveformPeaks.every((value) => Number.isInteger(value))).toBe(true);
    expect(media.waveformPeaks.every((value) => value >= 0 && value <= 100)).toBe(true);
  });

  it('does not attach waveformPeaks to non-audio media', () => {
    const media = buildPostMediaResponse({
      postType: PostType.IMAGE,
      imageUrls: ['/uploads/posts/images/image.jpg'],
      waveformPeaks: [10, 20, 30],
    });

    expect(media.mediaType).toBe(PostType.IMAGE);
    expect(media.waveformPeaks).toEqual([]);
  });
});
