-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1abe762
commit a7cf3c7
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
spec/services/integrations/hubspot/objects/deploy_invoices_service_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe Integrations::Hubspot::Objects::DeployInvoicesService do | ||
subject(:deploy_invoices_service) { described_class.new(integration:) } | ||
|
||
let(:integration) { create(:hubspot_integration) } | ||
|
||
describe '.call' do | ||
let(:http_client) { instance_double(LagoHttpClient::Client) } | ||
let(:endpoint) { "https://api.nango.dev/v1/hubspot/object" } | ||
let(:response) { instance_double('Response', success?: true) } | ||
|
||
before do | ||
allow(LagoHttpClient::Client).to receive(:new) | ||
.with(endpoint) | ||
.and_return(http_client) | ||
allow(http_client).to receive(:post_with_response).and_return(response) | ||
|
||
integration.invoices_properties_version = nil | ||
integration.save! | ||
end | ||
|
||
it 'successfully deploys invoices and updates the invoices_properties_version' do | ||
deploy_invoices_service.call | ||
|
||
aggregate_failures do | ||
expect(LagoHttpClient::Client).to have_received(:new).with(endpoint) | ||
expect(http_client).to have_received(:post_with_response) do |payload, headers| | ||
expect(payload[:name]).to eq('LagoInvoices') | ||
expect(headers['Authorization']).to include('Bearer') | ||
end | ||
expect(integration.reload.invoices_properties_version).to eq(described_class::VERSION) | ||
end | ||
end | ||
|
||
context 'when invoices_properties_version is already up-to-date' do | ||
before do | ||
integration.invoices_properties_version = described_class::VERSION | ||
integration.save! | ||
end | ||
|
||
it 'does not make an API call and keeps the version unchanged' do | ||
deploy_invoices_service.call | ||
|
||
aggregate_failures do | ||
expect(LagoHttpClient::Client).not_to have_received(:new) | ||
expect(http_client).not_to have_received(:post_with_response) | ||
expect(integration.reload.invoices_properties_version).to eq(described_class::VERSION) | ||
end | ||
end | ||
end | ||
|
||
context 'when the API call fails' do | ||
let(:response) { instance_double('Response', success?: false) } | ||
|
||
it 'does not update the invoices_properties_version' do | ||
deploy_invoices_service.call | ||
|
||
aggregate_failures do | ||
expect(LagoHttpClient::Client).to have_received(:new).with(endpoint) | ||
expect(integration.reload.invoices_properties_version).to be_nil | ||
end | ||
end | ||
end | ||
end | ||
end |