diff --git a/spec/requests/epp/contact/delete/used_spec.rb b/spec/requests/epp/contact/delete/used_spec.rb
deleted file mode 100644
index a4788c381..000000000
--- a/spec/requests/epp/contact/delete/used_spec.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require 'rails_helper'
-
-RSpec.describe 'EPP contact:delete' do
- let(:session_id) { create(:epp_session, user: user).session_id }
- let(:user) { create(:api_user, registrar: registrar) }
- let(:registrar) { create(:registrar) }
- let!(:registrant) { create(:registrant, registrar: registrar, code: 'TEST') }
- let(:request) { post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => "session=#{session_id}" }
- let(:request_xml) { <<-XML
-
-
-
-
-
- test
-
-
-
-
- XML
- }
-
- before do
- sign_in user
- end
-
- context 'when contact is used' do
- let!(:domain) { create(:domain, registrant: registrant) }
-
- specify do
- request
- expect(response).to have_code_of(2305)
- end
-
- it 'does not delete contact' do
- expect { request }.to_not change { Contact.count }
- end
- end
-
- context 'when contact is not used' do
- specify do
- request
- expect(response).to have_code_of(1000)
- end
-
- it 'deletes contact' do
- expect { request }.to change { Contact.count }.from(1).to(0)
- end
- end
-end
diff --git a/test/fixtures/contacts.yml b/test/fixtures/contacts.yml
index 36d0a4ec5..15b82148f 100644
--- a/test/fixtures/contacts.yml
+++ b/test/fixtures/contacts.yml
@@ -8,6 +8,9 @@ john:
registrar: bestnames
code: john-001
auth_info: cacb5b
+ statuses:
+ - ok
+ - linked
uuid: eb2f2766-b44c-4e14-9f16-32ab1a7cb957
created_at: <%= Time.zone.parse('2010-07-05') %>
updated_at: <%= Time.zone.parse('2010-07-06') %>
@@ -79,7 +82,7 @@ not_in_use:
name: Useless
email: useless@inbox.test
registrar: bestnames
- code: useless-001
+ code: not-in-use
auth_info: e75a2a
uuid: ca613cc5-a8dc-48c1-8d32-d3c6a0b6c952
diff --git a/test/integration/epp/contact/check/base_test.rb b/test/integration/epp/contact/check/base_test.rb
new file mode 100644
index 000000000..0035f0db5
--- /dev/null
+++ b/test/integration/epp/contact/check/base_test.rb
@@ -0,0 +1,103 @@
+require 'test_helper'
+
+class EppContactCheckBaseTest < ActionDispatch::IntegrationTest
+ setup do
+ @contact = contacts(:john)
+ end
+
+ def test_returns_valid_response
+ assert_equal 'john-001', @contact.code
+
+ request_xml = <<-XML
+
+
+
+
+
+ john-001
+
+
+
+
+ XML
+
+ post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
+
+ response_xml = Nokogiri::XML(response.body)
+ assert_equal '1000', response_xml.at_css('result')[:code]
+ assert_equal 1, response_xml.css('result').size
+ assert_equal 'john-001', response_xml.at_xpath('//contact:id', contact: xml_schema).text
+ end
+
+ def test_contact_is_available
+ request_xml = <<-XML
+
+
+
+
+
+ non-existing-id
+
+
+
+
+ XML
+
+ post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
+
+ response_xml = Nokogiri::XML(response.body)
+ assert_equal '1', response_xml.at_xpath('//contact:id', contact: xml_schema)['avail']
+ assert_nil response_xml.at_xpath('//contact:reason', contact: xml_schema)
+ end
+
+ def test_contact_is_unavailable
+ assert_equal 'john-001', @contact.code
+
+ request_xml = <<-XML
+
+
+
+
+
+ john-001
+
+
+
+
+ XML
+
+ post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
+
+ response_xml = Nokogiri::XML(response.body)
+ assert_equal '0', response_xml.at_xpath('//contact:id', contact: xml_schema)['avail']
+ assert_equal 'in use', response_xml.at_xpath('//contact:reason', contact: xml_schema).text
+ end
+
+ def test_multiple_contacts
+ request_xml = <<-XML
+
+
+
+
+
+ one.test
+ two.test
+ three.test
+
+
+
+
+ XML
+
+ post '/epp/command/check', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
+
+ response_xml = Nokogiri::XML(response.body)
+ assert_equal 3, response_xml.xpath('//contact:cd', contact: xml_schema).size
+ end
+
+ private
+
+ def xml_schema
+ 'https://epp.tld.ee/schema/contact-ee-1.1.xsd'
+ end
+end
\ No newline at end of file
diff --git a/test/integration/epp/contact/create/base_test.rb b/test/integration/epp/contact/create/base_test.rb
new file mode 100644
index 000000000..ce8cad680
--- /dev/null
+++ b/test/integration/epp/contact/create/base_test.rb
@@ -0,0 +1,40 @@
+require 'test_helper'
+
+class EppContactCreateBaseTest < ActionDispatch::IntegrationTest
+ def test_creates_new_contact_with_minimum_required_parameters
+ request_xml = <<-XML
+
+
+
+
+
+
+ New
+
+ +123.4
+ new@inbox.test
+
+
+
+
+ test
+
+
+
+
+ XML
+
+ assert_difference 'Contact.count' do
+ post '/epp/command/create', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
+ end
+
+ response_xml = Nokogiri::XML(response.body)
+ assert_equal '1000', response_xml.at_css('result')[:code]
+
+ contact = Contact.last
+ assert_not_empty contact.code
+ assert_equal 'New', contact.name
+ assert_equal 'new@inbox.test', contact.email
+ assert_equal '+123.4', contact.phone
+ end
+end
\ No newline at end of file
diff --git a/test/integration/epp/contact/delete/base_test.rb b/test/integration/epp/contact/delete/base_test.rb
new file mode 100644
index 000000000..9d7b4b861
--- /dev/null
+++ b/test/integration/epp/contact/delete/base_test.rb
@@ -0,0 +1,60 @@
+require 'test_helper'
+
+class EppContactDeleteBaseTest < ActionDispatch::IntegrationTest
+ def setup
+ @contact = contacts(:john)
+ end
+
+ def test_deletes_a_contact_that_is_not_in_use
+ @contact = contacts(:not_in_use)
+
+ # https://github.com/internetee/registry/issues/415
+ @contact.update_columns(code: @contact.code.upcase)
+
+ request_xml = <<-XML
+
+
+
+
+
+ not-in-use
+
+
+
+
+ XML
+
+ assert_difference 'Contact.count', -1 do
+ post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
+ end
+ response_xml = Nokogiri::XML(response.body)
+ assert_equal '1000', response_xml.at_css('result')[:code]
+ assert_equal 1, response_xml.css('result').size
+ end
+
+ def test_contact_that_is_in_use_cannot_be_deleted
+ assert_equal 'john-001', @contact.code
+
+ # https://github.com/internetee/registry/issues/415
+ @contact.update_columns(code: @contact.code.upcase)
+
+ request_xml = <<-XML
+
+
+
+
+
+ john-001
+
+
+
+
+ XML
+
+ assert_no_difference 'Contact.count' do
+ post '/epp/command/delete', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
+ end
+ response_xml = Nokogiri::XML(response.body)
+ assert_equal '2305', response_xml.at_css('result')[:code]
+ end
+end
\ No newline at end of file
diff --git a/test/integration/epp/contact/info/base_test.rb b/test/integration/epp/contact/info/base_test.rb
new file mode 100644
index 000000000..414c1a1d6
--- /dev/null
+++ b/test/integration/epp/contact/info/base_test.rb
@@ -0,0 +1,74 @@
+require 'test_helper'
+
+class EppContactInfoBaseTest < ActionDispatch::IntegrationTest
+ setup do
+ @contact = contacts(:john)
+ end
+
+ def test_returns_valid_response
+ assert_equal 'john-001', @contact.code
+ assert_equal [Contact::OK, Contact::LINKED], @contact.statuses
+ assert_equal 'john@inbox.test', @contact.email
+ assert_equal '+555.555', @contact.phone
+ assert_equal 'bestnames', @contact.registrar.code
+ assert_equal Time.zone.parse('2010-07-05'), @contact.created_at
+
+ # https://github.com/internetee/registry/issues/415
+ @contact.update_columns(code: @contact.code.upcase)
+
+ request_xml = <<-XML
+
+
+
+
+
+ john-001
+
+
+
+
+ XML
+
+ post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
+
+ response_xml = Nokogiri::XML(response.body)
+ assert_equal '1000', response_xml.at_css('result')[:code]
+ assert_equal 1, response_xml.css('result').size
+ assert_equal 'JOHN-001', response_xml.at_xpath('//contact:id', contact: xml_schema).text
+ assert_equal 'ok', response_xml.at_xpath('//contact:status', contact: xml_schema)['s']
+ assert_equal 'john@inbox.test', response_xml.at_xpath('//contact:email', contact: xml_schema)
+ .text
+ assert_equal '+555.555', response_xml.at_xpath('//contact:voice', contact: xml_schema).text
+ assert_equal 'bestnames', response_xml.at_xpath('//contact:clID', contact: xml_schema).text
+ assert_equal '2010-07-05T00:00:00+03:00', response_xml.at_xpath('//contact:crDate',
+ contact: xml_schema).text
+ end
+
+ def test_contact_not_found
+ assert_nil Contact.find_by(code: 'non-existing')
+
+ request_xml = <<-XML
+
+
+
+
+
+ non-existing
+
+
+
+
+ XML
+
+ post '/epp/command/info', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
+
+ response_xml = Nokogiri::XML(response.body)
+ assert_equal '2303', response_xml.at_css('result')[:code]
+ end
+
+ private
+
+ def xml_schema
+ 'https://epp.tld.ee/schema/contact-ee-1.1.xsd'
+ end
+end
\ No newline at end of file
diff --git a/test/integration/epp/contact/update/base_test.rb b/test/integration/epp/contact/update/base_test.rb
new file mode 100644
index 000000000..c3ac3d2b0
--- /dev/null
+++ b/test/integration/epp/contact/update/base_test.rb
@@ -0,0 +1,74 @@
+require 'test_helper'
+
+class EppContactUpdateBaseTest < ActionDispatch::IntegrationTest
+ setup do
+ @contact = contacts(:john)
+ end
+
+ def test_updates_contact
+ assert_equal 'john-001', @contact.code
+ assert_not_equal 'new name', @contact.name
+ assert_not_equal 'new-email@inbox.test', @contact.email
+ assert_not_equal '+123.4', @contact.phone
+
+ # https://github.com/internetee/registry/issues/415
+ @contact.update_columns(code: @contact.code.upcase)
+
+ request_xml = <<-XML
+
+
+
+
+
+ john-001
+
+
+ new name
+
+ +123.4
+ new-email@inbox.test
+
+
+
+
+
+ XML
+
+ post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
+ @contact.reload
+
+ response_xml = Nokogiri::XML(response.body)
+ assert_equal '1000', response_xml.at_css('result')[:code]
+ assert_equal 1, response_xml.css('result').size
+ assert_equal 'new name', @contact.name
+ assert_equal 'new-email@inbox.test', @contact.email
+ assert_equal '+123.4', @contact.phone
+ end
+
+ def test_non_existing_contact
+ assert_nil Contact.find_by(code: 'non-existing')
+
+ request_xml = <<-XML
+
+
+
+
+
+ non-existing
+
+
+ any
+
+
+
+
+
+
+ XML
+
+ post '/epp/command/update', { frame: request_xml }, 'HTTP_COOKIE' => 'session=api_bestnames'
+
+ response_xml = Nokogiri::XML(response.body)
+ assert_equal '2303', response_xml.at_css('result')[:code]
+ end
+end
\ No newline at end of file