require "spec_helper" module CFoundry module V2 describe User do let(:client) { build(:client) } subject { build(:user, client: client) } describe '#delete!' do describe 'when cloud controller was able to delete the user' do before do stub_request(:delete, /v2\/users\/.*/).to_return(:status => 200, :body => "", :headers => {}) allow(client.base).to receive(:info).and_return({:authorization_endpoint => 'some_endpoint'}) end it "also removes the user from uaa" do expect_any_instance_of(CFoundry::UAAClient).to receive(:delete_user) expect(subject.delete!).to be_truthy end end describe "when cloud controller was unable to delete the user" do before do allow(client.base).to receive(:delete).and_raise(CFoundry::APIError) end it "allows the exception to bubble up" do expect{ subject.delete! }.to raise_error(CFoundry::APIError) end end end describe '#get_meta_from_uaa' do let(:api_target) { 'http://api.example.com' } let(:login_target) { 'https://login.example.com' } let(:uaa_target) { 'https://uaa.example.com' } let(:user_email) { 'test-user@example.com' } let(:given_name) { 'John' } let(:family_name) { 'Doe' } before do stub_request(:get, "#{api_target}/info").to_return :status => 200, :headers => {'Content-Type' => 'application/json'}, :body => < 200, :headers => {'Content-Type' => 'application/json'}, :body => < 200, :headers => {'Content-Type' => 'application/json'}, :body => < 200, :headers => {'Content-Type' => 'application/json'}, :body => <