1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/test/test_helper.rb

111 lines
2.9 KiB
Ruby
Raw Normal View History

2019-04-04 11:57:36 +02:00
# frozen_string_literal: true
2016-12-01 13:08:41 +01:00
require 'coveralls'
Coveralls.wear!('rails')
2016-03-23 18:39:41 +01:00
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
2020-03-30 10:59:11 +02:00
require 'action_dispatch'
2016-03-23 18:39:41 +01:00
require 'rails/test_help'
require 'vcr'
require 'sidekiq/testing'
require 'minitest/reporters'
2022-08-29 17:34:09 +02:00
require 'helpers/invoice_helper'
require 'helpers/archive_helper'
VCR.configure do |config|
2019-04-04 11:57:36 +02:00
config.cassette_library_dir = 'test/vcr_cassettes'
config.hook_into :webmock
config.filter_sensitive_data('sk_test_testfaketestfaketestfake') { Setting.get('stripe_secret_key') }
config.filter_sensitive_data('pk_test_faketestfaketestfaketest') { Setting.get('stripe_public_key') }
2022-08-29 17:34:09 +02:00
config.ignore_request { |req| URI(req.uri).port == 9200 }
end
Sidekiq::Testing.fake!
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)] unless ENV['RM_INFO']
2016-03-23 18:39:41 +01:00
class ActiveSupport::TestCase
2022-08-29 17:34:09 +02:00
include ActionDispatch::TestProcess
include InvoiceHelper
include ArchiveHelper
2016-03-23 18:39:41 +01:00
# Add more helper methods to be used by all tests here...
ActiveRecord::Migration.check_pending!
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
2020-03-11 16:18:17 +01:00
{ 'Accept' => Mime[:json], 'Content-Type' => Mime[:json].to_s }
2016-04-06 15:22:32 +02:00
end
def open_api_headers(token)
{ 'Accept' => Mime[:json], 'Content-Type' => Mime[:json].to_s, 'Authorization' => "Token token=#{token}" }
end
def stripe_payment_method(error: nil)
2019-04-04 11:57:36 +02:00
number = '4242424242424242'
2016-04-06 16:26:45 +02:00
exp_month = 4
exp_year = DateTime.current.next_year.year
2019-04-04 11:57:36 +02:00
cvc = '314'
2016-04-06 16:26:45 +02:00
case error
when /card_declined/
2019-04-04 11:57:36 +02:00
number = '4000000000000002'
2016-04-06 16:26:45 +02:00
when /incorrect_number/
2019-04-04 11:57:36 +02:00
number = '4242424242424241'
2016-04-06 16:26:45 +02:00
when /invalid_expiry_month/
exp_month = 15
when /invalid_expiry_year/
exp_year = 1964
when /invalid_cvc/
2019-04-04 11:57:36 +02:00
cvc = '99'
2021-10-14 18:20:10 +02:00
when /require_3ds/
number = '4000002760003184'
2016-04-06 16:26:45 +02:00
end
Stripe::PaymentMethod.create(
2020-06-10 11:33:03 +02:00
{
type: 'card',
card: {
number: number,
exp_month: exp_month,
exp_year: exp_year,
cvc: cvc
}
},
{ api_key: Setting.get('stripe_secret_key') }
2016-04-06 11:27:56 +02:00
).id
end
# 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
def assert_dates_equal(expected, actual, msg = nil)
assert_not_nil actual, msg
assert_equal expected.to_date, actual.to_date, msg
end
end
class ActionDispatch::IntegrationTest
include Warden::Test::Helpers
Warden.test_mode!
2016-03-23 18:39:41 +01:00
end