2016-03-23 18:39:41 +01:00
|
|
|
ENV['RAILS_ENV'] ||= 'test'
|
|
|
|
require File.expand_path('../../config/environment', __FILE__)
|
|
|
|
require 'rails/test_help'
|
2016-04-06 15:15:09 +02:00
|
|
|
require 'vcr'
|
2016-04-04 17:42:45 +02:00
|
|
|
require 'sidekiq/testing'
|
|
|
|
require 'minitest/reporters'
|
2016-04-06 15:15:09 +02:00
|
|
|
|
|
|
|
VCR.configure do |config|
|
|
|
|
config.cassette_library_dir = "test/vcr_cassettes"
|
|
|
|
config.hook_into :webmock
|
|
|
|
end
|
|
|
|
|
2016-04-11 15:31:25 +02:00
|
|
|
Sidekiq::Testing.fake!
|
2016-04-04 17:42:45 +02:00
|
|
|
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new({ color: true })]
|
|
|
|
|
2016-04-06 11:27:56 +02:00
|
|
|
|
2016-03-23 18:39:41 +01:00
|
|
|
|
2016-04-06 15:15:09 +02:00
|
|
|
|
2016-03-23 18:39:41 +01:00
|
|
|
class ActiveSupport::TestCase
|
|
|
|
# Add more helper methods to be used by all tests here...
|
2016-04-04 17:42:45 +02:00
|
|
|
|
|
|
|
fixtures :all
|
2016-04-05 09:51:12 +02:00
|
|
|
|
|
|
|
def json_response(body)
|
|
|
|
JSON.parse(body, symbolize_names: true)
|
|
|
|
end
|
2016-04-06 11:27:56 +02:00
|
|
|
|
2016-04-06 15:22:32 +02:00
|
|
|
def default_headers
|
|
|
|
{ 'Accept' => Mime::JSON, 'Content-Type' => Mime::JSON.to_s }
|
|
|
|
end
|
|
|
|
|
2016-04-06 16:26:45 +02:00
|
|
|
def stripe_card_token(error: nil)
|
|
|
|
number = "4242424242424242"
|
|
|
|
exp_month = 4
|
|
|
|
exp_year = DateTime.now.next_year.year
|
|
|
|
cvc = "314"
|
|
|
|
|
|
|
|
case error
|
|
|
|
when /card_declined/
|
|
|
|
number = "4000000000000002"
|
|
|
|
when /incorrect_number/
|
|
|
|
number = "4242424242424241"
|
|
|
|
when /invalid_expiry_month/
|
|
|
|
exp_month = 15
|
|
|
|
when /invalid_expiry_year/
|
|
|
|
exp_year = 1964
|
|
|
|
when /invalid_cvc/
|
|
|
|
cvc = "99"
|
|
|
|
end
|
|
|
|
|
|
|
|
Stripe::Token.create(card: {
|
|
|
|
number: number,
|
|
|
|
exp_month: exp_month,
|
|
|
|
exp_year: exp_year,
|
|
|
|
cvc: cvc
|
|
|
|
},
|
2016-04-06 11:27:56 +02:00
|
|
|
).id
|
|
|
|
end
|
2016-04-11 15:31:25 +02:00
|
|
|
|
|
|
|
# Force the invoice generation worker to run NOW and check the resulting file generated.
|
|
|
|
# Delete the file afterwards.
|
|
|
|
# @param invoice {Invoice}
|
|
|
|
def assert_invoice_pdf(invoice)
|
|
|
|
assert_not_nil invoice, 'Invoice was not created'
|
|
|
|
|
|
|
|
invoice_worker = InvoiceWorker.new
|
|
|
|
invoice_worker.perform(invoice.id)
|
|
|
|
|
|
|
|
assert File.exist?(invoice.file), 'Invoice PDF was not generated'
|
|
|
|
|
|
|
|
File.delete(invoice.file)
|
|
|
|
end
|
2016-07-27 11:28:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Force the statistics export generation worker to run NOW and check the resulting file generated.
|
|
|
|
# Delete the file afterwards.
|
|
|
|
# @param export {Export}
|
|
|
|
def assert_export_xlsx(export)
|
|
|
|
assert_not_nil export, 'Export was not created'
|
|
|
|
|
|
|
|
if export.category == 'statistics'
|
|
|
|
export_worker = StatisticsExportWorker.new
|
|
|
|
export_worker.perform(export.id)
|
|
|
|
|
|
|
|
assert File.exist?(export.file), 'Export XLSX was not generated'
|
|
|
|
|
|
|
|
File.delete(export.file)
|
|
|
|
else
|
|
|
|
skip('Unable to test export which is not of the category "statistics"')
|
|
|
|
end
|
|
|
|
end
|
2016-04-04 17:42:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
class ActionDispatch::IntegrationTest
|
|
|
|
include Warden::Test::Helpers
|
|
|
|
Warden.test_mode!
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|