<commit_before>require 'spec_helper'

module Cb
  describe Cb::Clients::User do

    describe '#check_existing' do
      let(:body) do
        { ResponseUserCheck: { Request: { Email: '<EMAIL>' }, Status: 'Success', UserCheckStatus: 'EmailExistsPasswordsDoNotMatch', ResponseExternalID: 'abc123', ResponseOAuthToken: '<PASSWORD>', ResponsePartnerID: 'zyx654' } }
      end

      let(:response) do
        Clients::User.check_existing '<EMAIL>', '1337'
      end

      before do
        stub_request(:post, uri_stem(Cb.configuration.uri_user_check_existing)).to_return(body: body.to_json)
      end

      context 'by interacting with the API client directly' do
        it 'returns a CheckExisting response' do
          response.should be_a Responses::User::CheckExisting
        end
      end

      context 'When external id comes back' do
        it 'external_id should not be nil' do
          response.model.external_id.should_not be_nil
          response.model.external_id == 'abc123'
        end
      end

      context 'When oauth token comes back' do
        it 'oauth_token should not be nil' do
          response.model.oauth_token.should_not be_nil
          response.model.oauth_token == '<PASSWORD>'
        end
      end

      context 'When partner id comes back' do
        it 'partner_id should not be nil' do
          response.model.partner_id.should_not be_nil
          response.model.partner_id == 'zyx654'
        end
      end

      context 'When user check status comes back' do
        it 'status should not be nil' do
          response.model.status.should == 'EmailExistsPasswordsDoNotMatch'
        end
      end

      context 'When email comes back' do
        it 'email should not be nil' do
          response.model.email.should == '<EMAIL>'
        end
      end

    end

    context '.retrieve' do
      before :each do
        stub_request(:post, uri_stem(Cb.configuration.uri_user_retrieve)).
            with(:body => anything).
            to_return(:body => { ResponseUserInfo: { Errors: nil, Status: 'Success (Test)', UserInfo: Hash.new } }.to_json)
      end

      it 'should retrieve a user' do
        user = Cb.user.retrieve 'XRHP5HT66R55L6RVP6R9', true
        expect(user.cb_response.errors.nil?).to be true
        expect(user.cb_response.status).to be == 'Success (Test)'
        expect(user.nil?).to be false
        user.api_error.should == false
      end
    end

    context '.change_password' do
      before :each do
        stub_request(:post, uri_stem(Cb.configuration.uri_user_change_password)).
            with(:body => anything).
            to_return(:body => { ResponseUserChangePW: { Status: 'Success (Test)' } }.to_json)
      end

      it 'should change a user password' do
        result = Cb.user.change_password '<PASSWORD>', '<PASSWORD>', '<PASSWORD>', true

        expect(result.cb_response.errors.nil?).to eq true
        expect(result.cb_response.status).to eq 'Success (Test)'
        expect(result).to eq true
        result.api_error.should eq false
      end

    end


    context '.build_change_password_request' do
      it 'should build xml' do
        xml = Cb.user.send :build_change_password_request, 'a', 'b', 'c', true

        xml_wrapper = XmlSimple.xml_in xml, {'KeepRoot' => true}

        expect(xml_wrapper.count).to be == 1 # Assert one root node.
        expect(xml_wrapper.has_key? 'Request').to be true # Assert root node name.

        expect(xml.include?('<ExternalID>a</ExternalID>')).to be true
        expect(xml.include?('<OldPassword>b</OldPassword>')).to be true
        expect(xml.include?('<NewPassword>c</NewPassword>')).to be true
        expect(xml.include?('<Test>true</Test>')).to be true
        expect(xml.include?("<DeveloperKey>#{Cb.configuration.dev_key}</DeveloperKey>")).to be true
      end
    end


    context '.delete' do
      before :each do
        stub_request(:post, uri_stem(Cb.configuration.uri_user_delete)).
            with(:body => anything).
            to_return(:body => { ResponseUserDelete: { Status: 'Success (Test)' } }.to_json)
      end

      it 'should delete a user', :vcr => { :cassette_name => 'user/delete/success' } do
        result = Cb.user.delete 'xid', '<PASSWORD>wort', true

        expect(result.cb_response.errors.nil?).to be true
        expect(result.cb_response.status).to be == 'Success (Test)'
        expect(result).to be true
        result.api_error.should == false
      end
    end

    context '.build_retrieve_request' do
      it 'should build retriev a user' do
        xml = Cb.user.send :build_retrieve_request, 'a', true

        xml_wrapper = XmlSimple.xml_in xml, {'KeepRoot' => true}

        expect(xml_wrapper.count).to be == 1 # Assert one root node.
        expect(xml_wrapper.has_key? 'Request').to be true # Assert root node name.

        expect(xml.include?('<ExternalID>a</ExternalID>')).to be true
        expect(xml.include?('<Test>true</Test>')).to be true
        expect(xml.include?("<DeveloperKey>#{Cb.configuration.dev_key}</DeveloperKey>")).to be true
      end
    end

    context '.build_delete_request' do
      it 'should build delete xml' do
        xml = Cb.user.send :build_delete_request, 'a', 'b', true

        xml_wrapper = XmlSimple.xml_in xml, {'KeepRoot' => true}

        expect(xml_wrapper.count).to be == 1 # Assert one root node.
        expect(xml_wrapper.has_key? 'Request').to be true  # Assert root node name.

        expect(xml.include?('<ExternalID>a</ExternalID>')).to be true
        expect(xml.include?('<Password>b</Password>')).to be true
        expect(xml.include?('<Test>true</Test>')).to be true
        expect(xml.include?("<DeveloperKey>#{Cb.configuration.dev_key}</DeveloperKey>")).to be true
      end
    end

  end
