Merge pull request #2188 from betagouv/fix-pipedrive-deals

pipedrive: fix deals when no deals are returned
This commit is contained in:
Mathieu Magnin 2018-07-03 10:55:57 +02:00 committed by GitHub
commit 96b20668b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View file

@ -22,8 +22,8 @@ class Pipedrive::DealAdapter
end
def self.get_deals_ids_for_person(person_id)
Pipedrive::API.get_deals_for_person(person_id)
.map { |datum| datum['id'] }
deals = Pipedrive::API.get_deals_for_person(person_id) || []
deals.map { |datum| datum['id'] }
end
def self.update_deal_owner_and_stage(deal_id, owner_id, stage_id)

View file

@ -0,0 +1,27 @@
require 'spec_helper'
describe Pipedrive::DealAdapter do
let(:url) { PIPEDRIVE_API_URL }
let(:status) { 200 }
let(:body) { '{}' }
before do
stub_request(:get, url)
.to_return(status: status, body: body)
end
describe ".get_deals_ids_for_person" do
let(:url) { %r{/persons/1/deals\?*} }
subject { Pipedrive::DealAdapter.get_deals_ids_for_person('1') }
context "with valid data" do
let(:body) { '{ "success": true, "data": [ { "id": 34 }, { "id": 35 } ] }' }
it { is_expected.to eq [34, 35] }
end
context "when no data are returned" do
let(:body) { '{ "success": true, "data": null }' }
it { is_expected.to eq [] }
end
end
end

View file

@ -72,6 +72,7 @@ DatabaseCleaner.strategy = :transaction
TPS::Application.load_tasks
SIADETOKEN = :valid_token if !defined? SIADETOKEN
PIPEDRIVE_TOKEN = :pipedrive_test_token if !defined? PIPEDRIVE_TOKEN
include Warden::Test::Helpers