Skip to content

Commit 49778b8

Browse files
author
Krisztian Szabo
committed
Add tests for #upsert_leads
1 parent c847166 commit 49778b8

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

spec/mkto_rest_helper.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ def set_create_leads_stub_request(leads, hostname, token, options = nil)
2525
}
2626
url = "https://#{hostname}/rest/v1/leads.json"
2727
# taken from dev.marekto.com
28+
preferred_action = options && options.include?(:action) ? options[:action] : 'createOnly'
2829
req_body = {
29-
'action' => 'createOnly',
30-
'input' => []
30+
'action' => preferred_action
3131
}
32+
33+
req_body['lookupField'] = 'email' if options && options.include?(:upsert)
34+
35+
req_body['input'] = []
36+
3237
if options
3338
req_body['partitionName'] = options[:partition] if options[:partition]
3439
req_body['lookupField'] = options[:lookupField] if options[:lookupField]

spec/mkto_rest_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@
8484
end
8585
let(:partition) { 'bizdev' }
8686

87+
88+
describe '#upsert_leads' do
89+
let(:updated_leads) { authenticated_client.upsert_leads(sample_leads) }
90+
91+
it 'inserts or updates the given leads' do
92+
set_create_leads_stub_request(sample_leads, hostname, token, action: 'createOrUpdate', upsert: true)
93+
updated_leads
94+
end
95+
end
96+
8797
it 'can be updated by id' do
8898
set_update_lead_stub_request(:id, 1, { 'someFieldX' => 'new_value' }, hostname, token)
8999
lead1.update({ 'someFieldX' => 'new_value' }, :id)

0 commit comments

Comments
 (0)