Last active
September 4, 2018 21:31
-
-
Save nicooga/34d3f422d7db4325d22640f5baab6de7 to your computer and use it in GitHub Desktop.
Factory for creating talents for testing in screening wizard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module BaseFactory | |
extend ActiveSupport::Concern | |
include ActiveData::Model | |
included do | |
delegate :pipe, to: :new | |
end | |
class_methods do | |
def defop(name, &block) | |
define_method(name) do |*args| | |
ActiveRecord::Base.transaction do | |
instance_eval(*args, &block) | |
self.talent = talent.reload | |
self | |
end | |
end | |
define_singleton_method(name) do |*args| | |
new.send(name, *args) | |
end | |
end | |
end | |
def initialize(*args) | |
res = super(*args) | |
$talent_factory = self | |
res | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creates a talent for testing in the screening wizzard | |
# | |
# Usage: | |
# | |
# TalentFactory.new | |
# .create_user | |
# .pass_application_submission | |
# .claim_english | |
# .pass_english_step | |
# .talent.user.email | |
# | |
module ScreeningPriorityServicePatch | |
def call | |
:high | |
end | |
end | |
ScreeningPriorityService.prepend ScreeningPriorityServicePatch | |
require 'active_data' | |
class TalentFactory | |
include BaseFactory | |
attribute :id, Integer | |
attribute :email, String, default: 'auto.created.talent@toptal.io' | |
attribute :password, String, default: '123123' | |
attribute :priority, String, default: :high | |
attribute :vertical, String, default: :developer | |
attribute :claimer, Role, default: -> { Admin.active.first } | |
attribute :online_test_result, Integer, default: 150 | |
def talent | |
@talent ||= | |
if id then Talent.find(id) | |
elsif email then Talent.find_by(email: email) | |
end | |
end | |
def talent=(t) | |
@talent = t | |
end | |
defop :create_approved_developer do | |
create_almost_approved_talent.approve_toptal_email | |
end | |
defop :create_almost_approved_talent do | |
create_user | |
.pass_application_submission | |
.claim_english.pass_english_step | |
.claim_online_test.complete_online_test | |
.claim_tech_one.approve_tech_one | |
.claim_tech_two.approve_tech_two | |
.claim_project.approve_project | |
.claim_payment.approve_payment | |
.claim_training.approve_training | |
.claim_work_hours.approve_work_hours | |
.claim_profile_creation.approve_profile_creation | |
.approve_legal | |
.claim_profile_editing.approve_profile_editing | |
.claim_toptal_email | |
end | |
defop :create_designer do | |
self.vertical = :designer | |
create_user | |
end | |
defop :create_designer_on_portfolio_upload_step do | |
create_designer | |
.pass_application_submission | |
.claim_english | |
.pass_english_step | |
end | |
defop :create_developer_on_english_step do | |
create_user | |
.pass_application_submission | |
.claim_english | |
end | |
defop :create_user do | |
activate_chameleon_sw = ->(key) do | |
Chameleon::Participation.new.participate_in(key) | |
end | |
predicted_id = Talent.last.id + 1 | |
if User.where(email: email).exists? | |
email_array = email.split('@') | |
self.email = "#{email_array.first}+#{predicted_id}+@#{email_array.second}" | |
end | |
create_ba = BA::Talent::CreateApplicant.as_system.new( | |
talent_kind: vertical, | |
email: email, | |
password: password, | |
password_confirmation: password, | |
full_name: "TALENT #{vertical} #{predicted_id}", | |
acknowledge_confidentiality: true | |
) | |
create_ba.subject.new_talent_onboarding_flow_enabled = true | |
create_ba.subject.screening_wizard_enabled = true | |
create_ba.perform! | |
new_talent = create_ba.subject | |
BA::User::ConfirmNewTalent.as_system.new(new_talent.user).perform! | |
self.talent = new_talent | |
end | |
defop :upload_resume do | |
perform_action( | |
BA::Talent::SaveApplication | |
.as(talent) | |
.new(talent, resume: open_file('resume.pdf')) | |
) | |
end | |
defop :pass_application_submission do | |
perform_action( | |
BA::Talent::Onboarding::SubmitApplicationDetails | |
.as(talent) | |
.new( | |
talent, | |
applicant_skill_ids: %w[7889 684], | |
legal_name: talent.full_name, | |
citizenship_id: '196', | |
country_id: '196', | |
city: 'Belgrade, Serbia', | |
place_id: 'ChIJvT-116N6WkcR5H4X8lxkuB0', | |
city_name: 'Belgrade', | |
resume: open_file('resume.pdf'), | |
photo: open_file('2048x2048_photo_cropped.jpg') | |
) | |
) | |
end | |
defop :claim_english do | |
BA::Step::ClaimEnglish.as(claimer).new(step: talent.next_step, talent: talent).perform! | |
end | |
defop :pass_english_step do | |
BA::Step::ApproveEnglish.as(claimer).new( | |
talent.next_step, | |
comment: 'ok', | |
new_applicant_skill_names: [], | |
talent: talent, | |
specialization_id: '1', | |
applicant_skill_ids: %w[7889 684] | |
).perform! | |
end | |
defop :claim_online_test do | |
BA::Step::ClaimOnlineTest.as(claimer).new( | |
step: talent.next_step, | |
talent: talent, | |
test_option: :codility, | |
online_test_id: 2 | |
).perform! | |
end | |
defop :complete_online_test do | |
online_test = talent.online_test_results.first | |
report = { | |
url: "/#{online_test.external_id}", | |
report_url: "/#{online_test.external_id}", | |
id: online_test.external_id, | |
candidate: talent.id, | |
evaluation: { | |
result: online_test_result, | |
max_result: 300 | |
}, | |
score: online_test_result, | |
max_score: 300 | |
} | |
if online_test.is_a?(CodilityResult) | |
BA::CodilityResult::ProcessReport.as_system.new(report: report) | |
else | |
BA::HackerRankResult::ProcessReport.as_system.new(online_test, report: report) | |
end.perform! | |
end | |
defop :claim_tech_one do | |
BA::Step::ClaimTechnicalOne.as(claimer).new(talent.next_step, talent: talent).perform! | |
end | |
defop :approve_tech_one do | |
BA::Step::ApproveTechnicalOne.as(claimer).new(talent.next_step, talent: talent, comment: "Meh").perform! | |
end | |
defop :claim_tech_two do | |
BA::Step::ClaimTechnicalTwo.as(claimer).new(talent.next_step, talent: talent).perform! | |
end | |
defop :approve_tech_two do | |
BA::Step::ApproveTechnicalTwo.as(claimer).new(talent.next_step, talent: talent, comment: "Blah").perform! | |
end | |
defop :claim_project do | |
BA::Step::ClaimProject.as(claimer).new(talent.next_step, talent: talent).perform! | |
end | |
defop :approve_project do | |
BA::Step::ApproveProject.as(claimer).new(talent.next_step, talent: talent, comment: "Bleh").perform! | |
end | |
defop :claim_payment do | |
BA::Step::ClaimPayment.as(claimer).new(talent.next_step, talent: talent).perform! | |
end | |
defop :approve_payment do | |
talent.update(hourly_rate: 40) | |
BA::Step::ApprovePayment.as(claimer).new(talent.next_step, talent: talent, comment: "Blabla").perform! | |
end | |
defop :claim_training do | |
BA::Step::ClaimTraining.as(claimer).new(talent.next_step, talent: talent).perform! | |
end | |
defop :approve_training do | |
BA::Step::ApproveTraining.as(claimer).new(talent.next_step, talent: talent, comment: "Asdfsdf").perform! | |
end | |
defop :claim_work_hours do | |
BA::Step::ClaimWorkHours.as(claimer).new(talent.next_step, talent: talent).perform! | |
end | |
defop :approve_work_hours do | |
BA::Step::ApproveWorkHours.as(claimer).new( | |
talent.next_step, | |
talent: talent, | |
allocated_hours: 40, | |
comment: "Asdfsdf" | |
).perform! | |
end | |
defop :claim_profile_creation do | |
BA::Step::ClaimProfileCreation.as(claimer).new(talent.next_step, talent: talent).perform! | |
end | |
defop :approve_profile_creation do | |
BA::Step::ApproveProfileCreation.as(claimer).new(talent.next_step, talent: talent, comment: "Asdfsdf").perform! | |
end | |
defop :claim_legal do | |
BA::Step::ClaimLegal.as(claimer).new(talent.next_step, talent: talent).perform! | |
end | |
defop :approve_legal do | |
%i[tax_form talent_agreement].each do |kind| | |
talent.contracts.create!( | |
subject: talent, | |
kind: kind, | |
status: :signed, | |
sent_at: Time.now, | |
title: kind, | |
guid: 22.times.map { rand(0..9) }.join, | |
signed_at: Time.now, | |
signature_received_at: Time.now | |
) | |
end | |
BA::Step::ApproveLegal.as(claimer).new(talent.next_step, talent: talent, comment: "Asdfsdf").perform! | |
end | |
defop :claim_profile_editing do | |
BA::Step::ClaimProfileEditing.as(claimer).new(talent.next_step, talent: talent).perform! | |
end | |
defop :approve_profile_editing do | |
BA::Step::ApproveProfileEditing.as(claimer).new(talent.next_step, talent: talent, comment: "Asdfsdf").perform! | |
end | |
defop :claim_toptal_email do | |
BA::Step::ClaimToptalEmail.as(claimer).new(talent.next_step, talent: talent).perform! | |
end | |
defop :approve_toptal_email do | |
talent.update!(toptal_email: "auto.created.talent+#{talent.id}+@toptal.io") | |
BA::Step::ApproveToptalEmail.as(claimer).new(talent.next_step, talent: talent, comment: "Asdfsdf").perform! | |
end | |
def email=(email) | |
t = Talent.joins(:user).find_by(users: { email: email }) | |
self.talent = t if t | |
super(email) | |
end | |
private | |
def open_file(filename) | |
File.open Rails.root.join('testing', 'support', 'files', filename).to_s | |
end | |
def perform_action(action) | |
$last_performed_action = action | |
action.perform! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment