Skip to content

Instantly share code, notes, and snippets.

@matsales28
Created November 29, 2019 13:54
Show Gist options
  • Save matsales28/bf62831c30720182d040eaf3cca40ef2 to your computer and use it in GitHub Desktop.
Save matsales28/bf62831c30720182d040eaf3cca40ef2 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require 'simplecov'
require 'simplecov-console'
require 'capybara'
require "minitest/reporters"
require 'webmock/minitest'
class Minitest::Reporters::SpecReporter
def record_print_status(test)
print_colored_status(test)
print(" (%.2fs)" % test.time) unless test.time.nil?
test_name = test.name.gsub(/^test_: /, 'test:')
print pad_test(test_name)
puts
end
end
Minitest::Reporters.use! Minitest::Reporters::ProgressReporter.new
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::Console,
])
SimpleCov.start 'rails' do
add_filter 'application_cable/channel.rb'
add_filter 'application_cable/connection.rb'
add_filter 'application_record.rb'
add_filter 'application_job.rb'
add_filter 'application_mailer.rb'
end
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
require 'rails/test_help'
require 'minitest/autorun'
require 'sidekiq/testing'
# Sidekiq Unique Jobs hits Redis even if Sidekiq itself doesn't
SidekiqUniqueJobs.configure do |config|
config.enabled = false
end
Sidekiq::Testing.fake!
class ActiveSupport::TestCase
extend ActionDispatch::TestProcess
fixtures :all
include WebMock::API
include FactoryBot::Syntax::Methods
# Run tests in parallel with specified workers
# parallelize(workers: :number_of_processors)
# Setup all fixtures in test/fixtures/*.yml
# for all tests in alphabetical order.
def admin_sign_in
stub_request(:post, "#{ENV['FACTORY_HOST']}/api/v1/gomagics/auth")
.with(
body: {'email'=>'admin@gocase.com.br', 'password'=>'lovegocase'},
headers: {
'Accept' => '*/*',
'Content-Type' => 'application/x-www-form-urlencoded',
'Host' => 'localhost:3001'
}).
to_return(status: 200, body: {'id':1,'name':'GoCase Admin','email':'admin@gocase.com.br','factories':['fortaleza','fortaleza'],'locale':'pt-BR','able_to_auth':true}.to_json , headers: {})
post sessions_user_path \
'user[email]' => 'admin@gocase.com.br',
'user[password]' => 'lovegocase'
end
def mock
stub_request(:get, "#{ENV['FACTORY_HOST']}/api/v1/gomagics/factory/companies")
.with(
headers: {
'Accept'=>'*/*',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Host'=>'localhost:3001',
'User-Agent'=>'rest-client/2.1.0 (linux-gnu x86_64) ruby/2.6.5p114'
}).
to_return(status: 200, body: {'results':[['Resellers Global',19],['Gocase Fábrica. Fortaleza - CE',6],
['Manual Label Global',17],['Las Capinhas',20],['Site Global',2],['Etiquetas Manuais BR',16],
['Influencers Global',15],['Totem Iguatemi Store',26],['Produção',28],['Novos Produtos',29],
['Prototipos Reseller',30],['Prototipos Offline',31],['Prototipos Parceria',33],
['Totem Iguatemi Kioski In Loco',34],['Totem NL Store',35],['Totem Iguatemi Store In Loco',27],
['Influencer Special BR',37],['Influencer Special Global',38],['Site BR',1],['Totem Iguatemi',22],
['Influenciadores BR',14],['Prototypes GLOBAL',25],['Protótipos BR',24],['Prototipos Influencer',32],
['Subscription Box',40],['Gocase Tietê Plaza. São Paulo - SP',10],['Gocase Iguatemi. Fortaleza - CE',9],
['Influencer Tester Growth',39],['NL Store 2',41],['Gocase Villa Lobos São Paulo - SP',13],
['Gocase Patio Paulista. São Paulo - SP',23],['Resellers Brasil',21],['GRN Matriz',18],
['Gocase Grand Plaza. Santo André - SP',11],['Protótipos Sorteios',36],
['Gocase Cidade São Paulo. São Paulo - SP',7]]}.to_json, headers: {})
stub_request(:get, "#{ENV['FACTORY_HOST']}/api/v1/gomagics/factory/aasm_states").
with(
headers: {
'Accept'=>'*/*',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Host'=>'localhost:3001',
'User-Agent'=>'rest-client/2.1.0 (linux-gnu x86_64) ruby/2.6.5p114'
}).
to_return(status: 200, body: {'results':[['Aguardando','waiting'],['Produção','production'],
['Fechamento','closing'],['Pendente','pending'],['Cancelado','canceled'],['Enviado','sent'],
['Reembolsado','reimbursed'],['PLP','posting'],['Entregue','delivered'],
['Reembolso Cancelado','reimburse_canceled'],['Parcialmente Reembolsado','partial_reimbursed']]}.to_json,
headers: {})
stub_request(:get, "#{ENV['FACTORY_HOST']}/api/v1/gomagics/factory/materials_categories").
with(
headers: {
'Accept'=>'*/*',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Host'=>'localhost:3001',
'User-Agent'=>'rest-client/2.1.0 (linux-gnu x86_64) ruby/2.6.5p114'
}).
to_return(status: 200, body: {'results':[['Kit','kit'],['Earphone','earphone'],['Glitter','glitter'],
['Wallpaper','wallpaper'],['Pencil Bag','pencilbag'],['Waist Bag','waistbag'],['Grip','grip'],
['Electric Charger','electric-charger'],['Electric Charger Custom','electric-charger-custom'],
['Gift','gift'],['Pocket','pocket'],['Powerbank','powerbank'],['Package','package'],
['Headphone','headphone'],['Screen Cleaner','screen-cleaner'],['Gift Case','gift-case'],
['Lunch Bag','lunchbag'],['Adapter','adapter'],['Envelope','envelope'],['Bag','bag'],
['Headphone Body','headphone-body'],['Headphone Lid','headphone-lid'],['Powerbank Lid','powerbank-lid'],
['Sketchbook','sketchbook'],['Tablet','tabletcase'],['Case Clear','case-clear'],['Laptop','laptopcase'],
['Wallet','wallet'],['Case','case'],['Clutch','clutch'],['ring Kit','ring'],['Premium Box','premium-box'],
['Backpack','backpack'],['Microbag','microbag'],['Transfer Cable','transfer-cable'],
['Transfer Cable Custom','transfer-cable-custom'],['Skin','skin'],['Skin Custom','skin-custom'],
['Skin Double','skin-double'],['Accessory Bag','accessorybag'],['Digital Gift Card','digital-gift-card'],
['Battery','battery'],['Necessaire','necessaire'],['Sticker Book','stickerbbok'],
['Invoices / Labels','Invoices / Labels'],['Returns','Returns'],['Organizer','organizer'],
['Subscription','subscription'],['Lunch Box','lunchbox'],['Travel Bag','travelbag'],['Sticker','sticker'],
['Donation','donation'],['Powerbank Lid Clear','powerbank-lid-clear'],['Watchband','watchband']]}.to_json,
headers: {})
end
def assert_validation_error(field, message = "can't be blank")
assert_select ".input.#{field}.field_with_errors .error", message
end
def orders_mock
orders = File.read('test/models/order_mock.json')
@formatted_orders = JSON.parse(
orders, object_class: OpenStruct
)['message']['orders']
@formatted_orders.each do |o|
o.deadline = DateTime.parse(o.deadline)
end
@formatted_orders
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment