2021-11-18 22:05:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
RSpec.describe CustomerRelations::Contacts::CreateService, feature_category: :service_desk do
|
2021-11-18 22:05:49 +05:30
|
|
|
describe '#execute' do
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:not_found_or_does_not_belong) { 'The specified organization was not found or does not belong to this group' }
|
|
|
|
|
|
|
|
let(:params) { attributes_for(:contact, group: group) }
|
|
|
|
|
|
|
|
subject(:response) { described_class.new(group: group, current_user: user, params: params).execute }
|
|
|
|
|
|
|
|
context 'when user does not have permission' do
|
2022-03-02 08:16:31 +05:30
|
|
|
let_it_be(:group) { create(:group, :crm_enabled) }
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
before_all do
|
|
|
|
group.add_reporter(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an error' do
|
|
|
|
expect(response).to be_error
|
2022-07-16 23:28:13 +05:30
|
|
|
expect(response.message).to match_array(['You have insufficient permissions to manage contacts for this group'])
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has permission' do
|
2022-03-02 08:16:31 +05:30
|
|
|
let_it_be(:group) { create(:group, :crm_enabled) }
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
before_all do
|
|
|
|
group.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a contact' do
|
|
|
|
expect(response).to be_success
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an error when the contact is not persisted' do
|
|
|
|
params[:last_name] = nil
|
|
|
|
|
|
|
|
expect(response).to be_error
|
|
|
|
expect(response.message).to match_array(["Last name can't be blank"])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an error when the organization_id is invalid' do
|
|
|
|
params[:organization_id] = non_existing_record_id
|
|
|
|
|
|
|
|
expect(response).to be_error
|
|
|
|
expect(response.message).to match_array([not_found_or_does_not_belong])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an error when the organization belongs to a different group' do
|
2023-07-09 08:55:56 +05:30
|
|
|
crm_organization = create(:crm_organization)
|
|
|
|
params[:organization_id] = crm_organization.id
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
expect(response).to be_error
|
|
|
|
expect(response.message).to match_array([not_found_or_does_not_belong])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|