import { describe, expect, it } from 'vitest';
import { vehicleJsonLd } from '../src/lib/jsonLd';

describe('Vehicle JSON-LD', () => {
  it('maps listing fields to Vehicle schema', () => {
    const schema = vehicleJsonLd({
      canonicalUrl: 'https://auto.juozas.lt/automobiliai/bmw-320d-2018-vilnius',
      imageUrl: 'https://auto.juozas.lt/_astro/01.jpg',
      car: {
        make: 'BMW',
        model: '320d',
        year: 2018,
        price: 12500,
        mileage: 145000,
        fuel: 'dyzelinas',
        transmission: 'automatinė',
        bodyType: 'sedanas',
        color: 'Pilka',
        sold: false,
        vin: 'WBA8C91010A000000',
      },
    });

    expect(schema['@type']).toBe('Vehicle');
    expect(schema.vehicleModelDate).toBe(2018);
    expect(schema.mileageFromOdometer.value).toBe(145000);
    expect(schema.offers.price).toBe(12500);
    expect(schema.offers.priceCurrency).toBe('EUR');
  });

  it('marks sold listings as sold out', () => {
    const schema = vehicleJsonLd({
      canonicalUrl: 'https://auto.juozas.lt/automobiliai/bmw-320d-2018-vilnius',
      imageUrl: 'https://auto.juozas.lt/_astro/01.jpg',
      car: {
        make: 'BMW',
        model: '320d',
        year: 2018,
        price: 12500,
        mileage: 145000,
        fuel: 'dyzelinas',
        transmission: 'automatinė',
        bodyType: 'sedanas',
        color: 'Pilka',
        sold: true,
      },
    });

    expect(schema.offers.availability).toBe('https://schema.org/SoldOut');
  });
});
