2017-08-29 17:56:46 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ClientApi::Users::UserTeamsController, type: :controller do
|
2017-09-18 21:36:33 +08:00
|
|
|
login_user
|
|
|
|
let(:user_one) { User.first }
|
|
|
|
let(:user_two) { create :user, email: Faker::Internet.email }
|
|
|
|
let(:team) { create :team }
|
|
|
|
let(:user_team) { create :user_team, team: team, user: user_one }
|
|
|
|
|
2017-08-29 17:56:46 +08:00
|
|
|
describe 'DELETE #leave_team' do
|
2017-09-18 21:36:33 +08:00
|
|
|
it 'should return HTTP success if user can leave the team' do
|
|
|
|
create :user_team, team: team, user: user_two
|
|
|
|
delete :leave_team,
|
|
|
|
params: { team: team.id, user_team: user_team.id },
|
|
|
|
format: :json
|
|
|
|
expect(response).to be_success
|
|
|
|
expect(response).to have_http_status(:ok)
|
2017-08-29 17:56:46 +08:00
|
|
|
end
|
|
|
|
|
2017-09-18 21:36:33 +08:00
|
|
|
it 'should return HTTP unprocessable_entity if user can\'t ' \
|
|
|
|
'leave the team' do
|
|
|
|
delete :leave_team,
|
|
|
|
params: { team: team.id, user_team: user_team.id },
|
|
|
|
format: :json
|
|
|
|
expect(response).to_not be_success
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should return HTTP unprocessable_entity if no params given' do
|
|
|
|
delete :leave_team, format: :json
|
|
|
|
expect(response).to_not be_success
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #update_role' do
|
|
|
|
it 'should return HTTP success if user can leave the team' do
|
2017-12-14 17:52:13 +08:00
|
|
|
create :user_team, team: team, user: user_two, role: 2
|
2017-09-18 21:36:33 +08:00
|
|
|
post :update_role,
|
|
|
|
params: { team: team.id,
|
2017-12-14 17:52:13 +08:00
|
|
|
user_team: user_team.id,
|
2017-09-18 21:36:33 +08:00
|
|
|
role: 'normal_user' },
|
|
|
|
format: :json
|
2017-08-29 17:56:46 +08:00
|
|
|
expect(response).to be_success
|
2017-09-18 21:36:33 +08:00
|
|
|
expect(response).to have_http_status(:ok)
|
2017-08-29 17:56:46 +08:00
|
|
|
end
|
|
|
|
|
2017-09-18 21:36:33 +08:00
|
|
|
it 'should return HTTP unprocessable_entity if user can\'t ' \
|
|
|
|
'leave the team' do
|
|
|
|
post :update_role,
|
|
|
|
params: { team: team.id,
|
|
|
|
user_team: user_team.id,
|
|
|
|
role: 'normal_user' },
|
|
|
|
format: :json
|
2017-08-29 17:56:46 +08:00
|
|
|
expect(response).to_not be_success
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
|
|
end
|
2017-09-18 21:36:33 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE #remove_user' do
|
|
|
|
it 'should return HTTP success if user can be removed' do
|
|
|
|
user_team
|
|
|
|
user_team_two = create :user_team, team: team, user: user_two
|
|
|
|
post :remove_user,
|
|
|
|
params: { team: team.id, user_team: user_team_two.id },
|
|
|
|
format: :json
|
|
|
|
expect(response).to be_success
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
end
|
2017-08-29 17:56:46 +08:00
|
|
|
|
2017-09-18 21:36:33 +08:00
|
|
|
it 'should return HTTP unprocessable_entity if user can\'t ' \
|
|
|
|
'be removed' do
|
|
|
|
post :remove_user,
|
|
|
|
params: { team: team.id,
|
|
|
|
user_team: user_team.id,
|
|
|
|
role: 'normal_user' },
|
|
|
|
format: :json
|
2017-08-29 17:56:46 +08:00
|
|
|
expect(response).to_not be_success
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|