require 'spec_helper'
describe CareerBuilder::Client do
describe "#authenticate" do
context "with valid credentials" do
before do
stub_request(:post, "http://ws.careerbuilder.com/resumes/resumes.asmx/BeginSessionV2").with(:body => 'Packet=%3cPacket%3e%3cEmail%3evalid_email%3c%2fEmail%3e%3cPassword%3evalid_password%3c%2fPassword%3e%3c%2fPacket%3e').to_return(:body => "\r\n<Packet><Errors /><SessionToken>42df77a98a874c6ca8644cf8e8ceffa6-330779842-RY-4</SessionToken></Packet>")
@client = CareerBuilder::Client.new("valid_email", "valid_password")
end
it 'should return true' do
@client.authenticate.should be_true
end
it 'should be authenticated' do
@client.authenticate
@client.should be_authenticated
end
end
context "with invalid credentials" do
before do
stub_request(:post, "http://ws.careerbuilder.com/resumes/resumes.asmx/BeginSessionV2").with(:body => 'Packet=%3cPacket%3e%3cEmail%3evalid_email%3c%2fEmail%3e%3cPassword%3einvalid_password%3c%2fPassword%3e%3c%2fPacket%3e').to_return(:body => "\r\n<Packet><Errors><CBError><Code>300</Code><Text>300|Email (ryan@recruitmilitary.com) and password (AZG24N4) could not be validated.</Text></CBError></Errors><SessionToken>Invalid</SessionToken></Packet>")
@client = CareerBuilder::Client.new("valid_email", "invalid_password")
end
it 'should return false' do
@client.authenticate.should be_false
end
it 'should not be authenticated' do
@client.authenticate
@client.should_not be_authenticated
end
end
end
describe "#advanced_resume_search" do
context "with invalid credentials" do
before do
@client = CareerBuilder::Client.new("valid_email", "invalid_password")
@client.stub(:authenticate).and_return(false)
end
context "with valid options" do
it 'should raise InvalidCredentials' do
expect {
@client.advanced_resume_search(:keywords => "Ruby")
}.to raise_error(CareerBuilder::InvalidCredentials)
end
end
context "with invalid options" do
it 'should raise ArgumentError' do
expect {
@client.advanced_resume_search(:foo => "bar")
}.to raise_error(ArgumentError)
end
end
end
context "with valid credentials" do
before do
@client = CareerBuilder::Client.new("valid_email", "valid_password")
@client.stub(:session_token).and_return(42)
@client.stub(:authenticate).and_return(true)
end
context "with valid options" do
before do
stub_request(:post, "http://ws.careerbuilder.com/resumes/resumes.asmx/V2_AdvancedResumeSearch").with(:body => 'Packet=%3cPacket%3e%3cSessionToken%3e42%3c%2fSessionToken%3e%3cKeywords%3eRuby%3c%2fKeywords%3e%3c%2fPacket%3e').to_return(:body => "\r\n<Packet><Errors /><PageNumber>1</PageNumber><SearchTime>06/25/2010 12:03:14</SearchTime><FirstRec>1</FirstRec><LastRec>100</LastRec><Hits>3</Hits><MaxPage>1</MaxPage><Results><ResumeResultItem_V3><ContactEmail>Rhd4G067G4JVTLW99H7_A7C14Q67VKG000YBSCR~CBWS^U7A3LY6YY46V1MT0RJK@resume.cbdr.com</ContactEmail><ContactName>Rebecca Bernard</ContactName><HomeLocation>US-OH-Milford</HomeLocation><LastUpdate>2010/5/13</LastUpdate><ResumeTitle>BERNARD_SYSTEMS_ENGINEER</ResumeTitle><JobTitle>BERNARD_SYSTEMS_ENGINEER</JobTitle><RecentEmployer>TATA CONSULTANCY SERVICES</RecentEmployer><RecentJobTitle>CONSULTANCY SERVICES- Systems Engineer</RecentJobTitle><RecentPay>0</RecentPay><ResumeID>Rhd4G067G4JVTLW99H7</ResumeID><UserDID>U7X86R61VVKS4FWS03T</UserDID><ContactEmailMD5>139013c2fa2b945bdc340f8a698b009e</ContactEmailMD5></ResumeResultItem_V3><ResumeResultItem_V3><ContactEmail>Rhe7TZ764LHG1GQTPSM_A7C14Q67VKG000YBSCR~CBWS^U7A3LY6YY46V1MT0RJK@resume.cbdr.com</ContactEmail><ContactName>chris grader</ContactName><HomeLocation>US-OH-Milford</HomeLocation><LastUpdate>2010/6/4</LastUpdate><ResumeTitle>Chris Grader resume</ResumeTitle><JobTitle>Chris Grader resume</JobTitle><RecentEmployer>Millennial Medical, Inc</RecentEmployer><RecentJobTitle>Regional Sales Manager/Midwest Distributor</RecentJobTitle><RecentPay>0</RecentPay><ResumeID>Rhe7TZ764LHG1GQTPSM</ResumeID><UserDID>U346V1MKGCHPGCF9S8</UserDID><ContactEmailMD5>cfba57bf848b78211d99348cf0f90879</ContactEmailMD5></ResumeResultItem_V3><ResumeResultItem_V3><ContactEmail>RH52G867678F7GH02Q3_A7C14Q67VKG000YBSCR~CBWS^U7A3LY6YY46V1MT0RJK@resume.cbdr.com</ContactEmail><ContactName>Jeffrey Davis</ContactName><HomeLocation>US-OH-Goshen</HomeLocation><LastUpdate>2010/5/23</LastUpdate><ResumeTitle>Warehouse Distribution Specialist</ResumeTitle><JobTitle>Warehouse Distribution Specialist</JobTitle><RecentEmployer>OWENS & MINOR</RecentEmployer><RecentJobTitle>Warehouse Lead Supervisor</RecentJobTitle><RecentPay>35776</RecentPay><ResumeID>RH52G867678F7GH02Q3</ResumeID><UserDID>U1C29V68M3YM95SP0XK</UserDID><ContactEmailMD5>e814ebaa93aae5c3719e27d26d5af917</ContactEmailMD5></ResumeResultItem_V3></Results></Packet>")
@search = @client.advanced_resume_search(:keywords => "Ruby")
end
it 'should have the correct page number' do
@search.page_number.should == 1
end
it 'should have the correct search time' do
@search.search_time.should == Time.mktime(2010, 6, 25, 12, 3, 14)
end
it 'should return the correct number of hits' do
@search.hits.should == 3
end
it 'should return the correct max page' do
@search.max_page.should == 1
end
describe "#results" do
before do
@results = @search.results
@result = @results.first
end
it 'should return the correct contact email' do
@result.contact_email.should == "Rhd4G067G4JVTLW99H7_A7C14Q67VKG000YBSCR~CBWS^U7A3LY6YY46V1MT0RJK@resume.cbdr.com"
end
it 'should return the correct contact name' do
@result.contact_name.should == "Rebecca Bernard"
end
it 'should return the correct home location' do
@result.home_location.should == "US-OH-Milford"
end
it 'should return the correct last update' do
@result.last_update.should == Date.new(2010, 5, 13)
end
it 'should return the correct resume title' do
@result.title.should == "BERNARD_SYSTEMS_ENGINEER"
end
it 'should return the correct job title' do
@result.job_title.should == "BERNARD_SYSTEMS_ENGINEER"
end
it 'should return the correct recent pay' do
@result.recent_pay.should == 0
end
it 'should return the correct id' do
@result.id.should == "Rhd4G067G4JVTLW99H7"
end
it 'should return the correct user id' do
@result.user_did.should == "U7X86R61VVKS4FWS03T"
end
it 'should return the correct contact email md5' do
@result.contact_email_md5.should == "139013c2fa2b945bdc340f8a698b009e"
end
end
end
context "with invalid options" do
it 'should raise ArgumentError' do
expect {
@client.advanced_resume_search(:foo => "bar")
}.to raise_error(ArgumentError)
end
end
end
end
describe "get_resume" do
context "with invalid credentials" do
before do
@client = CareerBuilder::Client.new("valid_email", "invalid_password")
@client.stub(:authenticate).and_return(false)
end
context "with valid options" do
it 'should raise InvalidCredentials' do
expect {
@client.get_resume(:resume_id => "4242424242")
}.to raise_error(CareerBuilder::InvalidCredentials)
end
end
context "with invalid options" do
it 'should raise ArgumentError' do
expect {
@client.get_resume(:foo => "bar")
}.to raise_error(ArgumentError)
end
end
end
context "with valid credentials" do
before do
@client = CareerBuilder::Client.new("valid_email", "valid_password")
@client.stub(:session_token).and_return(42)
@client.stub(:authenticate).and_return(true)
end
context "with invalid options" do
it 'should raise ArgumentError' do
expect {
@client.get_resume(:foo => "bar")
}.to raise_error(ArgumentError)
end
end
context "when out of credits" do
before do
stub_request(:post, "http://ws.careerbuilder.com/resumes/resumes.asmx/V2_GetResume").with(:body => 'Packet=%3cPacket%3e%3cSessionToken%3e42%3c%2fSessionToken%3e%3cResumeID%3eRH52G867678F7GH02Q3%3c%2fResumeID%3e%3c%2fPacket%3e').to_return(:body => "\r\n<Packet><Warning></Warning></Packet>")
end
it 'should raise OutOfCredits' do
expect {
@resume = @client.get_resume(:resume_id => "RH52G867678F7GH02Q3")
}.to raise_error(CareerBuilder::OutOfCredits)
end
end
context "with valid options" do
RAW_RESUME_RESPONSE = "\r\n<Packet><TimeStamp>6/25/2010 3:19:20 PM</TimeStamp><ResumeID>RH52G867678F7GH02Q3</ResumeID><ResumeTitle>Warehouse Distribution Specialist</ResumeTitle><ContactName>Jeffrey Davis</ContactName><ContactEmail>Jeffd1969@aol.com</ContactEmail><ContactPhone>513-625-7228</ContactPhone><HomeLocation><City>Goshen</City><State>OH</State><Country>US</Country><ZipCode>45122</ZipCode><WorkStatus>Can work for any employer</WorkStatus></HomeLocation><Relocations><ExtLocation><City>Tokyo</City><State/><Country>JP</Country><ZipCode /><WorkStatus>Can work for any employer</WorkStatus></ExtLocation></Relocations><MaxCommuteMiles>10</MaxCommuteMiles><TravelPreference>Up to 25%</TravelPreference><CurrentlyEmployed>Yes</CurrentlyEmployed><MostRecentPay><Amount>35776</Amount><Per>year</Per></MostRecentPay><DesiredPay><Amount>45000</Amount><Per>year</Per></DesiredPay><DesiredJobTypes><string>Full Time</string></DesiredJobTypes><MostRecentTitle>Warehouse Lead Supervisor</MostRecentTitle><ExperienceMonths>216</ExperienceMonths><Management><ManagedOthers>No</ManagedOthers><NumberManaged>0</NumberManaged></Management><JobsLastThreeYears>0</JobsLastThreeYears><LastJobTenureMonths>0</LastJobTenureMonths><SecurityClearance>No</SecurityClearance><FelonyConvictions>No</FelonyConvictions><HighestDegree>None</HighestDegree><Certifications /><MotivationToChangeJobs /><EmploymentType /><LastUpdated>5/23/2010 10:41:12 PM</LastUpdated><Languages><string>English</string></Languages><DesiredShiftPreferences><string /></DesiredShiftPreferences><Interests><ExtInterest><Interest>Warehouse</Interest><ExperienceMonths>216</ExperienceMonths></ExtInterest></Interests><ResumeText>JEFFREY A. DAVIS</ResumeText><MilitaryExperience>Veteran</MilitaryExperience><WorkHistory><ExtCompany><CompanyName>OWENS & MINOR</CompanyName><JobTitle>Warehouse Lead Supervisor</JobTitle><Tenure>01/01/2008 - Present</Tenure></ExtCompany><ExtCompany><CompanyName>THE HOME DEPOT</CompanyName><JobTitle>- Sales Specialist</JobTitle><Tenure>01/01/2005 - Present</Tenure></ExtCompany><ExtCompany><CompanyName>RUBIES COSTUME CO</CompanyName><JobTitle>- Warehouse Assistant Manager</JobTitle><Tenure>01/01/2004 - 01/01/2006</Tenure></ExtCompany><ExtCompany><CompanyName>UNITED ELECTRIC POWER</CompanyName><JobTitle>Inventory Operations Manager</JobTitle><Tenure>01/01/2000 - 01/01/2004</Tenure></ExtCompany><ExtCompany><CompanyName>VEECO INSTRUMENTS, INC</CompanyName><JobTitle>Warehouse Supervisor</JobTitle><Tenure>01/01/1996 - 01/01/2000</Tenure></ExtCompany></WorkHistory><EducationHistory><ExtSchool><SchoolName>Eastern Oklahoma State College</SchoolName><Major>Business Management</Major><Degree /><GraduationDate>11993</GraduationDate></ExtSchool><ExtSchool><SchoolName>Suffolk County Community College</SchoolName><Major>Business Management</Major><Degree /><GraduationDate>11997</GraduationDate></ExtSchool></EducationHistory><Warning></Warning></Packet>".freeze
before do
stub_request(:post, "http://ws.careerbuilder.com/resumes/resumes.asmx/V2_GetResume").with(:body => 'Packet=%3cPacket%3e%3cSessionToken%3e42%3c%2fSessionToken%3e%3cResumeID%3eRH52G867678F7GH02Q3%3c%2fResumeID%3e%3c%2fPacket%3e').to_return(:body => RAW_RESUME_RESPONSE)
@resume = @client.get_resume(:resume_id => "RH52G867678F7GH02Q3")
end
# despite the fact that career builder gives us jacked up
# double encoded XML, let's retrieve the Resume#raw_response
# in a sane way.
it 'should return the raw response' do
@resume.raw_response.should == "\n6/25/2010 3:19:20 PMRH52G867678F7GH02Q3Warehouse Distribution SpecialistJeffrey DavisJeffd1969@aol.com513-625-7228GoshenOHUS45122Can work for any employerTokyoJPCan work for any employer10Up to 25%Yes35776year45000yearFull TimeWarehouse Lead Supervisor216No000NoNoNone5/23/2010 10:41:12 PMEnglishWarehouse216JEFFREY A. DAVISVeteranOWENS & MINORWarehouse Lead Supervisor01/01/2008 - PresentTHE HOME DEPOT- Sales Specialist01/01/2005 - PresentRUBIES COSTUME CO- Warehouse Assistant Manager01/01/2004 - 01/01/2006UNITED ELECTRIC POWERInventory Operations Manager01/01/2000 - 01/01/2004VEECO INSTRUMENTS, INCWarehouse Supervisor01/01/1996 - 01/01/2000Eastern Oklahoma State CollegeBusiness Management11993Suffolk County Community CollegeBusiness Management11997"
end
it 'should return the correct timestamp' do
@resume.timestamp.should == Time.mktime(2010, 6, 25, 15, 19, 20)
end
it 'should return the correct id' do
@resume.id.should == "RH52G867678F7GH02Q3"
end
it 'should return the correct title' do
@resume.title.should == "Warehouse Distribution Specialist"
end
it 'should return the correct contact name' do
@resume.contact_name.should == "Jeffrey Davis"
end
it 'should return the correct contact email' do
@resume.contact_email.should == "Jeffd1969@aol.com"
end
it 'should return the correct contact phone' do
@resume.contact_phone.should == "513-625-7228"
end
describe "#home_location" do
before do
@home_location = @resume.home_location
end
it 'should return the correct city' do
@home_location.city.should == "Goshen"
end
it 'should return the correct state' do
@home_location.state.should == "OH"
end
it 'should return the correct zip code' do
@home_location.zip_code.should == "45122"
end
it 'should return the correct country' do
@home_location.country.should == "US"
end
it 'should return the correct work status' do
@home_location.work_status.should == "Can work for any employer"
end
end
describe "#relocations" do
before do
@relocations = @resume.relocations
@relocation = @relocations.first
end
it 'should return the correct city' do
@relocation.city.should == "Tokyo"
end
it 'should return the correct state' do
@relocation.state.should == ""
end
it 'should return the correct zip code' do
@relocation.zip_code.should == ""
end
it 'should return the correct country' do
@relocation.country.should == "JP"
end
it 'should return the correct work status' do
@relocation.work_status.should == "Can work for any employer"
end
end
it 'should return the correct max commute miles' do
@resume.max_commute_miles.should == 10
end
it 'should return the correct travel preference' do
@resume.travel_preference.should == "Up to 25%"
end
it 'should return the correct currently employed' do
@resume.currently_employed.should == "Yes"
end
describe "#most_recent_pay" do
before do
@most_recent_pay = @resume.most_recent_pay
end
it 'should return the correct amount' do
@most_recent_pay.amount.should == 35776
end
it 'should return the correct per' do
@most_recent_pay.per.should == "year"
end
end
describe "#desired_pay" do
before do
@desired_pay = @resume.desired_pay
end
it 'should return the correct amount' do
@desired_pay.amount.should == 45000
end
it 'should return the correct per' do
@desired_pay.per.should == "year"
end
end
describe "#desired_job_types" do
before do
@desired_job_types = @resume.desired_job_types
@desired_job_type = @desired_job_types.first
end
it 'should return the correct text' do
@desired_job_type.text.should == "Full Time"
end
end
it 'should return the correct most recent title' do
@resume.most_recent_title.should == "Warehouse Lead Supervisor"
end
it 'should return the correct experience months' do
@resume.experience_months.should == 216
end
it 'should return the correct managed others' do
@resume.managed_others.should == "No"
end
it 'should return the correct number managed' do
@resume.number_managed.should == 0
end
it 'should return the correct jobs last three years' do
@resume.jobs_last_three_years.should == 0
end
it 'should return the correct last job tenure months' do
@resume.last_job_tenure_months.should == 0
end
it 'should return the correct security clearance' do
@resume.security_clearance.should == "No"
end
it 'should return the correct felony convictions' do
@resume.felony_convictions.should == "No"
end
it 'should return the correct highest degree' do
@resume.highest_degree.should == "None"
end
it 'should return the correct certifications' do
@resume.certifications.should == ""
end
it 'should return the correct motivation to change jobs' do
@resume.motivation_to_change_jobs.should == ""
end
it 'should return the correct employment type' do
@resume.employment_type.should == ""
end
it 'should return the correct last updated' do
@resume.last_updated.should == Time.mktime(2010, 5, 23, 22, 41, 12)
end
describe "#languages" do
before do
@languages = @resume.languages
@language = @languages.first
end
it 'should return the correct text' do
@language.text.should == "English"
end
end
describe "#desired_shift_preferences" do
before do
@desired_shift_preferences = @resume.desired_shift_preferences
@desired_shift_preference = @desired_shift_preferences.first
end
it 'should return the correct desired shift preferences' do
@desired_shift_preference.text.should == ""
end
end
describe "#interests" do
before do
@interests = @resume.interests
@interest = @interests.first
end
it 'should return the correct interest' do
@interest.interest.should == "Warehouse"
end
it 'should return the correct experience in months' do
@interest.experience_months.should == 216
end
end
it 'should return the correct resume text' do
@resume.text.should == "JEFFREY A. DAVIS"
end
it 'should return the military experience' do
@resume.military_experience.should == "Veteran"
end
describe "#companies" do
before do
@companies = @resume.companies
@company = @companies.first
end
it 'should return the correct company name' do
@company.name.should == "OWENS & MINOR"
end
it 'should return the correct job title' do
@company.job_title.should == "Warehouse Lead Supervisor"
end
it 'should return the correct tenure' do
@company.tenure.should == "01/01/2008 - Present"
end
end
describe "#schools" do
before do
@schools = @resume.schools
@school = @schools.first
end
it 'should return the correct school name' do
@school.name.should == "Eastern Oklahoma State College"
end
it 'should return the correct major' do
@school.major.should == "Business Management"
end
it 'should return the correct degree' do
@school.degree.should == ""
end
it 'should return the correct graduation date' do
@school.graduation_date.should == "11993"
end
end
it 'should return the correct warning' do
@resume.warning.should == ""
end
end
end
end
describe "#resume_actions_remaining_today" do
before do
stub_request(:post, "http://ws.careerbuilder.com/resumes/resumes.asmx/V2_ResumeActionsRemainingToday").with(:body => 'Packet=%3cPacket%3e%3cSessionToken%3e42%3c%2fSessionToken%3e%3cAccountDID%3eD7D15Q67VKG105ZB12%3c%2fAccountDID%3e%3c%2fPacket%3e').to_return(:body => "\r\n<Packet>1</Packet>")
@client = CareerBuilder::Client.new("valid_email", "valid_password")
@client.stub(:session_token).and_return(42)
@client.stub(:authenticate).and_return(true)
end
it 'should return the number of credits remaining' do
@client.resume_actions_remaining_today(:account_did => "D7D15Q67VKG105ZB12").should == 1
end
end
end