const { normalizeImageUri, toWikimediaFilePathUrl } = require('../../server/lib/plants');

describe('server plant image normalization', () => {
  it('accepts local public plant paths', () => {
    expect(normalizeImageUri('/plants/monstera-deliciosa.webp')).toBe('/plants/monstera-deliciosa.webp');
    expect(normalizeImageUri('plants/thumbs/monstera-deliciosa.webp')).toBe('/plants/thumbs/monstera-deliciosa.webp');
  });

  it('rejects invalid local paths', () => {
    expect(normalizeImageUri('/uploads/monstera.webp')).toBeNull();
    expect(normalizeImageUri('/plants/../../secret.webp')).toBeNull();
  });

  it('converts Wikimedia thumbnail URLs to stable file-path URLs for API responses', () => {
    expect(
      toWikimediaFilePathUrl('https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/Agave_americana_%28detail%29.jpg/330px-Agave_americana_%28detail%29.jpg'),
    ).toBe('https://commons.wikimedia.org/wiki/Special:FilePath/Agave_americana_(detail).jpg');
  });
});
