SHARE
TWEET

Untitled

a guest Apr 27th, 2018 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # frozen_string_literal: true
  2.  
  3. require 'rails_helper'
  4.  
  5. describe Endpoints::Users do
  6.   describe 'namespace User' do
  7.     describe '/CHANGE PASSWORD' do
  8.       let(:admin) { Fabricate(:user, role: :admin) }
  9.       let(:manager) { Fabricate(:user, is_manager: true) }
  10.       let(:user) { Fabricate(:user) }
  11.       let(:api_url) { '/api/users/change_password' }
  12.       let(:request_success) { double('result', success?: true) }
  13.       let(:request_failure) { double('result', success?: false) }
  14.  
  15.       it 'should change password if admin' do
  16.         allow_any_instance_of(
  17.           ActiveDirectoryService::Service
  18.         ).to receive(
  19.           :change_ldap_password
  20.         ).and_return(request_success)
  21.  
  22.         header_auth_to(admin)
  23.         post api_url, params: { user: { old_password: '123123123',
  24.                                         new_password: '321321321' } }
  25.         expect_success(response)
  26.         expect_status(201)
  27.       end
  28.  
  29.       it 'should not change password if user not admin' do
  30.         header_auth_to(manager)
  31.         post api_url, params: { user: { old_password: '123123123',
  32.                                         new_password: '321321321' } }
  33.         expect_status(403)
  34.         expect(response.body).to include('forbidden')
  35.  
  36.         header_auth_to(user)
  37.         post api_url, params: { user: { old_password: '123123123',
  38.                                         new_password: '321321321' } }
  39.         expect_status(403)
  40.         expect(response.body).to include('forbidden')
  41.       end
  42.  
  43.       it 'should raise error if request failure' do
  44.         allow_any_instance_of(
  45.           ActiveDirectoryService::Service
  46.         ).to receive(
  47.           :change_ldap_password
  48.         ).and_return(request_failure)
  49.  
  50.         header_auth_to(admin)
  51.         post api_url, params: { user: { old_password: '123123123',
  52.                                         new_password: '321321321' } }
  53.         expect(response).not_to be_successful
  54.         expect_status(422)
  55.       end
  56.     end
  57.   end
  58. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top