test/acceptance/acceptance_test.rb in xeroizer-2.20.0 vs test/acceptance/acceptance_test.rb in xeroizer-3.0.0
- old
+ new
@@ -1,9 +1,37 @@
+module AcceptanceTestHelpers
+ def self.oauth2_client
+ config = self.load_oauth2_config_from_env
+ Xeroizer::OAuth2Application.new(
+ config.client_id,
+ config.client_secret,
+ access_token: config.access_token,
+ tenant_id: config.tenant_id
+ )
+ end
+
+ def self.load_oauth2_config_from_env
+ raise "No XERO_CLIENT_ID environment variable specified." unless ENV["XERO_CLIENT_ID"]
+ raise "No XERO_CLIENT_SECRET environment variable specified." unless ENV["XERO_CLIENT_SECRET"]
+ raise "No XERO_ACCESS_TOKEN environment variable specified." unless ENV["XERO_ACCESS_TOKEN"]
+ raise "No XERO_TENANT_ID environment variable specified." unless ENV["XERO_TENANT_ID"]
+
+ OpenStruct.new(client_id: ENV["XERO_CLIENT_ID"],
+ client_secret: ENV["XERO_CLIENT_SECRET"],
+ access_token: ENV["XERO_ACCESS_TOKEN"],
+ tenant_id: ENV["XERO_TENANT_ID"])
+ end
+end
+
module AcceptanceTest
class << self
def included(klass)
klass.class_eval do
+ def self.it_works_using_oauth2(&block)
+ instance_exec(AcceptanceTestHelpers.oauth2_client, 'oauth2', &block)
+ end
+
def self.log_to_console
Xeroizer::Logging.const_set :Log, Xeroizer::Logging::StdOutLog
end
def self.no_log
@@ -21,33 +49,7 @@
end
end
end
end
end
- end
-
- def setup
- config = load_config_from_file || load_config_from_env
-
- @key_file = config.key_file
- @consumer_key = config.consumer_key
- @consumer_secret = config.consumer_secret
- end
-
- private
-
- def load_config_from_file
- the_file_name = File.join(File.dirname(__FILE__), '..', '..', '.oauth')
-
- return nil unless File.exist? the_file_name
-
- Xeroizer::OAuthConfig.load IO.read the_file_name
- end
-
- def load_config_from_env
- assert_not_nil ENV["CONSUMER_KEY"], "No CONSUMER_KEY environment variable specified."
- assert_not_nil ENV["CONSUMER_SECRET"], "No CONSUMER_SECRET environment variable specified."
- assert_not_nil ENV["PRIVATE_KEY_PATH"], "No PRIVATE_KEY_PATH environment variable specified."
- assert File.exist?(ENV["PRIVATE_KEY_PATH"]), "The file <#{ENV["PRIVATE_KEY_PATH"]}> does not exist."
- Xeroizer::OAuthCredentials.new ENV["CONSUMER_KEY"], ENV["CONSUMER_SECRET"], ENV["PRIVATE_KEY_PATH"]
end
end