require 'rails_helper' RSpec.describe 'EPP contact:create' do let(:request) { post '/epp/command/create', frame: request_xml } before do Setting.address_processing = false sign_in_to_epp_area end context 'when all ident params are valid' do let(:ident) { Contact.first.identifier } let(:request_xml) { <<-XML test +1.2 test@test.com test XML } it 'creates a contact' do expect { request }.to change { Contact.count }.from(0).to(1) end it 'saves ident type' do request expect(ident.type).to eq('priv') end it 'saves ident country code' do request expect(ident.country_code).to eq('US') end specify do request expect(epp_response).to have_result(:success) end end context 'when code is blank' do let(:request_xml) { <<-XML test +1.2 test@test.com XML } it 'does not create a contact' do expect { request }.to_not change { Contact.count } end specify do request expect(epp_response).to have_result(:required_param_missing, 'Required parameter missing: extension > extdata > ident [ident]') end end context 'when code is invalid' do let(:request_xml) { <<-XML test +1.2 test@test.com invalid XML } it 'does not create a contact' do expect { request }.to_not change { Contact.count } end specify do request message = 'Ident code does not conform to national identification number format of Estonia' expect(epp_response).to have_result(:param_syntax_error, message) end end context 'when country code is absent' do let(:request_xml) { <<-XML test +1.2 test@test.com test XML } it 'does not create a contact' do expect { request }.to_not change { Contact.count } end specify do request expect(epp_response).to have_result(:required_param_missing, 'Required ident attribute missing: cc') end end context 'when country code is blank' do let(:request_xml) { <<-XML test +1.2 test@test.com test XML } it 'does not create a contact' do expect { request }.to_not change { Contact.count } end specify do request expect(epp_response).to have_result(:syntax_error) end end context 'when mismatches' do let(:request_xml) { <<-XML test +1.2 test@test.com test XML } before do mismatches = [ Contact::Ident::Mismatch.new('priv', Country.new('DE')), ] allow(Contact::Ident).to receive(:mismatches).and_return(mismatches) end it 'does not create a contact' do expect { request }.to_not change { Contact.count } end specify do request expect(epp_response).to have_result(:param_syntax_error, 'Ident type "priv" is invalid for Germany') end end end