diff --git a/app/helpers/epp/contacts_helper.rb b/app/helpers/epp/contacts_helper.rb index ee2afcad4..29e211c87 100644 --- a/app/helpers/epp/contacts_helper.rb +++ b/app/helpers/epp/contacts_helper.rb @@ -13,10 +13,10 @@ module Epp::ContactsHelper #TODO add support for rem and add code = params_hash['epp']['command']['update']['update'][:id] @contact = Contact.where(code: code).first - stamp @contact - if @contact.update_attributes(contact_and_address_attributes.delete_if { |k, v| v.nil? }) + if stamp(@contact) && @contact.update_attributes(contact_and_address_attributes.delete_if { |k, v| v.nil? }) render 'epp/contacts/update' else + epp_errors << { code: '2303', msg: t('errors.messages.epp_obj_does_not_exist'), value: { obj: 'id', val: code } } if @contact == [] handle_errors(@contact) end end diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index e6e9f367c..9cf0fe448 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -68,7 +68,8 @@ describe 'EPP Contact', epp: true do context 'update command' do it "fails if request is invalid" do - response = epp_request('contacts/update_missing_attr.xml') + #response = epp_request('contacts/update_missing_attr.xml') + response = epp_request(contact_update_xml( {id: false} ), :xml) expect(response[:results][0][:result_code]).to eq('2003') expect(response[:results][0][:msg]).to eq('Required parameter missing: id') @@ -80,22 +81,23 @@ describe 'EPP Contact', epp: true do expect(Contact.first.updated_by_id).to be nil - response = epp_request('contacts/update.xml') - + response = epp_request(contact_update_xml, :xml) + expect(Contact.first.updated_by_id).to eq 1 end it 'is succesful' do Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013') - response = epp_request('contacts/update.xml') + response = epp_request(contact_update_xml( { chg: { email: 'fred@bloggers.ee', postalInfo: { name: 'Fred Bloggers' } } } ), :xml) + expect(response[:msg]).to eq('Command completed successfully') - expect(Contact.first.name).to eq('John Doe') - expect(Contact.first.email).to eq('jdoe@example.com') + expect(Contact.first.name).to eq('Fred Bloggers') + expect(Contact.first.email).to eq('fred@bloggers.ee') end it 'returns phone and email error' do Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013') - response = epp_request('contacts/update_with_errors.xml') + response = epp_request(contact_update_xml( { chg: { email: "qwe", phone: "123qweasd" } }), :xml) expect(response[:results][0][:result_code]).to eq('2005') expect(response[:results][0][:msg]).to eq('Phone nr is invalid') diff --git a/spec/support/epp_contact_xml_builder.rb b/spec/support/epp_contact_xml_builder.rb index 0e8436d68..4fc211ff1 100644 --- a/spec/support/epp_contact_xml_builder.rb +++ b/spec/support/epp_contact_xml_builder.rb @@ -72,6 +72,64 @@ module EppContactXmlBuilder end end + #CONTACT UPDATE NEEDS WORK USE ON YOUR OWN RISK + def contact_update_xml(xml_params={}) + xml = Builder::XmlMarkup.new + + #postalInfo = xml_params.try(:chg).try(:postalInfo) + #addr = postalInfo.try(:addr) + postalInfo = xml_params[:chg][:postalInfo] rescue nil + addr = postalInfo[:addr] rescue nil + + if !addr + addr = { street: 'Downtown', city: 'Stockholm', cc: 'SE' } + end + + if !postalInfo + postalInfo = { name: 'Jane Doe', org: 'Fake Inc.', voice: '+321.12345', fax: '12312312', addr: addr } + end + + xml_params[:chg] = xml_params[:chg] || { postalInfo: postalInfo } + + xml_params[:chg][:postalInfo] = postalInfo + xml_params[:chg][:postalInfo][:addr] = addr + + + xml.instruct!(:xml, standalone: 'no') + xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do + xml.command do + xml.update do + xml.tag!('contact:update', 'xmlns:contact' => 'urn:ietf:params:xml:ns:contact-1.0') do + xml.tag!('contact:id', (xml_params[:id] || 'sh8013') ) unless xml_params[:id] == false + unless xml_params[:chg] == [ false ] + xml.tag!('contact:chg') do + xml.tag!('contact:voice', xml_params[:chg][:phone] || '+123.321123' ) unless xml_params[:chg][:phone] == false + xml.tag!('contact:email', xml_params[:chg][:email] || 'jane@doe.com' ) unless xml_params[:chg][:email] == false + unless xml_params[:chg][:postalInfo] == false + xml.tag!('contact:postalInfo') do + xml.tag!('contact:name', xml_params[:chg][:postalInfo][:name] ) unless xml_params[:chg][:postalInfo][:name] == false + xml.tag!('contact:org', xml_params[:chg][:postalInfo][:org] ) unless xml_params[:chg][:postalInfo][:org] == false + unless xml_params[:chg][:postalInfo][:addr] == false + xml.tag!('contact:addr') do + xml.tag!('contact:street', xml_params[:chg][:postalInfo][:addr][:street] ) unless xml_params[:chg][:postalInfo][:addr][:street] == false + xml.tag!('contact:street', xml_params[:chg][:postalInfo][:addr][:street2] ) unless xml_params[:chg][:postalInfo][:addr][:street2] == false + xml.tag!('contact:street', xml_params[:chg][:postalInfo][:addr][:street3] ) unless xml_params[:chg][:postalInfo][:addr][:street3] == false + xml.tag!('contact:city' , xml_params[:chg][:postalInfo][:addr][:city] ) unless xml_params[:chg][:postalInfo][:addr][:city] == false + xml.tag!('contact:sp' , xml_params[:chg][:postalInfo][:addr][:sp] ) unless xml_params[:chg][:postalInfo][:addr][:sp] == false + xml.tag!('contact:pc' , xml_params[:chg][:postalInfo][:addr][:pc] ) unless xml_params[:chg][:postalInfo][:addr][:pc] == false + xml.tag!('contact:cc' , xml_params[:chg][:postalInfo][:addr][:cc] ) unless xml_params[:chg][:postalInfo][:addr][:cc] == false + end + end + end + end + end + end + end + end + xml.clTRID 'ABC-12345' + end + end + end end RSpec.configure do |c|