require 'spec_helper'

RSpec.describe Idxprb::Configurator do
  subject { Idxprb::Configurator.new('config_key') }

  context 'when running in production' do
    before do
      ENV['PRODUCTION'] = 'true'
      expect_any_instance_of(Diplomat::Kv)
        .to receive(:get)
        .with('config_key')
        .and_return('{"config_from":"consul"}')
    end

    it 'loads the config from consul' do
      expect(subject.configs).to eq('config_from' => 'consul')
    end
  end

  context 'when running other environment than production' do
    before do
      ENV['PRODUCTION'] = nil
      expect(File)
        .to receive(:read)
        .with('config.json')
        .and_return('{"config_from":"file"}')
    end

    it 'loads the config from config file' do
      expect(subject.configs).to eq('config_from' => 'file')
    end
  end
end