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'
|
2020-12-15 15:48:13 +01:00
|
|
|
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'
|
2016-04-06 15:15:09 +02:00
|
|
|
require 'vcr'
|
2016-04-04 17:42:45 +02:00
|
|
|
require 'sidekiq/testing'
|
|
|
|
require 'minitest/reporters'
|
2022-08-29 17:34:09 +02:00
|
|
|
require 'helpers/invoice_helper'
|
|
|
|
require 'helpers/archive_helper'
|
2019-10-01 14:32:30 +02:00
|
|
|
|
2016-04-06 15:15:09 +02:00
|
|
|
VCR.configure do |config|
|
2019-04-04 11:57:36 +02:00
|
|
|
config.cassette_library_dir = 'test/vcr_cassettes'
|
2016-04-06 15:15:09 +02:00
|
|
|
config.hook_into :webmock
|
2021-06-11 14:29:30 +02:00
|
|
|
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 }
|
2016-04-06 15:15:09 +02:00
|
|
|
end
|
|
|
|
|
2016-04-11 15:31:25 +02:00
|
|
|
Sidekiq::Testing.fake!
|
2021-05-19 18:12:52 +02:00
|
|
|
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)] unless ENV['RM_INFO']
|
2016-04-04 17:42:45 +02:00
|
|
|
|
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...
|
2020-12-15 15:48:13 +01:00
|
|
|
ActiveRecord::Migration.check_pending!
|
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
|
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
|
|
|
|
|
2022-11-23 11:59:06 +01:00
|
|
|
def upload_headers
|
|
|
|
{ 'Accept' => Mime[:json], 'Content-Type' => 'multipart/form-data' }
|
|
|
|
end
|
|
|
|
|
2021-06-28 09:50:37 +02:00
|
|
|
def open_api_headers(token)
|
|
|
|
{ 'Accept' => Mime[:json], 'Content-Type' => Mime[:json].to_s, 'Authorization' => "Token token=#{token}" }
|
|
|
|
end
|
|
|
|
|
2019-09-11 16:19:24 +02:00
|
|
|
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
|
2019-12-02 15:29:05 +01:00
|
|
|
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
|
|
|
|
|
2019-09-11 16:19:24 +02:00
|
|
|
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
|
2016-04-11 15:31:25 +02:00
|
|
|
|
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-12-01 11:37:09 +01:00
|
|
|
|
2018-12-06 18:26:01 +01:00
|
|
|
def assert_dates_equal(expected, actual, msg = nil)
|
|
|
|
assert_not_nil actual, msg
|
|
|
|
assert_equal expected.to_date, actual.to_date, msg
|
|
|
|
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
|