mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
parent
e4ae71b308
commit
1b36e93eba
1 changed files with 48 additions and 0 deletions
48
spec/api/repp/contact_v1_spec.rb
Normal file
48
spec/api/repp/contact_v1_spec.rb
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Repp::ContactV1, db: true do
|
||||||
|
let(:user) { FactoryGirl.create(:api_user, registrar: registrar) }
|
||||||
|
let(:registrar) { FactoryGirl.create(:registrar) }
|
||||||
|
|
||||||
|
describe '/contacts' do
|
||||||
|
subject(:fields) { HashWithIndifferentAccess.new(JSON.parse(response.body)['contacts'].first).keys }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Grape::Endpoint.before_each do |endpoint|
|
||||||
|
allow(endpoint).to receive(:current_user).and_return(user)
|
||||||
|
end
|
||||||
|
|
||||||
|
registrar.contacts << FactoryGirl.create(:contact)
|
||||||
|
|
||||||
|
get '/repp/v1/contacts', { limit: 1, details: true }, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'responds with success' do
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when address processing is enabled' do
|
||||||
|
before do
|
||||||
|
expect(Contact).to receive(:address_processing).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns contact address' do
|
||||||
|
expect(fields).to include(Contact.address_attributes)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when address processing is disabled' do
|
||||||
|
before do
|
||||||
|
expect(Contact).to receive(:address_processing).and_return(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not return contact address' do
|
||||||
|
expect(fields).to_not include(Contact.address_attributes)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def http_auth_key
|
||||||
|
ActionController::HttpAuthentication::Basic.encode_credentials(user.username, user.password)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue