feat: Bulk add team members in Team APIs (#1695)

This commit is contained in:
Sojan Jose
2021-01-29 12:34:52 +05:30
committed by GitHub
parent bf7915c8a3
commit f9c3b7f2f1
8 changed files with 58 additions and 18 deletions

View File

@@ -52,8 +52,9 @@ RSpec.describe 'Team Members API', type: :request do
expect(response).to have_http_status(:unauthorized)
end
it 'add a new team member when its administrator' do
params = { user_id: agent.id }
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 }
post "/api/v1/accounts/#{account.id}/teams/#{team.id}/team_members",
params: params,
@@ -62,7 +63,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['id']).to eq(agent.id)
expect(json_response.count).to eq(user_ids.count)
end
end
end
@@ -90,9 +91,10 @@ RSpec.describe 'Team Members API', type: :request do
expect(response).to have_http_status(:unauthorized)
end
it 'destroys the team member when its administrator' do
params = { user_id: agent.id }
create(:team_member, team: team, user: agent)
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 }
delete "/api/v1/accounts/#{account.id}/teams/#{team.id}",
params: params,
headers: administrator.create_new_auth_token,

View File

@@ -75,7 +75,7 @@ RSpec.describe 'Teams API', type: :request do
end
it 'creates a new team when its administrator' do
params = { name: 'Test Team' }
params = { name: 'test-team' }
post "/api/v1/accounts/#{account.id}/teams",
params: params,
@@ -102,7 +102,7 @@ RSpec.describe 'Teams API', type: :request do
let(:administrator) { create(:user, account: account, role: :administrator) }
it 'returns unauthorized for agent' do
params = { name: 'New Team' }
params = { name: 'new-team' }
put "/api/v1/accounts/#{account.id}/teams/#{team.id}",
params: params,
@@ -113,7 +113,7 @@ RSpec.describe 'Teams API', type: :request do
end
it 'updates an existing team when its an administrator' do
params = { name: 'New Team' }
params = { name: 'new-team' }
put "/api/v1/accounts/#{account.id}/teams/#{team.id}",
params: params,
@@ -121,7 +121,7 @@ RSpec.describe 'Teams API', type: :request do
as: :json
expect(response).to have_http_status(:success)
expect(team.reload.name).to eq('New Team')
expect(team.reload.name).to eq('new-team')
end
end
end