end
<commit_msg>Make sure we are asserting on the values for the #check_existing test cases.<commit_after>require 'spec_helper'

module Cb
  describe Cb::Clients::User do

    describe '#check_existing' do
      let(:body) do
        { ResponseUserCheck: { Request: { Email: '<EMAIL>' }, Status: 'Success', UserCheckStatus: 'EmailExistsPasswordsDoNotMatch', ResponseExternalID: 'abc123', ResponseOAuthToken: '<PASSWORD>', ResponsePartnerID: 'zyx654' } }
      end

      let(:response) do
        Clients::User.check_existing '<EMAIL>', '1337'
      end

      before do
        stub_request(:post, uri_stem(Cb.configuration.uri_user_check_existing)).to_return(body: body.to_json)
      end

      context 'by interacting with the API client directly' do
        it 'returns a CheckExisting response' do
          response.should be_a Responses::User::CheckExisting
        end
      end

      context 'When external id comes back' do
        it 'external_id should not be nil' do
          response.model.external_id.should == 'abc123'
        end
      end

      context 'When oauth token comes back' do
        it 'oauth_token should not be nil' do
          response.model.oauth_token.should == '<PASSWORD>'
        end
      end

      context 'When partner id comes back' do
        it 'partner_id should not be nil' do
          response.model.partner_id.should == 'zyx654'
        end
      end

      context 'When user check status comes back' do
        it 'status should not be nil' do
          response.model.status.should == 'EmailExistsPasswordsDoNotMatch'
        end
      end

      context 'When email comes back' do
        it 'email should not be nil' do
          response.model.email.should == '<EMAIL>'
        end
      end

    end

    context '.retrieve' do
      before :each do
        stub_request(:post, uri_stem(Cb.configuration.uri_user_retrieve)).
            with(:body => anything).
            to_return(:body => { ResponseUserInfo: { Errors: nil, Status: 'Success (Test)', UserInfo: Hash.new } }.to_json)
      end

      it 'should retrieve a user' do
        user = Cb.user.retrieve 'XRHP5HT66R55L6RVP6R9', true
        expect(user.cb_response.errors.nil?).to be true
        expect(user.cb_response.status).to be == 'Success (Test)'
        expect(user.nil?).to be false
        user.api_error.should == false
      end
    end

    context '.change_password' do
      before :each do
        stub_request(:post, uri_stem(Cb.configuration.uri_user_change_password)).
            with(:body => anything).
            to_return(:body => { ResponseUserChangePW: { Status: 'Success (Test)' } }.to_json)
      end

      it 'should change a user password' do
        result = Cb.user.change_password '<PASSWORD>', '<PASSWORD>', '<PASSWORD>', true

        expect(result.cb_response.errors.nil?).to eq true
        expect(result.cb_response.status).to eq 'Success (Test)'
        expect(result).to eq true
        result.api_error.should eq false
      end

    end


    context '.build_change_password_request' do
      it 'should build xml' do
        xml = Cb.user.send :build_change_password_request, 'a', 'b', 'c', true

        xml_wrapper = XmlSimple.xml_in xml, {'KeepRoot' => true}

        expect(xml_wrapper.count).to be == 1 # Assert one root node.
        expect(xml_wrapper.has_key? 'Request').to be true # Assert root node name.

        expect(xml.include?('<ExternalID>a</ExternalID>')).to be true
        expect(xml.include?('<OldPassword>b</OldPassword>')).to be true
        expect(xml.include?('<NewPassword>c</NewPassword>')).to be true
        expect(xml.include?('<Test>true</Test>')).to be true
        expect(xml.include?("<DeveloperKey>#{Cb.configuration.dev_key}</DeveloperKey>")).to be true
      end
    end


    context '.delete' do
      before :each do
        stub_request(:post, uri_stem(Cb.configuration.uri_user_delete)).
            with(:body => anything).
            to_return(:body => { ResponseUserDelete: { Status: 'Success (Test)' } }.to_json)
      end

      it 'should delete a user', :vcr => { :cassette_name => 'user/delete/success' } do
        result = Cb.user.delete 'xid', '<PASSWORD>wort', true

        expect(result.cb_response.errors.nil?).to be true
        expect(result.cb_response.status).to be == 'Success (Test)'
        expect(result).to be true
        result.api_error.should == false
      end
    end

    context '.build_retrieve_request' do
      it 'should build retriev a user' do
        xml = Cb.user.send :build_retrieve_request, 'a', true

        xml_wrapper = XmlSimple.xml_in xml, {'KeepRoot' => true}

        expect(xml_wrapper.count).to be == 1 # Assert one root node.
        expect(xml_wrapper.has_key? 'Request').to be true # Assert root node name.

        expect(xml.include?('<ExternalID>a</ExternalID>')).to be true
        expect(xml.include?('<Test>true</Test>')).to be true
        expect(xml.include?("<DeveloperKey>#{Cb.configuration.dev_key}</DeveloperKey>")).to be true
      end
    end

    context '.build_delete_request' do
      it 'should build delete xml' do
        xml = Cb.user.send :build_delete_request, 'a', 'b', true

        xml_wrapper = XmlSimple.xml_in xml, {'KeepRoot' => true}

        expect(xml_wrapper.count).to be == 1 # Assert one root node.
        expect(xml_wrapper.has_key? 'Request').to be true  # Assert root node name.

        expect(xml.include?('<ExternalID>a</ExternalID>')).to be true
        expect(xml.include?('<Password>b</Password>')).to be true
        expect(xml.include?('<Test>true</Test>')).to be true
        expect(xml.include?("<DeveloperKey>#{Cb.configuration.dev_key}</DeveloperKey>")).to be true
      end
    end

  end
end

{'fraction_non_alphanumeric': 0.12090592334494774, 'fraction_numerical': 0.004703832752613241, 'mean_word_length': 2.661033163265306, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 64}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4094604', 'n_tokens_mistral': 3523, 'n_tokens_neox': 3419, 'n_words': 886}