Skip to content

Commit

Permalink
env variable mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcam-src committed Sep 24, 2024
1 parent cbbd07d commit f2a7428
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions spec/services/tasks/download_stats_migration_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,28 @@
let(:mock_admin_set) { FactoryBot.create(:solr_query_result, :admin_set, title_tesim: [admin_set_title]) }
let(:output_path) { Rails.root.join('tmp', 'download_migration_test_output.csv') }
let(:service) { described_class.new }
let(:spec_base_analytics_url) { 'https://analytics-qa.lib.unc.edu' }
let(:spec_site_id) { '5' }
let(:spec_auth_token) { 'testtoken' }
let(:matomo_stats_migration_fixture) do
JSON.parse(File.read(File.join(Rails.root, '/spec/fixtures/files/matomo_stats_migration_fixture.json')))
end

around do |example|
# Set the environment variables for the test
@auth_token = ENV['MATOMO_AUTH_TOKEN']
@site_id = ENV['MATOMO_SITE_ID']
@matomo_base_url = ENV['MATOMO_BASE_URL']
ENV['MATOMO_AUTH_TOKEN'] = spec_auth_token
ENV['MATOMO_SITE_ID'] = spec_site_id
ENV['MATOMO_BASE_URL'] = spec_base_analytics_url
example.run
# Reset the environment variables
ENV['MATOMO_AUTH_TOKEN'] = @auth_token
ENV['MATOMO_SITE_ID'] = @site_id
ENV['MATOMO_BASE_URL'] = @matomo_base_url
end

before do
allow(ActiveFedora::SolrService).to receive(:get).with("title_tesim:#{admin_set_title}", { :rows => 1, 'df' => 'title_tesim'}).and_return('response' => { 'docs' => [mock_admin_set] })
end
Expand Down

0 comments on commit f2a7428

Please sign in to comment.