chore: API improvements (#3637)
- Unique validations for Inbox members and Team member objects - Move notification processing to Async
This commit is contained in:
@@ -81,7 +81,7 @@ RSpec.describe 'Inbox Member API', type: :request do
|
||||
end
|
||||
|
||||
it 'add inbox members' do
|
||||
params = { inbox_id: inbox.id, user_ids: [agent_to_add.id] }
|
||||
params = { inbox_id: inbox.id, user_ids: [old_agent.id, agent_to_add.id] }
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/inbox_members",
|
||||
headers: administrator.create_new_auth_token,
|
||||
|
||||
@@ -55,6 +55,8 @@ RSpec.describe 'Team Members API', type: :request do
|
||||
it 'add a new team members when its administrator' do
|
||||
user_ids = (1..5).map { create(:user, account: account, role: :agent).id }
|
||||
params = { user_ids: user_ids }
|
||||
# have a team member added already
|
||||
create(:team_member, team: team, user: User.find(user_ids.first))
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/teams/#{team.id}/team_members",
|
||||
params: params,
|
||||
@@ -63,7 +65,7 @@ RSpec.describe 'Team Members API', type: :request do
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
json_response = JSON.parse(response.body)
|
||||
expect(json_response.count).to eq(user_ids.count)
|
||||
expect(json_response.count).to eq(user_ids.count - 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -93,15 +95,16 @@ RSpec.describe 'Team Members API', type: :request do
|
||||
|
||||
it 'destroys the team members when its administrator' do
|
||||
user_ids = (1..5).map { create(:user, account: account, role: :agent).id }
|
||||
params = { user_ids: user_ids }
|
||||
user_ids.each { |id| create(:team_member, team: team, user: User.find(id)) }
|
||||
params = { user_ids: user_ids.first(3) }
|
||||
|
||||
delete "/api/v1/accounts/#{account.id}/teams/#{team.id}",
|
||||
delete "/api/v1/accounts/#{account.id}/teams/#{team.id}/team_members",
|
||||
params: params,
|
||||
headers: administrator.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(team.team_members.count).to eq(0)
|
||||
expect(team.team_members.count).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -78,19 +78,9 @@ shared_examples_for 'assignment_handler' do
|
||||
expect(conversation.reload.assignee).to eq(agent)
|
||||
end
|
||||
|
||||
it 'creates a new notification for the agent' do
|
||||
it 'dispaches assignee changed event' do
|
||||
expect(EventDispatcherJob).to(have_been_enqueued.at_least(:once).with('assignee.changed', anything, anything))
|
||||
expect(update_assignee).to eq(true)
|
||||
expect(agent.notifications.count).to eq(1)
|
||||
end
|
||||
|
||||
it 'does not create assignment notification if notification setting is turned off' do
|
||||
notification_setting = agent.notification_settings.first
|
||||
notification_setting.unselect_all_email_flags
|
||||
notification_setting.unselect_all_push_flags
|
||||
notification_setting.save!
|
||||
|
||||
expect(update_assignee).to eq(true)
|
||||
expect(agent.notifications.count).to eq(0)
|
||||
end
|
||||
|
||||
context 'when agent is current user' do
|
||||
|
||||
Reference in New Issue
Block a user