import { describe, expect, test } from '@jest/globals';

import { IModel } from './models';
import { findMatchingModel, findMatchingModelFromConfig } from './utils';

describe('models', () => {
  describe('findMatchingModel', () => {
    const model = 'stehfestBouwman2006';
    const term = 'noxToAirInorganicFertiliser';
    const path =
      'hestia_earth/models/stehfestBouwman2006/noxToAirInorganicFertiliser.py';

    test('should find by model', () => {
      const params = { model, term } as Partial<IModel>;

      expect(findMatchingModel(params)).toEqual(
        expect.objectContaining({ model, term, path })
      );
    });

    test('should handle values with dot', () => {
      expect(
        findMatchingModel(
          {
            model: 'ipcc2019',
            term: 'animal.pregnancyRateTotal'
          },
          { useDotValues: true }
        )
      ).toEqual(
        expect.objectContaining({
          model: 'ipcc2019',
          term: 'pregnancyRateTotal'
        })
      );
    });
  });

  describe('findMatchingModelFromConfig', () => {
    test('should handle completeness', () => {
      const model = 'cycle';

      expect(
        findMatchingModelFromConfig({
          model,
          value: 'completeness'
        })
      ).toEqual(
        expect.objectContaining({
          model: 'cycle',
          modelKey: 'completeness.animalFeed'
        })
      );
    });

    test('should handle feedConversionRatio', () => {
      const model = 'hestia';

      expect(
        findMatchingModelFromConfig({
          model,
          value: 'feedConversionRatio'
        })
      ).toEqual(
        expect.objectContaining({
          model: 'hestia',
          term: 'feedConversionRatioCarbon'
        })
      );
    });

    test('should handle ecoinventV3AndEmberClimate', () => {
      const model = 'ecoinventV3AndEmberClimate';

      expect(
        findMatchingModelFromConfig({
          model,
          value: 'all'
        })
      ).toEqual(
        expect.objectContaining({
          model
        })
      );
    });

    test('should handle ecoinventV3AndEmberClimate', () => {
      const model = 'ecoinventV3AndEmberClimate';

      expect(
        findMatchingModelFromConfig({
          model,
          value: 'all'
        })
      ).toEqual(
        expect.objectContaining({
          model
        })
      );
    });

    test('should handle seed_emissions', () => {
      const model = 'hestia';

      expect(
        findMatchingModelFromConfig({
          model,
          value: 'seed_emissions'
        })
      ).toEqual(
        expect.objectContaining({
          model,
          modelKey: 'seed_emissions'
        })
      );
    });
  });
});
