spec/requests/labs_spec.rb in medivo-0.2.7 vs spec/requests/labs_spec.rb in medivo-0.2.8

- old
+ new

@@ -1,55 +1,91 @@ require 'spec_helper' describe 'LabController' do - before do - WebMock.allow_net_connect! - end + before { WebMock.allow_net_connect! } describe "showing lab list and map" do - before do @zip_code = "90210" stub(Medivo::Lab).findLabs(@zip_code) { [BeverlyHillsLab1, BeverlyHillsLab2] } end it "/labs/data returns lab and zip data as json" do - visit Medivo::Engine.routes.url_helpers.data_labs_path :zip_code => @zip_code + visit Medivo::Engine.routes.url_helpers.labs_path :zip_code => @zip_code # can't seem to get json back .. just html .. but it works in rails server just fine # so testing for the string will have to do for now page.body.should match /#{BeverlyHillsLab1.name}/i page.body.should match /#{BeverlyHillsLab2.name}/i end it "/labs/search shows search results on the map and list", :js=>true, :driver=>:selenium_chrome do - visit search_labs_path :zip_code=>@zip_code + visit search_labs_path zip_code: @zip_code page.body.should match /465 N ROXBURY DR STE 715, BEVERLY HILLS, CA/i page.body.should match /8737 BEVERLY BLVD STE 401, LOS ANGELES, CA/i end end - describe "making appointments" do + describe "finding appointments" do before do @lab_code = "20060" @date = "11/01/2011" - @am_pm = '' + @am_pm = nil end - it "/labs/appointments returns appointment data as json" do + let(:path) { + Medivo::Engine.routes.url_helpers.find_appointment_labs_path lab_code: @lab_code, date: @date + } + + it "valid request returns appointment times as json" do body = {'time'=> ["11/03/2011|08:30 AM", "11/04/2011|08:30 AM"]} - stub(Medivo::Appointment).find(@lab_code, @date, nil) { body } - visit Medivo::Engine.routes.url_helpers.data_appointments_path :lab_code=>@lab_code, :date=>@date + mock(Medivo::Appointment).find(@lab_code, @date, @am_pm) { body } + visit path page.body.should match "08:30 AM" end - #it "/labs/appointments returns appointment data as json", :js=>true, :driver=>:selenium_chrome do - # body = {'time'=> ["11/03/2011|08:30 AM", "11/04/2011|08:30 AM"]} - # stub(Medivo::Appointment).find(@lab_code, @date, nil) { body } - # visit Medivo::Engine.routes.url_helpers.data_appointments_path :lab_code=>@lab_code, :appointment_date=>@date - # page.body.should match "08:30 AM" + it "invalid request raising ( RestClient::RequestTimeout ) returns error and message info as json" do + exception = RestClient.const_get("RequestTimeout") + mock(Medivo::Appointment).find(@lab_code, @date, @am_pm) { raise exception } + visit path + page.body.should match "Could be lab_code is wrong, or labcorp server is down" + end + + it "invalid request raising ( RestClient::Exception ) returns error and message info as json" do + response = OpenStruct.new(code: 404, body: 'hi rob') + exception = RestClient.const_get("Exception").new(response) + mock(Medivo::Appointment).find(@lab_code, @date, @am_pm) { raise exception } + visit path + page.body.should match response.body + end + + ## TODO, get this working + it "invalid request raising ( Exception ) returns error and message info as json" # do + #response = OpenStruct.new(code: 500 , body: 'whacky exception' ) + #p exception = Exception.new(response) + #mock(Medivo::Appointment).find(@lab_code, @date, @am_pm) { raise exception } + #visit path + #page.body.should match response.body #end end + describe "making appointments" do + before do + @lab_code = "20060" + @time_id = "11/01/2011|8:30 AM" + @user = {first_name: 'dude', last_name: 'man', date_of_birth: '12/28/1980', + email_address: 'dudeman@dude.com', phone_number: '4155551212'} + @params = { lab_code: @lab_code, time_id: @time_id, user: @user } + end + + let(:path) { Medivo::Engine.routes.url_helpers.make_appointment_labs_path } + + it "make appointment" do + response_body = { confirmation: '123' } + stub(Medivo::Appointment).make(@lab_code, @time_id, hash_including(@user) ) { response_body } + post path, @params + response.body.should == response_body.to_json + end + end end