Sha256: b0eac3c75a1a11a6520a1fb0074e96af9486f40ca856e5957c693dcfccc52bc9

Contents?: true

Size: 1.73 KB

Versions: 8

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe 'Intercom::Lead' do
  let (:client) { Intercom::Client.new(token: 'token') }

  it 'should be listable' do
    proxy = client.deprecated__leads.all
    _(proxy.resource_name).must_equal 'contacts'
    _(proxy.resource_class).must_equal Intercom::Lead
  end

  it 'should not throw ArgumentErrors when there are no parameters' do
    client.expects(:post)
    client.deprecated__leads.create
  end

  it 'can update a lead with an id' do
    lead = Intercom::Lead.new(id: 'de45ae78gae1289cb')
    client.expects(:put).with('/contacts/de45ae78gae1289cb', 'custom_attributes' => {})
    client.deprecated__leads.save(lead)
  end

  describe 'converting' do
    let(:lead) { Intercom::Lead.from_api(user_id: 'contact_id') }
    let(:user) { Intercom::User.from_api(id: 'user_id') }

    it do
      client.expects(:post).with(
        '/contacts/convert',
        contact: { user_id: lead.user_id },
        user: { 'id' => user.id }
      ).returns(test_user)

      client.deprecated__leads.convert(lead, user)
    end
  end

  it 'returns a DeprecatedLeadsCollectionProxy for all without making any requests' do
    client.expects(:execute_request).never
    all = client.deprecated__leads.all
    _(all).must_be_instance_of(Intercom::DeprecatedLeadsCollectionProxy)
  end

  it 'deletes a lead' do
    lead = Intercom::Lead.new('id' => '1')
    client.expects(:delete).with('/contacts/1', {}).returns(lead)
    client.deprecated__leads.delete(lead)
  end

  it 'sends a request for a hard deletion' do
    lead = Intercom::Lead.new('id' => '1')
    client.expects(:post).with('/user_delete_requests', intercom_user_id: '1').returns(id: lead.id)
    client.deprecated__leads.request_hard_delete(lead)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
intercom-4.2.1 spec/unit/intercom/lead_spec.rb
intercom-4.2.0 spec/unit/intercom/lead_spec.rb
intercom-4.1.3 spec/unit/intercom/lead_spec.rb
intercom-4.1.2 spec/unit/intercom/lead_spec.rb
intercom-4.1.1 spec/unit/intercom/lead_spec.rb
intercom-4.1.0 spec/unit/intercom/lead_spec.rb
intercom-4.0.1 spec/unit/intercom/lead_spec.rb
intercom-4.0.0 spec/unit/intercom/lead_spec.rb