Feature: Contact Merge Action (#378)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Contact Merge Action API', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
let!(:base_contact) { create(:contact, account: account) }
|
||||
let!(:mergee_contact) { create(:contact, account: account) }
|
||||
|
||||
describe 'POST /api/v1/actions/contact_merge' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
post '/api/v1/actions/contact_merge'
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let(:merge_action) { double }
|
||||
|
||||
before do
|
||||
allow(ContactMergeAction).to receive(:new).and_return(merge_action)
|
||||
allow(merge_action).to receive(:perform)
|
||||
end
|
||||
|
||||
it 'merges two contacts by calling contact merge action' do
|
||||
post '/api/v1/actions/contact_merge',
|
||||
params: { base_contact_id: base_contact.id, mergee_contact_id: mergee_contact.id },
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response['id']).to eq(base_contact.id)
|
||||
expected_params = { account: account, base_contact: base_contact, mergee_contact: mergee_contact }
|
||||
expect(ContactMergeAction).to have_received(:new).with(expected_params)
|
||||
expect(merge_action).to have_received(:perform)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -4,7 +4,7 @@ RSpec.describe 'Profile API', type: :request do
|
||||
let(:account) { create(:account) }
|
||||
|
||||
describe 'GET /api/v1/profile' do
|
||||
context 'when unauthenticated user' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
get '/api/v1/profile'
|
||||
|
||||
@@ -12,7 +12,7 @@ RSpec.describe 'Profile API', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it authenticated user' do
|
||||
context 'when it is an authenticated user' do
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
|
||||
it 'returns current user information' do
|
||||
@@ -29,7 +29,7 @@ RSpec.describe 'Profile API', type: :request do
|
||||
end
|
||||
|
||||
describe 'PUT /api/v1/profile' do
|
||||
context 'when unauthenticated user' do
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
put '/api/v1/profile'
|
||||
|
||||
@@ -37,12 +37,13 @@ RSpec.describe 'Profile API', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it authenticated user' do
|
||||
context 'when it is an authenticated user' do
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
|
||||
it 'updates the name & email' do
|
||||
new_email = Faker::Internet.email
|
||||
put '/api/v1/profile',
|
||||
params: { profile: { name: 'test', 'email': 'test@test.com' } },
|
||||
params: { profile: { name: 'test', 'email': new_email } },
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
@@ -51,7 +52,7 @@ RSpec.describe 'Profile API', type: :request do
|
||||
agent.reload
|
||||
expect(json_response['id']).to eq(agent.id)
|
||||
expect(json_response['email']).to eq(agent.email)
|
||||
expect(agent.email).to eq('test@test.com')
|
||||
expect(agent.email).to eq(new_email)
|
||||
end
|
||||
|
||||
it 'updates the password' do
|
||||
@@ -68,7 +69,7 @@ RSpec.describe 'Profile API', type: :request do
|
||||
expect(agent.avatar.attached?).to eq(false)
|
||||
file = fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png')
|
||||
put '/api/v1/profile',
|
||||
params: { profile: { name: 'test', 'email': 'test@test.com', avatar: file } },
|
||||
params: { profile: { avatar: file } },
|
||||
headers: agent.create_new_auth_token
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
Reference in New Issue
Block a user