Skip to content

Commit

Permalink
Adding specs to additional fees endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhohe committed May 5, 2020
1 parent 8f05ceb commit c3c6738
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ group :development, :test do
gem 'rspec'
gem 'webmock'
gem 'vcr'
gem 'pry'
end
126 changes: 126 additions & 0 deletions spec/ttdrest/concerns/additional_fees_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'pry'

describe Ttdrest::Client do
describe "with initialized client" do
let(:client) { Ttdrest::Client.new }

let(:owner_id) { 1 }
let(:owner_type) { 'campaign' }
let(:start_date) { Time.now }
let(:fee_1) do
{
description: 'Foo Fee',
amount: 678,
fee_type: 'FeeCPM',
}
end
let(:fee_2) do
{
description: 'Bar Fee',
amount: 404,
fee_type: 'PartnerCostPercentage',
}
end
let(:fees) { [fee_1, fee_2] }

let(:additional_fees_body_response) { { 'Foo' => 'bar' } }

describe '#get_additional_fees' do
it 'builds the path with the given id and type' do
expect(client).to receive(:get).with('/additionalfees/campaign/1', {})
client.get_additional_fees(owner_id, owner_type)
end
end

describe '#create_additional_fees' do
it 'builds the additional fees body and submits it to the create api' do
# We test building the body, so just make sure we use it and it's converted to json
expect(client).to receive(:additional_fees_body).and_return(additional_fees_body_response)
expect(client).to receive(:data_post).with('/additionalfees', 'application/json', "{\"Foo\":\"bar\"}")
client.create_additional_fees(owner_id,owner_type,start_date,fees)
end
end

describe '#update_additional_fees' do
it 'builds the additional fees body and submits it to the create api' do
# We test building the body, so just make sure we use it and it's converted to json
expect(client).to receive(:additional_fees_body).and_return(additional_fees_body_response)
expect(client).to receive(:data_put).with('/additionalfees', 'application/json', "{\"Foo\":\"bar\"}")
client.update_additional_fees(owner_id,owner_type,start_date,fees)
end
end

describe "#additional_fees_body" do
it 'builds and populates the StartDateUtc attribute with iso8601 format' do
expect(
client.additional_fees_body(owner_id, owner_type, start_date, fees)
).to include({ "StartDateUtc" => start_date.utc.strftime("%Y-%m-%dT%H:%M:%SZ") })
end

it 'builds OwnerId attribute' do
expect(
client.additional_fees_body(owner_id, owner_type, start_date, fees)
).to include({ 'OwnerId' => owner_id })
end

it 'builds OwnerType attribute' do
expect(
client.additional_fees_body(owner_id, owner_type, start_date, fees)
).to include({ 'OwnerType' => owner_type })
end

it 'builds Fees attribute using each fee provided' do
expect(
client.additional_fees_body(owner_id, owner_type, start_date, fees)['Fees']
).to include({
'Description' => fee_1[:description],
'Amount' => fee_1[:amount],
'FeeType' => fee_1[:fee_type]
})
expect(
client.additional_fees_body(owner_id, owner_type, start_date, fees)['Fees']
).to include({
'Description' => fee_2[:description],
'Amount' => fee_2[:amount],
'FeeType' => fee_2[:fee_type]
})
end

context 'with raw JSON fees' do
let(:fee_1) do
{
'Description' => 'Foo Fee',
'Amount' => 678,
'FeeType' => 'FeeCPM',
}
end
let(:fee_2) do
{
'Description' => 'Bar Fee',
'Amount' => 404,
'FeeType' => 'PartnerCostPercentage',
}
end

it 'builds Fees attribute using each fee provided' do
expect(
client.additional_fees_body(owner_id, owner_type, start_date, fees)['Fees']
).to include({
'Description' => fee_1['Description'],
'Amount' => fee_1['Amount'],
'FeeType' => fee_1['FeeType']
})
expect(
client.additional_fees_body(owner_id, owner_type, start_date, fees)['Fees']
).to include({
'Description' => fee_2['Description'],
'Amount' => fee_2['Amount'],
'FeeType' => fee_2['FeeType']
})
end
end
end
end
end

0 comments on commit c3c6738

Please sign in to comment.