require 'test_helper' class EppContactCreateBaseTest < EppTestCase def test_creates_new_contact_with_required_attributes name = 'new' email = 'new@registrar.test' phone = '+1.2' request_xml = <<-XML #{name} #{phone} #{email} any XML assert_difference 'Contact.count' do post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml assert_epp_response :completed_successfully contact = Contact.find_by(name: name) assert_equal name, contact.name assert_equal email, contact.email assert_equal phone, contact.phone assert_not_empty contact.code end def test_responses_with_error_on_birthday name = 'new' email = 'new@registrar.test' phone = '+1.2' request_xml = <<-XML #{name} #{phone} #{email} 31-12-2000 XML assert_no_difference 'Contact.count' do post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml assert_epp_response :parameter_value_syntax_error end def test_responses_with_error_on_invalid_birthday_date name = 'new' email = 'new@registrar.test' phone = '+1.2' birthday_wrong_format = '1111-22-33' birthday_above_valid_range = '1800-01-01' birthday_below_valid_range = '2050-07-09' request_xml = <<-XML #{name} #{phone} #{email} #{birthday_wrong_format} XML assert_no_difference 'Contact.count' do post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml assert_epp_response :parameter_value_syntax_error request_xml.sub! ">#{birthday_wrong_format}<", ">#{birthday_above_valid_range}<" assert_no_difference 'Contact.count' do post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml assert_epp_response :parameter_value_syntax_error request_xml.sub! ">#{birthday_above_valid_range}<", ">#{birthday_below_valid_range}<" assert_no_difference 'Contact.count' do post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml assert_epp_response :parameter_value_syntax_error end def test_responces_error_with_email_error name = 'new' email = 'new@registrar@test' phone = '+1.2' request_xml = <<-XML #{name} #{phone} #{email} any XML assert_no_difference 'Contact.count' do post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml assert_epp_response :parameter_value_syntax_error end def test_respects_custom_code name = 'new' code = 'custom-id' session = epp_sessions(:api_bestnames) request_xml = <<-XML #{code} #{name} +1.2 any@any.test any XML post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => "session=#{session.session_id}" } response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml contact = Contact.find_by(name: name) assert_equal "#{session.user.registrar.code}:#{code}".upcase, contact.code end def test_fails_when_required_attributes_are_missing request_xml = <<-XML \s +123.4 new@inbox.test test XML assert_no_difference 'Contact.count' do post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml assert_epp_response :required_parameter_missing end def test_does_not_save_address_when_address_processing_turned_off name = 'new' email = 'new@registrar.test' phone = '+1.2' request_xml = <<-XML #{name} 123 Example Tallinn FFF 123456 EE #{phone} #{email} 123 XML assert_difference 'Contact.count' do post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml assert_epp_response :completed_without_address contact = Contact.find_by(name: name) assert_equal name, contact.name assert_equal email, contact.email assert_equal phone, contact.phone assert_not_empty contact.code assert_nil contact.city assert_nil contact.street assert_nil contact.zip assert_nil contact.country_code assert_nil contact.state end def test_saves_address_when_address_processing_turned_on Setting.address_processing = true name = 'new' email = 'new@registrar.test' phone = '+1.2' street = '123 Example' city = 'Tallinn' state = 'Harjumaa' zip = '123456' country_code = 'EE' request_xml = <<-XML #{name} #{street} #{city} #{state} #{zip} #{country_code} #{phone} #{email} 123 XML assert_difference 'Contact.count' do post epp_create_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end response_xml = Nokogiri::XML(response.body) assert_correct_against_schema response_xml assert_epp_response :completed_successfully contact = Contact.find_by(name: name) assert_equal name, contact.name assert_equal email, contact.email assert_equal phone, contact.phone assert_not_empty contact.code assert_equal city, contact.city assert_equal street, contact.street assert_equal zip, contact.zip assert_equal country_code, contact.country_code assert_equal state, contact.state end end