{"size": 1391, "ext": "js", "max_stars_repo_path": "src/plugin_discovery/plugin_config/__tests__/settings.js", "max_stars_repo_name": "chandlerprall/kibana", "max_stars_repo_stars_event_min_datetime": "2016-12-17T07:34:09.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-25T16:38:27.000Z", "max_issues_repo_path": "src/plugin_discovery/plugin_config/__tests__/settings.js", "max_issues_repo_name": "chandlerprall/kibana", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/plugin_discovery/plugin_config/__tests__/settings.js", "max_forks_repo_name": "chandlerprall/kibana", "max_forks_repo_forks_event_min_datetime": "2020-11-04T07:06:39.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T07:06:39.000Z"}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 21.4, "max_line_length": 59, "alphanum_fraction": 0.4845434939}
import expect from 'expect.js';
import sinon from 'sinon';

import { PluginPack } from '../../plugin_pack';
import { getSettings } from '../settings';

describe('plugin_discovery/settings', () => {
  const pluginSpec = new PluginPack({
    path: '/dev/null',
    pkg: {
      name: 'test',
      version: 'kibana',
    },
    provider: ({ Plugin }) => new Plugin({
      configPrefix: 'a.b.c',
      deprecations: ({ rename }) => [
        rename('foo', 'bar')
      ]
    }),
  })
    .getPluginSpecs()
    .pop();

  describe('getSettings()', () => {
    it('reads settings from config prefix', async () => {
      const rootSettings = {
        a: {
          b: {
            c: {
              enabled: false
            }
          }
        }
      };

      expect(await getSettings(pluginSpec, rootSettings))
        .to.eql({
          enabled: false
        });
    });

    it('allows rootSettings to be undefined', async () => {
      expect(await getSettings(pluginSpec))
        .to.eql(undefined);
    });

    it('resolves deprecations', async () => {
      const logDeprecation = sinon.stub();
      expect(await getSettings(pluginSpec, {
        a: {
          b: {
            c: {
              foo: true
            }
          }
        }
      }, logDeprecation)).to.eql({
        bar: true
      });

      sinon.assert.calledOnce(logDeprecation);
    });
  });
});
