import { describe, expect, it } from 'vitest';

import { FeedItemOrmEntity } from '../entities/FeedItemOrmEntity';
import { TypeOrmSocialSchemaError } from '../errors/TypeOrmSocialSchemaError';
import { FeedItemOrmMapper } from './FeedItemOrmMapper';

describe('FeedItemOrmMapper', () => {
  it('maps orm entity to domain FeedItem', () => {
    const mapper = new FeedItemOrmMapper();

    const orm = new FeedItemOrmEntity();
    orm.id = '00000000-0000-0000-0000-000000000001';
    orm.timestamp = new Date('2025-01-01T00:00:00.000Z');
    orm.type = 'new-result-posted';
    orm.actorFriendId = null;
    orm.actorDriverId = '00000000-0000-0000-0000-0000000000aa';
    orm.leagueId = null;
    orm.raceId = '00000000-0000-0000-0000-0000000000bb';
    orm.teamId = null;
    orm.position = 2;
    orm.headline = 'Hello';
    orm.body = 'World';
    orm.ctaLabel = null;
    orm.ctaHref = null;

    const domain = mapper.toDomain(orm);

    expect(domain).toEqual({
      id: orm.id,
      timestamp: orm.timestamp,
      type: orm.type,
      actorDriverId: orm.actorDriverId,
      raceId: orm.raceId,
      position: orm.position,
      headline: orm.headline,
      body: orm.body,
    });
  });

  it('throws TypeOrmSocialSchemaError for invalid shape', () => {
    const mapper = new FeedItemOrmMapper();

    const orm = new FeedItemOrmEntity();
    orm.id = '';
    orm.timestamp = new Date('2025-01-01T00:00:00.000Z');
    orm.type = 'new-result-posted';
    orm.actorFriendId = null;
    orm.actorDriverId = null;
    orm.leagueId = null;
    orm.raceId = null;
    orm.teamId = null;
    orm.position = null;
    orm.headline = 'Hello';
    orm.body = null;
    orm.ctaLabel = null;
    orm.ctaHref = null;

    expect(() => mapper.toDomain(orm)).toThrow(TypeOrmSocialSchemaError);
  });
});