import { describe, it, expect } from 'vitest';
import deprecated from './deprecated';

describe('deprecated', () => {
  const deprecation = deprecated[0] as any;

  it('migrates legacy attributes to the new format', () => {
    const legacyAttributes = {
      titleId: 123,
      titleType: 'movie',
      seasonNumber: 2,
      episodeNumber: 5,
      titleName: 'Test Movie',
      titleReleaseYear: 2020,
      titleDirector: 'Test Director',
    };

    const migratedAttributes = deprecation?.migrate
      ? deprecation.migrate(legacyAttributes, [])
      : {};

    expect(migratedAttributes).toEqual({
      id: '123',
      idType: 'justwatch',
      objectType: 'movie',
      seasonNumber: 2,
      episodeNumber: 5,
      meta: {
        justwatchId: 123,
        title: 'Test Movie',
        objectType: 'movie',
        originalTitle: 'Test Movie',
        originalReleaseYear: 2020,
        director: 'Test Director',
      },
    });
  });

  it('generates the correct shortcode for legacy attributes', () => {
    const legacyAttributes = {
      titleId: 123,
      titleType: 'show',
      seasonNumber: 2,
      episodeNumber: 5,
    };

    const shortcode = deprecation.save({ attributes: legacyAttributes });

    expect(shortcode).toBe(
      '[justwatch id="123" type="show" season="2" episode="5"]'
    );
  });

  it('generates the correct shortcode for missing legacy attributes', () => {
    const legacyAttributes = {
      titleId: undefined,
      titleType: undefined,
      seasonNumber: undefined,
      episodeNumber: undefined,
      titleName: undefined,
      titleReleaseYear: undefined,
      titleDirector: undefined,
    };

    const shortcode = deprecation.save({ attributes: legacyAttributes });

    expect(shortcode).toBe(
      ''
    );
  });
});