scinote-web/spec/controllers/client_api/users/invitations_controller_spec.rb

41 lines
1.6 KiB
Ruby
Raw Normal View History

2017-09-28 20:49:33 +08:00
require 'rails_helper'
describe ClientApi::Users::InvitationsController, type: :controller do
login_user
let(:user_one) { User.first }
let(:team_one) { create :team }
let(:emails_one) { Array.new(3) { Faker::Internet.email } }
describe '#invite_users' do
it 'returns HTTP success if users were invited' do
post :invite_users, params: { user_role: 'normal_user',
emails: emails_one },
format: :json
expect(response).to be_success
expect(response).to have_http_status(:ok)
expect(response).to render_template('client_api/users/invite_users')
end
it 'returns HTTP success if users were invited to team' do
create :user_team, team: team_one, user: user_one
post :invite_users, params: { team_id: team_one.id,
user_role: 'normal_user',
emails: emails_one },
format: :json
expect(response).to be_success
expect(response).to have_http_status(:ok)
expect(response).to render_template('client_api/users/invite_users')
end
it 'returns HTTP unprocessable_entity if users can\'t be invited to team' do
post :invite_users, params: { team_id: team_one.id,
user_role: 'normal_user',
emails: emails_one },
format: :json
expect(response).to_not be_success
expect(response).to have_http_status(:unprocessable_entity)
expect(response.content_type).to eq 'application/json'
end
end
end