diff --git a/spec/requests/domain_spec.rb b/spec/requests/domain_spec.rb deleted file mode 100644 index 44afef5cf..000000000 --- a/spec/requests/domain_spec.rb +++ /dev/null @@ -1,3 +0,0 @@ -describe Repp::API do - -end diff --git a/spec/requests/domain_v1_spec.rb b/spec/requests/domain_v1_spec.rb new file mode 100644 index 000000000..898132823 --- /dev/null +++ b/spec/requests/domain_v1_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +describe Repp::DomainV1 do + let(:epp_user) { Fabricate(:epp_user) } + + before(:each) { create_settings } + + describe 'GET /repp/v1/domains' do + it 'returns domains of the current registrar' do + Fabricate.times(2, :domain, registrar: epp_user.registrar) + + get_with_auth '/repp/v1/domains', {}, epp_user + expect(response.status).to eq(200) + + body = JSON.parse(response.body) + expect(body['total_pages']).to eq(1) + + # TODO: Maybe there is a way not to convert from and to json again + expect(body['domains'].to_json).to eq(epp_user.registrar.domains.to_json) + end + end +end diff --git a/spec/support/request.rb b/spec/support/request.rb new file mode 100644 index 000000000..053874f0b --- /dev/null +++ b/spec/support/request.rb @@ -0,0 +1,36 @@ +module Request + def get_with_auth(path, params, epp_user) + get path, params, env_with_auth(epp_user) + end + + def delete_with_auth(path, epp_user) + delete path, params, env_with_auth(epp_user) + end + + def post_with_auth(path, params, epp_user) + post path, params, env_with_auth(epp_user) + end + + def patch_with_auth(path, params, epp_user) + patch path, params, env_with_auth(epp_user) + end + + def env + { + 'Accept' => 'application/json', + 'Content-Type' => 'application/json' + } + end + + def env_with_auth(epp_user) + env.merge({ + 'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials( + epp_user.username, epp_user.password + ) + }) + end +end + +RSpec.configure do |c| + c.include Request, type: :request +end