spec/support/helpers/configuration_helper.rb in fortnox-api-0.8.2 vs spec/support/helpers/configuration_helper.rb in fortnox-api-0.9.0
- old
+ new
@@ -1,12 +1,39 @@
# frozen_string_literal: true
+require 'dotenv'
+require 'jwt'
+
+DOTENV_FILE_NAME = '.env.test'
+Dotenv.load(DOTENV_FILE_NAME)
+
+DEBUG = ENV.fetch('DEBUG', false) == true
+
module Helpers
module Configuration
- def set_api_test_configuration
+ def set_api_test_configuration # rubocop:disable Metrics/MethodLength
Fortnox::API.configure do |config|
- config.client_secret = '9aBA8ZgsvR'
- config.access_tokens = ['ccaef817-d5d8-4b1c-a316-54f3e55c5c54']
+ config.debugging = DEBUG
+
+ if DEBUG
+ config.logger = lambda {
+ logger = Logger.new($stdout)
+ logger.level = Logger::DEBUG
+ return logger
+ }.call
+ end
end
+
+ Fortnox::API.access_token = ENV.fetch('FORTNOX_API_ACCESS_TOKEN')
+ end
+
+ def add_to_registry(symbol, klass)
+ unless Fortnox::API::Registry.key? symbol
+ # Only register the key once...
+ Fortnox::API::Registry.register(symbol) { klass }
+ end
+
+ # ... but stub the value each test run
+ Fortnox::API::Registry.stub(symbol, klass)
end
end
end