enhancement: Current password confirmation in change password (#2108)

* add current password field in change password form

* locale changes

* chore: update password API

* chore: rubocop fixes

* replace currentPassword with current_password

* code cleanup

* replace input with woot-input

* code cleanup

Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
Muhsin Keloth
2021-06-02 17:52:24 +05:30
committed by GitHub
parent 2c42e70637
commit b0b4d9d6f5
6 changed files with 201 additions and 84 deletions

View File

@@ -39,7 +39,7 @@ RSpec.describe 'Profile API', type: :request do
end
context 'when it is an authenticated user' do
let(:agent) { create(:user, account: account, role: :agent) }
let(:agent) { create(:user, password: 'Test123!', account: account, role: :agent) }
it 'updates the name & email' do
new_email = Faker::Internet.email
@@ -56,13 +56,23 @@ RSpec.describe 'Profile API', type: :request do
expect(agent.email).to eq(new_email)
end
it 'updates the password' do
it 'updates the password when current password is provided' do
put '/api/v1/profile',
params: { profile: { password: 'test123', password_confirmation: 'test123' } },
params: { profile: { current_password: 'Test123!', password: 'test123', password_confirmation: 'test123' } },
headers: agent.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
expect(agent.reload.valid_password?('test123')).to eq true
end
it 'throws error when current password provided is invalid' do
put '/api/v1/profile',
params: { profile: { current_password: 'Test', password: 'test123', password_confirmation: 'test123' } },
headers: agent.create_new_auth_token,
as: :json
expect(response).to have_http_status(:unprocessable_entity)
end
it 'updates avatar' do