2017-09-05 20:43:35 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-01-31 19:05:45 +08:00
|
|
|
describe ClientApi::Users::UsersController, type: :controller, broken: true do
|
2017-09-05 20:43:35 +08:00
|
|
|
login_user
|
|
|
|
|
|
|
|
before do
|
2017-10-05 21:53:05 +08:00
|
|
|
# user password is set in user factory defaults to 'asdf1243'
|
2017-09-05 20:43:35 +08:00
|
|
|
@user = User.first
|
|
|
|
end
|
|
|
|
|
2017-10-05 16:24:28 +08:00
|
|
|
describe '#sign_out_user' do
|
|
|
|
it 'returns unauthorized response' do
|
|
|
|
sign_out @user
|
|
|
|
get :sign_out_user, format: :json
|
|
|
|
expect(response).to have_http_status(:unauthorized)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds successfully if the user is signed out' do
|
|
|
|
get :sign_out_user, format: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(subject.current_user).to eq(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-05 20:47:05 +08:00
|
|
|
describe 'GET current_user_info' do
|
|
|
|
it 'responds successfully' do
|
2017-09-05 20:43:35 +08:00
|
|
|
get :current_user_info, format: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
describe 'POST update' do
|
|
|
|
let(:new_password) { 'secretPassword' }
|
2017-10-06 15:54:17 +08:00
|
|
|
let(:new_email) { 'banana@fruit.com' }
|
2017-10-05 21:53:05 +08:00
|
|
|
|
|
|
|
it 'responds successfully if all password params are set' do
|
|
|
|
post :update,
|
|
|
|
params: { user: { password: new_password,
|
|
|
|
password_confirmation: new_password,
|
|
|
|
current_password: 'asdf1243' } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
|
|
|
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'responds unsuccessfully if no current_password is provided' do
|
|
|
|
post :update,
|
|
|
|
params: { user: { password: new_password,
|
|
|
|
password_confirmation: new_password } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
2017-09-05 20:43:35 +08:00
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'responds unsuccessfully if no password_confirmation is provided' do
|
|
|
|
post :update,
|
|
|
|
params: { user: { password: new_password,
|
|
|
|
current_password: 'asdf1243' } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
2017-09-05 20:43:35 +08:00
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'responds successfully if time_zone is updated' do
|
|
|
|
post :update, params: { user: { time_zone: 'Pacific/Fiji' } },
|
|
|
|
format: :json
|
2017-09-05 20:43:35 +08:00
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
2017-10-06 15:54:17 +08:00
|
|
|
it 'responds successfully if email is updated' do
|
|
|
|
post :update, params: { user: { email: new_email,
|
|
|
|
current_password: 'asdf1243' } },
|
|
|
|
format: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
expect(@user.reload.email).to eq(new_email)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds unsuccessfully if email is updated without password' do
|
|
|
|
post :update, params: { user: { email: new_email } },
|
|
|
|
format: :json
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
|
|
expect(@user.reload.email).to_not eq(new_email)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'responds unsuccessfully if email is updated with invalid email' do
|
|
|
|
post :update, params: { user: { email: 'bananafruit.com',
|
|
|
|
current_password: 'asdf1243' } },
|
|
|
|
format: :json
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
|
|
expect(@user.reload.email).to_not eq(new_email)
|
|
|
|
end
|
|
|
|
|
2017-09-05 20:47:05 +08:00
|
|
|
it 'changes timezone' do
|
2017-09-05 20:43:35 +08:00
|
|
|
user = User.first
|
|
|
|
expect(user.time_zone).to eq('UTC')
|
2017-10-05 21:53:05 +08:00
|
|
|
post :update, params: { user: { time_zone: 'Pacific/Fiji' } },
|
|
|
|
format: :json
|
2017-09-05 20:43:35 +08:00
|
|
|
expect(user.reload.time_zone).to eq('Pacific/Fiji')
|
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'responds successfully if initials are provided' do
|
|
|
|
post :update, params: { user: { initials: 'TD' } }, format: :json
|
2017-09-05 20:43:35 +08:00
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'updates user initials' do
|
2017-09-05 20:43:35 +08:00
|
|
|
user = User.first
|
2017-09-05 20:47:05 +08:00
|
|
|
expect(user.initials).not_to eq('TD')
|
2017-10-05 21:53:05 +08:00
|
|
|
post :update, params: { user: { initials: 'TD' } }, format: :json
|
2017-09-05 20:47:05 +08:00
|
|
|
expect(user.reload.initials).to eq('TD')
|
2017-09-05 20:43:35 +08:00
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'responds successfully if system_message_email_notification provided' do
|
|
|
|
post :update,
|
|
|
|
params: { user: { system_message_email_notificationatus: 'false' } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'changes system_message_email_notification from false => true' do
|
2017-09-05 20:43:35 +08:00
|
|
|
user = User.first
|
2017-10-05 21:53:05 +08:00
|
|
|
user.system_message_email_notification = false
|
2017-09-05 20:43:35 +08:00
|
|
|
user.save
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
post :update,
|
|
|
|
params: { user: { system_message_email_notification: true } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
2017-10-05 21:53:05 +08:00
|
|
|
expect(user.reload.system_message_email_notification).to eql('true')
|
2017-09-05 20:43:35 +08:00
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'changes system_message_email_notification from true => false' do
|
2017-09-05 20:43:35 +08:00
|
|
|
user = User.first
|
2017-10-05 21:53:05 +08:00
|
|
|
user.system_message_email_notification = true
|
2017-09-05 20:43:35 +08:00
|
|
|
user.save
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
post :update,
|
|
|
|
params: { user: { system_message_email_notification: false } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
2017-10-05 21:53:05 +08:00
|
|
|
expect(user.reload.system_message_email_notification).to eql('false')
|
2017-09-05 20:43:35 +08:00
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'responds successfully if recent_email_notification provided' do
|
|
|
|
post :update,
|
|
|
|
params: { user: { recent_email_notification: false } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'changes recent_email_notification from false => true' do
|
2017-09-05 20:43:35 +08:00
|
|
|
user = User.first
|
2017-10-05 21:53:05 +08:00
|
|
|
user.recent_email_notification = false
|
2017-09-05 20:43:35 +08:00
|
|
|
user.save
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
post :update,
|
|
|
|
params: { user: { recent_email_notification: true } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
2017-10-05 21:53:05 +08:00
|
|
|
expect(user.reload.recent_email_notification).to eql('true')
|
2017-09-05 20:43:35 +08:00
|
|
|
end
|
|
|
|
|
2017-09-05 20:47:05 +08:00
|
|
|
it 'changes notification from true => false' do
|
2017-09-05 20:43:35 +08:00
|
|
|
user = User.first
|
2017-10-05 21:53:05 +08:00
|
|
|
user.recent_email_notification = true
|
2017-09-05 20:43:35 +08:00
|
|
|
user.save
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
post :update,
|
|
|
|
params: { user: { recent_email_notification: false } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
2017-10-05 21:53:05 +08:00
|
|
|
expect(user.reload.recent_email_notification).to eql('false')
|
2017-09-05 20:43:35 +08:00
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'responds successfully if recent_notification provided' do
|
|
|
|
post :update, params: { user: { recent_notification: false } },
|
|
|
|
format: :json
|
2017-09-05 20:43:35 +08:00
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'changes recent_notification from false => true' do
|
2017-09-05 20:43:35 +08:00
|
|
|
user = User.first
|
|
|
|
user.recent_notification = false
|
|
|
|
user.save
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
post :update, params: { user: { recent_notification: true } },
|
|
|
|
format: :json
|
|
|
|
expect(user.reload.recent_notification).to eql('true')
|
2017-09-05 20:43:35 +08:00
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'changes recent_notification from true => false' do
|
2017-09-05 20:43:35 +08:00
|
|
|
user = User.first
|
|
|
|
user.recent_notification = true
|
|
|
|
user.save
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
post :update, params: { user: { recent_notification: false } },
|
|
|
|
format: :json
|
|
|
|
expect(user.reload.recent_notification).to eq('false')
|
2017-09-05 20:43:35 +08:00
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'responds successfully if assignments_email_notification provided' do
|
|
|
|
post :update,
|
|
|
|
params: { user: { assignments_email_notification: false } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'changes assignments_email_notification from false => true' do
|
2017-09-05 20:43:35 +08:00
|
|
|
user = User.first
|
2017-10-05 21:53:05 +08:00
|
|
|
user.assignments_email_notification = false
|
2017-09-05 20:43:35 +08:00
|
|
|
user.save
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
post :update,
|
|
|
|
params: { user: { assignments_email_notification: true } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
2017-10-05 21:53:05 +08:00
|
|
|
expect(user.reload.assignments_email_notification).to eq('true')
|
2017-09-05 20:43:35 +08:00
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'changes assignments_email_notification from true => false' do
|
2017-09-05 20:43:35 +08:00
|
|
|
user = User.first
|
2017-10-05 21:53:05 +08:00
|
|
|
user.assignments_email_notification = true
|
2017-09-05 20:43:35 +08:00
|
|
|
user.save
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
post :update,
|
|
|
|
params: { user: { assignments_email_notification: false } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
2017-10-05 21:53:05 +08:00
|
|
|
expect(user.reload.assignments_email_notification).to eq('false')
|
2017-09-05 20:43:35 +08:00
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'responds successfully if assignments_notification provided' do
|
|
|
|
post :update,
|
|
|
|
params: { user: { assignments_notification: false } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'changes assignments_notification from false => true' do
|
2017-09-05 20:43:35 +08:00
|
|
|
user = User.first
|
|
|
|
user.assignments_notification = false
|
|
|
|
user.save
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
post :update,
|
|
|
|
params: { user: { assignments_notification: true } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
2017-10-05 21:53:05 +08:00
|
|
|
expect(user.reload.assignments_notification).to eq('true')
|
2017-09-05 20:43:35 +08:00
|
|
|
end
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
it 'changes assignments_notification from true => false' do
|
2017-09-05 20:43:35 +08:00
|
|
|
user = User.first
|
|
|
|
user.assignments_notification = true
|
|
|
|
user.save
|
|
|
|
|
2017-10-05 21:53:05 +08:00
|
|
|
post :update,
|
|
|
|
params: { user: { assignments_notification: false } },
|
2017-09-05 20:43:35 +08:00
|
|
|
format: :json
|
2017-10-05 21:53:05 +08:00
|
|
|
expect(user.reload.assignments_notification).to eq('false')
|
2017-09-05 20:43:35 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|