import { UploadMediaPresenter } from './UploadMediaPresenter';

describe('UploadMediaPresenter', () => {
  let presenter: UploadMediaPresenter;

  beforeEach(() => {
    presenter = new UploadMediaPresenter();
  });

  describe('transform', () => {
    it('should map result with URL to response model', () => {
      const result = {
        mediaId: 'media-123',
        url: 'https://example.com/uploaded-file.png',
      };

      const response = presenter.transform(result);

      expect(response).toEqual({
        success: true,
        mediaId: 'media-123',
        url: 'https://example.com/uploaded-file.png',
      });
    });

    it('should map result without URL to response model', () => {
      const result = {
        mediaId: 'media-123',
        url: undefined,
      };

      const response = presenter.transform(result);

      expect(response).toEqual({
        success: true,
        mediaId: 'media-123',
      });
      expect(response.url).toBeUndefined();
    });

    it('should always set success to true', () => {
      const result = {
        mediaId: 'media-456',
        url: 'https://example.com/test.jpg',
      };

      const response = presenter.transform(result);

      expect(response.success).toBe(true);
    });
  });

  describe('reset', () => {
    it('should clear the model', () => {
      presenter.transform({ mediaId: 'media-123', url: 'https://example.com/file.png' });
      expect(presenter.getResponseModel()).not.toBeNull();

      presenter.reset();
      expect(presenter.getResponseModel()).toBeNull();
    });
  });

  describe('responseModel', () => {
    it('should throw error when accessed before transform()', () => {
      expect(() => presenter.responseModel).toThrow('Presenter not presented');
    });

    it('should return model after transform()', () => {
      presenter.transform({ mediaId: 'media-123', url: 'https://example.com/file.png' });
      expect(presenter.responseModel).toEqual({
        success: true,
        mediaId: 'media-123',
        url: 'https://example.com/file.png',
      });
    });
  });

  describe('getResponseModel', () => {
    it('should return null before transform()', () => {
      expect(presenter.getResponseModel()).toBeNull();
    });

    it('should return model after transform()', () => {
      presenter.transform({ mediaId: 'media-123', url: 'https://example.com/file.png' });
      expect(presenter.getResponseModel()).toEqual({
        success: true,
        mediaId: 'media-123',
        url: 'https://example.com/file.png',
      });
    });
  });
});