spec/concerns/crud_leads_spec.rb in mrkt-1.2.0 vs spec/concerns/crud_leads_spec.rb in mrkt-1.2.1

- old
+ new

@@ -1,7 +1,7 @@ describe Mrkt::CrudLeads do - include_context 'initialized client' + include_context 'with an initialized client' describe 'get_lead_by_id' do subject { client.get_lead_by_id(id, fields: fields) } let(:id) { 200 } @@ -54,10 +54,12 @@ it { is_expected.to eq(response_stub) } end end describe '#get_leads' do + subject { client.get_leads(filter_type, filter_values) } + let(:filter_type) { 'email' } let(:filter_values) { %w[user@example.com] } let(:response_stub) do { requestId: 'c245#14cd6830ae2', @@ -72,11 +74,10 @@ } ], success: true } end - subject { client.get_leads(filter_type, filter_values) } before do stub_request(:get, "https://#{host}/rest/v1/leads.json") .with(query: { filterType: filter_type, filterValues: filter_values.join(',') }) .to_return(json_stub(response_stub)) @@ -84,10 +85,12 @@ it { is_expected.to eq(response_stub) } end describe '#createupdate_leads' do + subject { client.createupdate_leads(leads, lookup_field: :email) } + let(:leads) do [ firstName: 'John', lastName: 'Snow', email: 'sample@example.com' @@ -116,11 +119,10 @@ status: 'created' } ] } end - subject { client.createupdate_leads(leads, lookup_field: :email) } before do stub_request(:post, "https://#{host}/rest/v1/leads.json") .with(json_stub(request_body)) .to_return(json_stub(response_stub)) @@ -128,10 +130,12 @@ it { is_expected.to eq(response_stub) } end describe '#delete_leads' do + subject { client.delete_leads(leads) } + let(:leads) { [1] } let(:request_body) do { input: [ { id: 1 } @@ -145,11 +149,10 @@ { id: 4098, status: 'deleted' } ], success: true } end - subject { client.delete_leads(leads) } before do stub_request(:delete, "https://#{host}/rest/v1/leads.json") .with(json_stub(request_body)) .to_return(json_stub(response_stub)) @@ -157,16 +160,16 @@ it { is_expected.to eq(response_stub) } end describe '#associate_lead' do + subject(:action) { client.associate_lead(id, cookie) } + let(:id) { 1 } let(:cookie) { 'id:561-HYG-937&token:_mch-marketo.com-1427205775289-40768' } let(:request_stub) { {} } - subject { client.associate_lead(id, cookie) } - before do stub_request(:post, "https://#{host}/rest/v1/leads/#{id}/associate.json?#{URI.encode_www_form(cookie: cookie)}") .with(json_stub(request_stub)) .to_return(json_stub(response_stub)) end @@ -195,23 +198,23 @@ } ] } end - it 'should raise an Error' do - expect { subject }.to raise_error(Mrkt::Errors::LeadNotFound) + it 'raises an Error' do + expect { action }.to raise_error(Mrkt::Errors::LeadNotFound) end end end describe '#merge_leads' do + subject(:action) { client.merge_leads(id, losing_lead_ids) } + let(:id) { 1 } let(:losing_lead_ids) { [2, 3, 4] } let(:request_stub) { {} } - subject { client.merge_leads(id, losing_lead_ids) } - before do params = ::Faraday::Utils::ParamsHash.new params[:mergeInCRM] = false params[:leadIds] = losing_lead_ids.join(',') if losing_lead_ids @@ -243,17 +246,19 @@ } ] } end - it 'should raise an Error' do - expect { subject }.to raise_error(Mrkt::Errors::LeadNotFound) + it 'raises an Error' do + expect { action }.to raise_error(Mrkt::Errors::LeadNotFound) end end end describe '#describe_lead' do + subject { client.describe_lead } + let(:response_stub) do { requestId: '5c9e#169a68fa806', result: [ { @@ -286,11 +291,9 @@ } ], success: true } end - - subject { client.describe_lead } before do stub_request(:get, "https://#{host}/rest/v1/leads/describe.json") .to_return(json_stub(response_stub)) end